diff --git a/lab.cpp b/lab.cpp index 698c5cb..d4ab5d9 100644 --- a/lab.cpp +++ b/lab.cpp @@ -1,6 +1,7 @@ #include #include "var.h" using namespace nasal; +using namespace std; int main() { @@ -33,11 +34,44 @@ int main() n.PrintList(); std::cout<data=NULL; + head->next=NULL; +} +NasalHash::NasalHash(NasalHash &Source) +{ + HashUnit *temp; + HashUnit *SourceTemp=Source.head; + + head=new HashUnit; + head->next=NULL; + head->data=NULL; + + temp=head; + while(SourceTemp->next) + { + SourceTemp=SourceTemp->next; + temp->next=new HashUnit; + temp=temp->next; + temp->Type=SourceTemp->Type; + temp->VarName=SourceTemp->VarName; + if(temp->Type=="int") + { + temp->data=new int; + *((int *)temp->data)=*((int *)SourceTemp->data); + } + if(temp->Type=="float") + { + temp->data=new float; + *((float *)temp->data)=*((float *)SourceTemp->data); + } + if(temp->Type=="double") + { + temp->data=new double; + *((double *)temp->data)=*((double *)SourceTemp->data); + } + if(temp->Type=="char") + { + temp->data=new char; + *((char *)temp->data)=*((char *)SourceTemp->data); + } + if(temp->Type=="long long int") + { + temp->data=new long long int; + *((long long int *)temp->data)=*((long long int *)SourceTemp->data); + } + if(temp->Type=="string") + { + temp->data=new std::string; + *((std::string *)temp->data)=*((std::string *)SourceTemp->data); + } + if(temp->Type=="array") + { + temp->data=new NasalList; + *((NasalList *)temp->data)=*((NasalList *)SourceTemp->data); + } + if(temp->Type=="hash") + { + temp->data=new NasalHash; + *((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data); + } + temp->next=NULL; + } +} +NasalHash::~NasalHash() +{ + HashUnit *temp=head; + while(temp->next) + { + head=temp->next; + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; + temp=head; + } + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; +} +void NasalHash::PrintHash() +{ + HashUnit *temp=head; + std::cout<<"{ "; + while(temp->next) + { + temp=temp->next; + std::cout<VarName<<":"; + if(temp->next) + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data)<<", "; + if(temp->Type=="float") + std::cout<<*((float *)temp->data)<<", "; + if(temp->Type=="double") + std::cout<<*((double *)temp->data)<<", "; + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\", "; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data)<<", "; + if(temp->Type=="string") + std::cout<<"\""<<*((std::string *)temp->data)<<"\", "; + if(temp->Type=="array") + { + ((NasalList *)temp->data)->PrintList(); + std::cout<<", "; + } + if(temp->Type=="hash") + { + ((NasalHash *)temp->data)->PrintHash(); + std::cout<<", "; + } + } + else + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data); + if(temp->Type=="float") + std::cout<<*((float *)temp->data); + if(temp->Type=="double") + std::cout<<*((double *)temp->data); + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\""; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data); + if(temp->Type=="string") + std::cout<<"\""<<*((std::string *)temp->data)<<"\""; + if(temp->Type=="array") + ((NasalList *)temp->data)->PrintList(); + if(temp->Type=="hash") + ((NasalHash *)temp->data)->PrintHash(); + } + } + std::cout<<"}"; +} +void NasalHash::Append(const char *VariaName,void *AppendData,const char *TypeName) +{ + NasalHash TempHash;//sometimes user may use n.append(n) + if(TypeName=="hash") + TempHash=*((NasalHash *)AppendData); + HashUnit *temp=head; + while(temp->next) + { + temp=temp->next; + } + HashUnit *NewHashMember=new HashUnit; + NewHashMember->data=NULL; + temp->next=NewHashMember; + NewHashMember->VarName=VariaName; + NewHashMember->Type=TypeName; + if(TypeName=="int") + { + NewHashMember->data=new int; + *((int *)NewHashMember->data)=*((int *)AppendData); + } + else if(TypeName=="float") + { + NewHashMember->data=new float; + *((float *)NewHashMember->data)=*((float *)AppendData); + } + else if(TypeName=="double") + { + NewHashMember->data=new double; + *((double *)NewHashMember->data)=*((double *)AppendData); + } + else if(TypeName=="char") + { + NewHashMember->data=new char; + *((char *)NewHashMember->data)=*((char *)AppendData); + } + else if(TypeName=="long long int") + { + NewHashMember->data=new long long int; + *((long long int *)NewHashMember->data)=*((long long int *)AppendData); + } + else if(TypeName=="string") + { + NewHashMember->data=new std::string; + *((std::string *)NewHashMember->data)=*((std::string *)AppendData); + } + else if(TypeName=="array") + { + NewHashMember->data=new NasalList; + *((NasalList *)NewHashMember->data)=*((NasalList *)AppendData); + } + else if(TypeName=="hash") + { + NewHashMember->data=new NasalHash; + *((NasalHash *)NewHashMember->data)=TempHash; + } + NewHashMember->next=NULL; +} +int NasalHash::Contains(const char *VariaName) +{ + HashUnit *temp=head; + while(temp->next) + { + temp=temp->next; + if(temp->VarName==VariaName) + return 1; + } + return 0; +} +NasalList NasalHash::Keys() +{ + NasalList FeedBackList; + HashUnit *temp=head; + while(temp->next) + { + temp=temp->next; + FeedBackList.Append(&(temp->VarName),"string"); + } + return FeedBackList; +} +void NasalHash::Delete(const char *VariaName) +{ + HashUnit *temp=head; + HashUnit *LastNode; + while(temp->next) + { + LastNode=temp; + temp=temp->next; + if(temp->VarName==VariaName) + { + LastNode->next=temp->next; + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + delete temp; + return; + } + } + std::cout<<"[Error]: Could not find this element \""<next) + { + head=temp->next; + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; + temp=head; + } + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; + head=new HashUnit; + head->next=NULL; + + temp=head; + while(SourceTemp->next) + { + SourceTemp=SourceTemp->next; + temp->next=new HashUnit; + temp=temp->next; + temp->Type=SourceTemp->Type; + temp->VarName=SourceTemp->VarName; + if(temp->Type=="int") + { + temp->data=new int; + *((int *)temp->data)=*((int *)SourceTemp->data); + } + if(temp->Type=="float") + { + temp->data=new float; + *((float *)temp->data)=*((float *)SourceTemp->data); + } + if(temp->Type=="double") + { + temp->data=new double; + *((double *)temp->data)=*((double *)SourceTemp->data); + } + if(temp->Type=="char") + { + temp->data=new char; + *((char *)temp->data)=*((char *)SourceTemp->data); + } + if(temp->Type=="long long int") + { + temp->data=new long long int; + *((long long int *)temp->data)=*((long long int *)SourceTemp->data); + } + if(temp->Type=="string") + { + temp->data=new std::string; + *((std::string *)temp->data)=*((std::string *)SourceTemp->data); + } + if(temp->Type=="array") + { + temp->data=new NasalList; + *((NasalList *)temp->data)=*((NasalList *)SourceTemp->data); + } + if(temp->Type=="hash") + { + temp->data=new NasalHash; + *((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data); + } + temp->next=NULL; + } + return *this; +} + +} +#endif diff --git a/nasal_hash.h b/nasal_hash.h index d71a9fe..6d9acd1 100644 --- a/nasal_hash.h +++ b/nasal_hash.h @@ -8,7 +8,6 @@ namespace nasal { - struct HashUnit { std::string VarName; @@ -22,199 +21,15 @@ class NasalHash private: HashUnit *head; public: - NasalHash() - { - head=new HashUnit; - head->next=NULL; - } - ~NasalHash() - { - HashUnit *temp=head; - while(temp->next) - { - head=temp->next; - if(temp->data) - { - if(temp->Type=="int") - delete (int *)temp->data; - if(temp->Type=="float") - delete (float *)temp->data; - if(temp->Type=="double") - delete (double *)temp->data; - if(temp->Type=="char") - delete (char *)temp->data; - if(temp->Type=="long long int") - delete (long long int *)temp->data; - if(temp->Type=="string") - delete (std::string *)temp->data; - if(temp->Type=="array") - delete (NasalList *)temp->data; - if(temp->Type=="hash") - delete (NasalHash *)temp->data; - } - delete temp; - temp=head; - } - delete temp; - } - void PrintHash() - { - HashUnit *temp=head; - std::cout<<"{ "; - while(temp->next) - { - temp=temp->next; - std::cout<VarName<<":"; - if(temp->next) - { - if(temp->Type=="int") - std::cout<<*((int *)temp->data)<<", "; - if(temp->Type=="float") - std::cout<<*((float *)temp->data)<<", "; - if(temp->Type=="double") - std::cout<<*((double *)temp->data)<<", "; - if(temp->Type=="char") - std::cout<<"\""<<*((char *)temp->data)<<"\", "; - if(temp->Type=="long long int") - std::cout<<*((long long int *)temp->data)<<", "; - if(temp->Type=="string") - std::cout<<"\""<<*((std::string *)temp->data)<<"\", "; - if(temp->Type=="array") - { - ((NasalList *)temp->data)->PrintList(); - std::cout<<", "; - } - if(temp->Type=="hash") - { - ((NasalHash *)temp->data)->PrintHash(); - std::cout<<", "; - } - } - else - { - if(temp->Type=="int") - std::cout<<*((int *)temp->data); - if(temp->Type=="float") - std::cout<<*((float *)temp->data); - if(temp->Type=="double") - std::cout<<*((double *)temp->data); - if(temp->Type=="char") - std::cout<<"\""<<*((char *)temp->data)<<"\""; - if(temp->Type=="long long int") - std::cout<<*((long long int *)temp->data); - if(temp->Type=="string") - std::cout<<"\""<<*((std::string *)temp->data)<<"\""; - if(temp->Type=="array") - ((NasalList *)temp->data)->PrintList(); - if(temp->Type=="hash") - ((NasalHash *)temp->data)->PrintHash(); - } - } - std::cout<<"}"; - } - void Append(const char *VariaName,void *AppendData,const char *TypeName) - { - HashUnit *temp=head; - while(temp->next) - { - temp=temp->next; - } - HashUnit *NewHashMember=new HashUnit; - temp->next=NewHashMember; - NewHashMember->VarName=VariaName; - NewHashMember->Type=TypeName; - if(TypeName=="int") - { - NewHashMember->data=new int; - *((int *)NewHashMember->data)=*((int *)AppendData); - } - if(TypeName=="float") - { - NewHashMember->data=new float; - *((float *)NewHashMember->data)=*((float *)AppendData); - } - if(TypeName=="double") - { - NewHashMember->data=new double; - *((double *)NewHashMember->data)=*((double *)AppendData); - } - if(TypeName=="char") - { - NewHashMember->data=new char; - *((char *)NewHashMember->data)=*((char *)AppendData); - } - if(TypeName=="long long int") - { - NewHashMember->data=new long long int; - *((long long int *)NewHashMember->data)=*((long long int *)AppendData); - } - if(TypeName=="string") - { - NewHashMember->data=new std::string; - *((std::string *)NewHashMember->data)=*((std::string *)AppendData); - } - if(temp->Type=="array") - ; - if(temp->Type=="hash") - ; - NewHashMember->next=NULL; - } - int Contains(const char *VariaName) - { - HashUnit *temp=head; - while(temp->next) - { - temp=temp->next; - if(temp->VarName==VariaName) - return 1; - } - return 0; - } - NasalList Keys() - { - NasalList FeedBackList; - HashUnit *temp=head; - while(temp->next) - { - temp=temp->next; - FeedBackList.Append(&(temp->VarName),"string"); - } - return FeedBackList; - } - void Delete(const char *VariaName) - { - HashUnit *temp=head; - HashUnit *LastNode; - while(temp->next) - { - LastNode=temp; - temp=temp->next; - if(temp->VarName==VariaName) - { - LastNode->next=temp->next; - if(temp->Type=="int") - delete (int *)temp->data; - if(temp->Type=="float") - delete (float *)temp->data; - if(temp->Type=="double") - delete (double *)temp->data; - if(temp->Type=="char") - delete (char *)temp->data; - if(temp->Type=="long long int") - delete (long long int *)temp->data; - if(temp->Type=="string") - delete (std::string *)temp->data; - if(temp->Type=="array") - delete (NasalList *)temp->data; - if(temp->Type=="hash") - delete (NasalHash *)temp->data; - delete temp; - return; - } - } - std::cout<<"[Error]: Could not find this element \""<data=NULL; + head->next=NULL; +} +NasalList::NasalList(NasalList &Source) +{ + ListUnit *temp; + ListUnit *SourceTemp=Source.head; + + head=new ListUnit; + head->next=NULL; + + temp=head; + while(SourceTemp->next) + { + SourceTemp=SourceTemp->next; + temp->next=new ListUnit; + temp=temp->next; + temp->Type=SourceTemp->Type; + if(temp->Type=="int") + { + temp->data=new int; + *((int *)temp->data)=*((int *)SourceTemp->data); + } + if(temp->Type=="float") + { + temp->data=new float; + *((float *)temp->data)=*((float *)SourceTemp->data); + } + if(temp->Type=="double") + { + temp->data=new double; + *((double *)temp->data)=*((double *)SourceTemp->data); + } + if(temp->Type=="char") + { + temp->data=new char; + *((char *)temp->data)=*((char *)SourceTemp->data); + } + if(temp->Type=="long long int") + { + temp->data=new long long int; + *((long long int *)temp->data)=*((long long int *)SourceTemp->data); + } + if(temp->Type=="string") + { + temp->data=new std::string; + *((std::string *)temp->data)=*((std::string *)SourceTemp->data); + } + if(temp->Type=="array") + { + temp->data=new NasalList; + *((NasalList *)temp->data)=*((NasalList *)SourceTemp->data); + } + if(temp->Type=="hash") + { + temp->data=new NasalHash; + *((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data); + } + temp->next=NULL; + } +} +NasalList::~NasalList() +{ + ListUnit *temp=head; + while(temp->next) + { + head=temp->next; + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; + temp=head; + } + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; +} + +void NasalList::PrintList() +{ + ListUnit *temp=head; + std::cout<<"[ "; + while(temp->next) + { + temp=temp->next; + if(temp->next) + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data)<<", "; + if(temp->Type=="float") + std::cout<<*((float *)temp->data)<<", "; + if(temp->Type=="double") + std::cout<<*((double *)temp->data)<<", "; + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\", "; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data)<<", "; + if(temp->Type=="string") + std::cout<<"\""<<*((std::string *)temp->data)<<"\", "; + if(temp->Type=="array") + { + ((NasalList *)temp->data)->PrintList(); + std::cout<<", "; + } + if(temp->Type=="hash") + { + ((NasalHash *)temp->data)->PrintHash(); + std::cout<<", "; + } + } + else + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data); + if(temp->Type=="float") + std::cout<<*((float *)temp->data); + if(temp->Type=="double") + std::cout<<*((double *)temp->data); + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\""; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data); + if(temp->Type=="string") + std::cout<<"\""<<*((std::string *)temp->data)<<"\""; + if(temp->Type=="array") + ((NasalList *)temp->data)->PrintList(); + if(temp->Type=="hash") + ((NasalHash *)temp->data)->PrintHash(); + } + } + std::cout<<"]"; +} + +void NasalList::Append(void *AppendData,const char *TypeName) +{ + NasalList TempList;//sometimes user may use n.append(n) + if(TypeName=="array") + TempList=*((NasalList *)AppendData); + ListUnit *temp=head; + while(temp->next) + { + temp=temp->next; + } + ListUnit *NewListMember=new ListUnit; + temp->next=NewListMember; + NewListMember->data=NULL; + NewListMember->Type=TypeName; + if(TypeName=="int") + { + NewListMember->data=new int; + *((int *)NewListMember->data)=*((int *)AppendData); + } + if(TypeName=="float") + { + NewListMember->data=new float; + *((float *)NewListMember->data)=*((float *)AppendData); + } + if(TypeName=="double") + { + NewListMember->data=new double; + *((double *)NewListMember->data)=*((double *)AppendData); + } + if(TypeName=="char") + { + NewListMember->data=new char; + *((char *)NewListMember->data)=*((char *)AppendData); + } + if(TypeName=="long long int") + { + NewListMember->data=new long long int; + *((long long int *)NewListMember->data)=*((long long int *)AppendData); + } + if(TypeName=="string") + { + NewListMember->data=new std::string; + *((std::string *)NewListMember->data)=*((std::string *)AppendData); + } + if(TypeName=="array") + { + NewListMember->data=new NasalList; + *((NasalList *)NewListMember->data)=TempList; + } + if(TypeName=="hash") + { + NewListMember->data=new NasalHash; + *((NasalHash *)NewListMember->data)=*((NasalHash *)AppendData); + } + NewListMember->next=NULL; +} + +NasalList& NasalList::operator=(const NasalList &Source) +{ + ListUnit *temp=head; + ListUnit *SourceTemp=Source.head; + while(temp->next) + { + head=temp->next; + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; + temp=head; + } + if(temp->data) + { + if(temp->Type=="int") + delete (int *)temp->data; + if(temp->Type=="float") + delete (float *)temp->data; + if(temp->Type=="double") + delete (double *)temp->data; + if(temp->Type=="char") + delete (char *)temp->data; + if(temp->Type=="long long int") + delete (long long int *)temp->data; + if(temp->Type=="string") + delete (std::string *)temp->data; + if(temp->Type=="array") + delete (NasalList *)temp->data; + if(temp->Type=="hash") + delete (NasalHash *)temp->data; + } + delete temp; + head=new ListUnit; + head->next=NULL; + + temp=head; + while(SourceTemp->next) + { + SourceTemp=SourceTemp->next; + temp->next=new ListUnit; + temp=temp->next; + temp->Type=SourceTemp->Type; + if(temp->Type=="int") + { + temp->data=new int; + *((int *)temp->data)=*((int *)SourceTemp->data); + } + if(temp->Type=="float") + { + temp->data=new float; + *((float *)temp->data)=*((float *)SourceTemp->data); + } + if(temp->Type=="double") + { + temp->data=new double; + *((double *)temp->data)=*((double *)SourceTemp->data); + } + if(temp->Type=="char") + { + temp->data=new char; + *((char *)temp->data)=*((char *)SourceTemp->data); + } + if(temp->Type=="long long int") + { + temp->data=new long long int; + *((long long int *)temp->data)=*((long long int *)SourceTemp->data); + } + if(temp->Type=="string") + { + temp->data=new std::string; + *((std::string *)temp->data)=*((std::string *)SourceTemp->data); + } + if(temp->Type=="array") + { + temp->data=new NasalList; + *((NasalList *)temp->data)=*((NasalList *)SourceTemp->data); + } + if(temp->Type=="hash") + { + temp->data=new NasalHash; + *((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data); + } + temp->next=NULL; + } + return *this; +} + +} + +#endif diff --git a/nasal_list.h b/nasal_list.h index 6c24849..b2c066e 100644 --- a/nasal_list.h +++ b/nasal_list.h @@ -3,7 +3,7 @@ #include #include -#include "nasal_hash.h" + namespace nasal { @@ -20,267 +20,12 @@ class NasalList private: ListUnit *head; public: - NasalList() - { - head=new ListUnit; - head->data=NULL; - head->next=NULL; - } - ~NasalList() - { - ListUnit *temp=head; - while(temp->next) - { - head=temp->next; - if(temp->data) - { - if(temp->Type=="int") - delete (int *)temp->data; - if(temp->Type=="float") - delete (float *)temp->data; - if(temp->Type=="double") - delete (double *)temp->data; - if(temp->Type=="char") - delete (char *)temp->data; - if(temp->Type=="long long int") - delete (long long int *)temp->data; - if(temp->Type=="string") - delete (std::string *)temp->data; - if(temp->Type=="array") - delete (NasalList *)temp->data; - if(temp->Type=="hash"); - //delete (NasalHash *)temp->data; - } - delete temp; - temp=head; - } - if(temp->data) - { - if(temp->Type=="int") - delete (int *)temp->data; - if(temp->Type=="float") - delete (float *)temp->data; - if(temp->Type=="double") - delete (double *)temp->data; - if(temp->Type=="char") - delete (char *)temp->data; - if(temp->Type=="long long int") - delete (long long int *)temp->data; - if(temp->Type=="string") - delete (std::string *)temp->data; - if(temp->Type=="array") - delete (NasalList *)temp->data; - if(temp->Type=="hash") - ; - } - delete temp; - } - void PrintList() - { - ListUnit *temp=head; - std::cout<<"[ "; - while(temp->next) - { - temp=temp->next; - if(temp->next) - { - if(temp->Type=="int") - std::cout<<*((int *)temp->data)<<", "; - if(temp->Type=="float") - std::cout<<*((float *)temp->data)<<", "; - if(temp->Type=="double") - std::cout<<*((double *)temp->data)<<", "; - if(temp->Type=="char") - std::cout<<"\""<<*((char *)temp->data)<<"\", "; - if(temp->Type=="long long int") - std::cout<<*((long long int *)temp->data)<<", "; - if(temp->Type=="string") - std::cout<<"\""<<*((std::string *)temp->data)<<"\", "; - if(temp->Type=="array") - { - ((NasalList *)temp->data)->PrintList(); - std::cout<<", "; - } - if(temp->Type=="hash") - { - ;//((NasalHash *)temp->data)->PrintHash(); - std::cout<<", "; - } - } - else - { - if(temp->Type=="int") - std::cout<<*((int *)temp->data); - if(temp->Type=="float") - std::cout<<*((float *)temp->data); - if(temp->Type=="double") - std::cout<<*((double *)temp->data); - if(temp->Type=="char") - std::cout<<"\""<<*((char *)temp->data)<<"\""; - if(temp->Type=="long long int") - std::cout<<*((long long int *)temp->data); - if(temp->Type=="string") - std::cout<<"\""<<*((std::string *)temp->data)<<"\""; - if(temp->Type=="array") - ((NasalList *)temp->data)->PrintList(); - if(temp->Type=="hash") - ;//((NasalHash *)temp->data)->PrintHash(); - } - } - std::cout<<"]"; - } - void Append(void *AppendData,const char *TypeName) - { - NasalList TempList;//sometimes user may use n.append(n) - if(TypeName=="array") - TempList=*((NasalList *)AppendData); - ListUnit *temp=head; - while(temp->next) - { - temp=temp->next; - } - ListUnit *NewListMember=new ListUnit; - temp->next=NewListMember; - NewListMember->Type=TypeName; - if(TypeName=="int") - { - NewListMember->data=new int; - *((int *)NewListMember->data)=*((int *)AppendData); - } - if(TypeName=="float") - { - NewListMember->data=new float; - *((float *)NewListMember->data)=*((float *)AppendData); - } - if(TypeName=="double") - { - NewListMember->data=new double; - *((double *)NewListMember->data)=*((double *)AppendData); - } - if(TypeName=="char") - { - NewListMember->data=new char; - *((char *)NewListMember->data)=*((char *)AppendData); - } - if(TypeName=="long long int") - { - NewListMember->data=new long long int; - *((long long int *)NewListMember->data)=*((long long int *)AppendData); - } - if(TypeName=="string") - { - NewListMember->data=new std::string; - *((std::string *)NewListMember->data)=*((std::string *)AppendData); - } - if(TypeName=="array") - { - NewListMember->data=new NasalList; - *((NasalList *)NewListMember->data)=TempList; - } - if(TypeName=="hash") - ; - NewListMember->next=NULL; - } - NasalList& operator=(const NasalList &Source) - { - ListUnit *temp=head; - ListUnit *SourceTemp=Source.head; - while(temp->next) - { - head=temp->next; - if(temp->data) - { - if(temp->Type=="int") - delete (int *)temp->data; - if(temp->Type=="float") - delete (float *)temp->data; - if(temp->Type=="double") - delete (double *)temp->data; - if(temp->Type=="char") - delete (char *)temp->data; - if(temp->Type=="long long int") - delete (long long int *)temp->data; - if(temp->Type=="string") - delete (std::string *)temp->data; - if(temp->Type=="array") - delete (NasalList *)temp->data; - if(temp->Type=="hash") - ; - } - delete temp; - temp=head; - } - if(temp->data) - { - if(temp->Type=="int") - delete (int *)temp->data; - if(temp->Type=="float") - delete (float *)temp->data; - if(temp->Type=="double") - delete (double *)temp->data; - if(temp->Type=="char") - delete (char *)temp->data; - if(temp->Type=="long long int") - delete (long long int *)temp->data; - if(temp->Type=="string") - delete (std::string *)temp->data; - if(temp->Type=="array") - delete (NasalList *)temp->data; - if(temp->Type=="hash") - ; - } - delete temp; - head=new ListUnit; - head->next=NULL; - - temp=head; - while(SourceTemp->next) - { - SourceTemp=SourceTemp->next; - temp->next=new ListUnit; - temp=temp->next; - temp->Type=SourceTemp->Type; - if(temp->Type=="int") - { - temp->data=new int; - *((int *)temp->data)=*((int *)SourceTemp->data); - } - if(temp->Type=="float") - { - temp->data=new float; - *((float *)temp->data)=*((float *)SourceTemp->data); - } - if(temp->Type=="double") - { - temp->data=new double; - *((double *)temp->data)=*((double *)SourceTemp->data); - } - if(temp->Type=="char") - { - temp->data=new char; - *((char *)temp->data)=*((char *)SourceTemp->data); - } - if(temp->Type=="long long int") - { - temp->data=new long long int; - *((long long int *)temp->data)=*((long long int *)SourceTemp->data); - } - if(temp->Type=="string") - { - temp->data=new std::string; - *((std::string *)temp->data)=*((std::string *)SourceTemp->data); - } - if(temp->Type=="array") - { - temp->data=new NasalList; - *((NasalList *)temp->data)=*((NasalList *)SourceTemp->data); - } - if(temp->Type=="hash") - ; - temp->next=NULL; - } - return *this; - } + NasalList(); + NasalList(NasalList &); + ~NasalList(); + void PrintList(); + void Append(void *,const char *); + NasalList& operator=(const NasalList &); }; } diff --git a/nasal_print.h b/nasal_print.h index 4f06401..5086c4a 100644 --- a/nasal_print.h +++ b/nasal_print.h @@ -3,8 +3,8 @@ #include #include -#include "nasal_hash.h" -#include "nasal_list.h" +#include "nasal_hash.cpp" +#include "nasal_list.cpp" namespace nasal { diff --git a/var.h b/var.h new file mode 100644 index 0000000..db94d2c --- /dev/null +++ b/var.h @@ -0,0 +1,23 @@ +#ifndef __VAR_H__ +#define __VAR_H__ + +#include "nasal_hash.cpp" +#include "nasal_list.cpp" +#include "nasal_print.h" + +// int +// char +// long long int +// double +// float +// string +// const char * +// NasalHash +// NasalList + +/* +NasalList->delete NasalList & NasalHash + +NasalHash->delete NasalList & NasalHash +*/ +#endif