add class var&add function pop|subvec|setsize
This commit is contained in:
parent
c582269683
commit
141f4e9d26
39
lab.cpp
39
lab.cpp
|
@ -72,6 +72,45 @@ int main()
|
|||
qthash.Append("int",&a,"int");
|
||||
qt.Append(&qthash,"hash");
|
||||
qt.PrintList();
|
||||
std::cout<<std::endl;
|
||||
|
||||
NasalList _l;
|
||||
_l.Append(&a,"int");
|
||||
_l.SetSize(10);
|
||||
_l.PrintList();
|
||||
std::cout<<std::endl;
|
||||
_l.SetSize(3);
|
||||
_l.PrintList();
|
||||
std::cout<<std::endl;
|
||||
|
||||
_l.SetSize(0);
|
||||
_l.PrintList();
|
||||
std::cout<<std::endl;
|
||||
_l.Append(&a,"int");
|
||||
_l.Append(&a,"int");
|
||||
_l.Append(&a,"int");
|
||||
_l.Append(&a,"int");
|
||||
_l.Append(&a,"int");
|
||||
_l.Append(&a,"int");
|
||||
NasalList _k;
|
||||
_l.PrintList();
|
||||
std::cout<<std::endl;
|
||||
_k=_l.SubVec(9,4);
|
||||
_k.PrintList();
|
||||
std::cout<<std::endl;
|
||||
_k=_l.SubVec(1,10);
|
||||
_k.PrintList();
|
||||
std::cout<<std::endl;
|
||||
|
||||
NasalList _m;
|
||||
var _temp=_k.Pop();
|
||||
_m.Append(&_temp,"var");
|
||||
_k.PrintList();
|
||||
std::cout<<std::endl;
|
||||
_m.PrintList();
|
||||
std::cout<<std::endl;
|
||||
qthash.Append("var",&_temp,"var");
|
||||
qthash.PrintHash();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
177
nasal_hash.cpp
177
nasal_hash.cpp
|
@ -12,6 +12,7 @@ NasalHash::NasalHash()
|
|||
head->data=NULL;
|
||||
head->next=NULL;
|
||||
}
|
||||
|
||||
NasalHash::NasalHash(NasalHash &Source)
|
||||
{
|
||||
HashUnit *temp;
|
||||
|
@ -34,37 +35,37 @@ NasalHash::NasalHash(NasalHash &Source)
|
|||
temp->data=new int;
|
||||
*((int *)temp->data)=*((int *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
{
|
||||
temp->data=new float;
|
||||
*((float *)temp->data)=*((float *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
{
|
||||
temp->data=new double;
|
||||
*((double *)temp->data)=*((double *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
{
|
||||
temp->data=new char;
|
||||
*((char *)temp->data)=*((char *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="long long int")
|
||||
else 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")
|
||||
else if(temp->Type=="string")
|
||||
{
|
||||
temp->data=new std::string;
|
||||
*((std::string *)temp->data)=*((std::string *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
{
|
||||
temp->data=new NasalList;
|
||||
*((NasalList *)temp->data)=*((NasalList *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
{
|
||||
temp->data=new NasalHash;
|
||||
*((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data);
|
||||
|
@ -72,6 +73,7 @@ NasalHash::NasalHash(NasalHash &Source)
|
|||
temp->next=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
NasalHash::~NasalHash()
|
||||
{
|
||||
HashUnit *temp=head;
|
||||
|
@ -82,19 +84,19 @@ NasalHash::~NasalHash()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
@ -104,23 +106,24 @@ NasalHash::~NasalHash()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
}
|
||||
|
||||
void NasalHash::PrintHash()
|
||||
{
|
||||
HashUnit *temp=head;
|
||||
|
@ -133,22 +136,22 @@ void NasalHash::PrintHash()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
std::cout<<*((int *)temp->data)<<", ";
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
std::cout<<*((float *)temp->data)<<", ";
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
std::cout<<*((double *)temp->data)<<", ";
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
std::cout<<"\""<<*((char *)temp->data)<<"\", ";
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
std::cout<<*((long long int *)temp->data)<<", ";
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
std::cout<<"\""<<*((std::string *)temp->data)<<"\", ";
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
{
|
||||
((NasalList *)temp->data)->PrintList();
|
||||
std::cout<<", ";
|
||||
}
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
{
|
||||
((NasalHash *)temp->data)->PrintHash();
|
||||
std::cout<<", ";
|
||||
|
@ -158,24 +161,25 @@ void NasalHash::PrintHash()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
std::cout<<*((int *)temp->data);
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
std::cout<<*((float *)temp->data);
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
std::cout<<*((double *)temp->data);
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
std::cout<<"\""<<*((char *)temp->data)<<"\"";
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
std::cout<<*((long long int *)temp->data);
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
std::cout<<"\""<<*((std::string *)temp->data)<<"\"";
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
((NasalList *)temp->data)->PrintList();
|
||||
if(temp->Type=="hash")
|
||||
else 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)
|
||||
|
@ -231,6 +235,50 @@ void NasalHash::Append(const char *VariaName,void *AppendData,const char *TypeNa
|
|||
NewHashMember->data=new NasalHash;
|
||||
*((NasalHash *)NewHashMember->data)=TempHash;
|
||||
}
|
||||
else if(TypeName=="var")
|
||||
{
|
||||
NewHashMember->Type=(*(var *)AppendData).Type;
|
||||
if((*(var *)AppendData).Type=="int")
|
||||
{
|
||||
NewHashMember->data=new int;
|
||||
*((int *)NewHashMember->data)=*((int *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="float")
|
||||
{
|
||||
NewHashMember->data=new float;
|
||||
*((float *)NewHashMember->data)=*((float *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="double")
|
||||
{
|
||||
NewHashMember->data=new double;
|
||||
*((double *)NewHashMember->data)=*((double *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="char")
|
||||
{
|
||||
NewHashMember->data=new char;
|
||||
*((char *)NewHashMember->data)=*((char *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="long long int")
|
||||
{
|
||||
NewHashMember->data=new long long int;
|
||||
*((long long int *)NewHashMember->data)=*((long long int *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="string")
|
||||
{
|
||||
NewHashMember->data=new std::string;
|
||||
*((std::string *)NewHashMember->data)=*((std::string *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="array")
|
||||
{
|
||||
NewHashMember->data=new NasalList;
|
||||
*((NasalList *)NewHashMember->data)=*((NasalList *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="hash")
|
||||
{
|
||||
NewHashMember->data=new NasalHash;
|
||||
*((NasalHash *)NewHashMember->data)=*((NasalHash *)(*(var *)AppendData).data);
|
||||
}
|
||||
}
|
||||
NewHashMember->next=NULL;
|
||||
}
|
||||
int NasalHash::Contains(const char *VariaName)
|
||||
|
@ -244,6 +292,7 @@ int NasalHash::Contains(const char *VariaName)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NasalList NasalHash::Keys()
|
||||
{
|
||||
NasalList FeedBackList;
|
||||
|
@ -255,6 +304,7 @@ NasalList NasalHash::Keys()
|
|||
}
|
||||
return FeedBackList;
|
||||
}
|
||||
|
||||
void NasalHash::Delete(const char *VariaName)
|
||||
{
|
||||
HashUnit *temp=head;
|
||||
|
@ -268,19 +318,19 @@ void NasalHash::Delete(const char *VariaName)
|
|||
LastNode->next=temp->next;
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
delete temp;
|
||||
return;
|
||||
|
@ -289,6 +339,7 @@ void NasalHash::Delete(const char *VariaName)
|
|||
std::cout<<"[Error]: Could not find this element \""<<VariaName<<"\"."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
NasalHash& NasalHash::operator=(const NasalHash &Source)
|
||||
{
|
||||
HashUnit *temp=head;
|
||||
|
@ -300,19 +351,19 @@ NasalHash& NasalHash::operator=(const NasalHash &Source)
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
@ -322,19 +373,19 @@ NasalHash& NasalHash::operator=(const NasalHash &Source)
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
@ -354,37 +405,37 @@ NasalHash& NasalHash::operator=(const NasalHash &Source)
|
|||
temp->data=new int;
|
||||
*((int *)temp->data)=*((int *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
{
|
||||
temp->data=new float;
|
||||
*((float *)temp->data)=*((float *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
{
|
||||
temp->data=new double;
|
||||
*((double *)temp->data)=*((double *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
{
|
||||
temp->data=new char;
|
||||
*((char *)temp->data)=*((char *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="long long int")
|
||||
else 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")
|
||||
else if(temp->Type=="string")
|
||||
{
|
||||
temp->data=new std::string;
|
||||
*((std::string *)temp->data)=*((std::string *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
{
|
||||
temp->data=new NasalList;
|
||||
*((NasalList *)temp->data)=*((NasalList *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
{
|
||||
temp->data=new NasalHash;
|
||||
*((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data);
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
namespace nasal
|
||||
{
|
||||
#ifndef nil
|
||||
#define nil -1
|
||||
#endif
|
||||
|
||||
struct HashUnit
|
||||
{
|
||||
|
|
492
nasal_list.cpp
492
nasal_list.cpp
|
@ -12,6 +12,7 @@ NasalList::NasalList()
|
|||
head->data=NULL;
|
||||
head->next=NULL;
|
||||
}
|
||||
|
||||
NasalList::NasalList(NasalList &Source)
|
||||
{
|
||||
ListUnit *temp;
|
||||
|
@ -32,44 +33,49 @@ NasalList::NasalList(NasalList &Source)
|
|||
temp->data=new int;
|
||||
*((int *)temp->data)=*((int *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
{
|
||||
temp->data=new float;
|
||||
*((float *)temp->data)=*((float *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
{
|
||||
temp->data=new double;
|
||||
*((double *)temp->data)=*((double *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
{
|
||||
temp->data=new char;
|
||||
*((char *)temp->data)=*((char *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="long long int")
|
||||
else 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")
|
||||
else if(temp->Type=="string")
|
||||
{
|
||||
temp->data=new std::string;
|
||||
*((std::string *)temp->data)=*((std::string *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
{
|
||||
temp->data=new NasalList;
|
||||
*((NasalList *)temp->data)=*((NasalList *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
{
|
||||
temp->data=new NasalHash;
|
||||
*((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data);
|
||||
}
|
||||
else if(temp->Type=="null")
|
||||
{
|
||||
temp->data=NULL;
|
||||
}
|
||||
temp->next=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
NasalList::~NasalList()
|
||||
{
|
||||
ListUnit *temp=head;
|
||||
|
@ -80,19 +86,19 @@ NasalList::~NasalList()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
@ -102,19 +108,19 @@ NasalList::~NasalList()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
@ -131,45 +137,51 @@ void NasalList::PrintList()
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
std::cout<<*((int *)temp->data)<<", ";
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
std::cout<<*((float *)temp->data)<<", ";
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
std::cout<<*((double *)temp->data)<<", ";
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
std::cout<<"\""<<*((char *)temp->data)<<"\", ";
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
std::cout<<*((long long int *)temp->data)<<", ";
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
std::cout<<"\""<<*((std::string *)temp->data)<<"\", ";
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
{
|
||||
((NasalList *)temp->data)->PrintList();
|
||||
std::cout<<", ";
|
||||
}
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
{
|
||||
((NasalHash *)temp->data)->PrintHash();
|
||||
std::cout<<", ";
|
||||
}
|
||||
else if(temp->Type=="null")
|
||||
{
|
||||
std::cout<<"NULL, ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(temp->Type=="int")
|
||||
std::cout<<*((int *)temp->data);
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
std::cout<<*((float *)temp->data);
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
std::cout<<*((double *)temp->data);
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
std::cout<<"\""<<*((char *)temp->data)<<"\"";
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
std::cout<<*((long long int *)temp->data);
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
std::cout<<"\""<<*((std::string *)temp->data)<<"\"";
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
((NasalList *)temp->data)->PrintList();
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
((NasalHash *)temp->data)->PrintHash();
|
||||
else if(temp->Type=="null")
|
||||
std::cout<<"NULL";
|
||||
}
|
||||
}
|
||||
std::cout<<"]";
|
||||
|
@ -194,37 +206,138 @@ void NasalList::Append(void *AppendData,const char *TypeName)
|
|||
NewListMember->data=new int;
|
||||
*((int *)NewListMember->data)=*((int *)AppendData);
|
||||
}
|
||||
if(TypeName=="float")
|
||||
else if(TypeName=="float")
|
||||
{
|
||||
NewListMember->data=new float;
|
||||
*((float *)NewListMember->data)=*((float *)AppendData);
|
||||
}
|
||||
if(TypeName=="double")
|
||||
else if(TypeName=="double")
|
||||
{
|
||||
NewListMember->data=new double;
|
||||
*((double *)NewListMember->data)=*((double *)AppendData);
|
||||
}
|
||||
if(TypeName=="char")
|
||||
else if(TypeName=="char")
|
||||
{
|
||||
NewListMember->data=new char;
|
||||
*((char *)NewListMember->data)=*((char *)AppendData);
|
||||
}
|
||||
if(TypeName=="long long int")
|
||||
else if(TypeName=="long long int")
|
||||
{
|
||||
NewListMember->data=new long long int;
|
||||
*((long long int *)NewListMember->data)=*((long long int *)AppendData);
|
||||
}
|
||||
if(TypeName=="string")
|
||||
else if(TypeName=="string")
|
||||
{
|
||||
NewListMember->data=new std::string;
|
||||
*((std::string *)NewListMember->data)=*((std::string *)AppendData);
|
||||
}
|
||||
if(TypeName=="array")
|
||||
else if(TypeName=="array")
|
||||
{
|
||||
NewListMember->data=new NasalList;
|
||||
*((NasalList *)NewListMember->data)=TempList;
|
||||
}
|
||||
if(TypeName=="hash")
|
||||
else if(TypeName=="hash")
|
||||
{
|
||||
NewListMember->data=new NasalHash;
|
||||
*((NasalHash *)NewListMember->data)=*((NasalHash *)AppendData);
|
||||
}
|
||||
else if(TypeName=="var")
|
||||
{
|
||||
NewListMember->Type=(*(var *)AppendData).Type;
|
||||
if((*(var *)AppendData).Type=="int")
|
||||
{
|
||||
NewListMember->data=new int;
|
||||
*((int *)NewListMember->data)=*((int *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="float")
|
||||
{
|
||||
NewListMember->data=new float;
|
||||
*((float *)NewListMember->data)=*((float *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="double")
|
||||
{
|
||||
NewListMember->data=new double;
|
||||
*((double *)NewListMember->data)=*((double *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="char")
|
||||
{
|
||||
NewListMember->data=new char;
|
||||
*((char *)NewListMember->data)=*((char *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="long long int")
|
||||
{
|
||||
NewListMember->data=new long long int;
|
||||
*((long long int *)NewListMember->data)=*((long long int *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="string")
|
||||
{
|
||||
NewListMember->data=new std::string;
|
||||
*((std::string *)NewListMember->data)=*((std::string *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="array")
|
||||
{
|
||||
NewListMember->data=new NasalList;
|
||||
*((NasalList *)NewListMember->data)=*((NasalList *)(*(var *)AppendData).data);
|
||||
}
|
||||
else if((*(var *)AppendData).Type=="hash")
|
||||
{
|
||||
NewListMember->data=new NasalHash;
|
||||
*((NasalHash *)NewListMember->data)=*((NasalHash *)(*(var *)AppendData).data);
|
||||
}
|
||||
}
|
||||
NewListMember->next=NULL;
|
||||
}
|
||||
|
||||
void NasalList::Append(void *AppendData,std::string &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);
|
||||
}
|
||||
else if(TypeName=="float")
|
||||
{
|
||||
NewListMember->data=new float;
|
||||
*((float *)NewListMember->data)=*((float *)AppendData);
|
||||
}
|
||||
else if(TypeName=="double")
|
||||
{
|
||||
NewListMember->data=new double;
|
||||
*((double *)NewListMember->data)=*((double *)AppendData);
|
||||
}
|
||||
else if(TypeName=="char")
|
||||
{
|
||||
NewListMember->data=new char;
|
||||
*((char *)NewListMember->data)=*((char *)AppendData);
|
||||
}
|
||||
else if(TypeName=="long long int")
|
||||
{
|
||||
NewListMember->data=new long long int;
|
||||
*((long long int *)NewListMember->data)=*((long long int *)AppendData);
|
||||
}
|
||||
else if(TypeName=="string")
|
||||
{
|
||||
NewListMember->data=new std::string;
|
||||
*((std::string *)NewListMember->data)=*((std::string *)AppendData);
|
||||
}
|
||||
else if(TypeName=="array")
|
||||
{
|
||||
NewListMember->data=new NasalList;
|
||||
*((NasalList *)NewListMember->data)=TempList;
|
||||
}
|
||||
else if(TypeName=="hash")
|
||||
{
|
||||
NewListMember->data=new NasalHash;
|
||||
*((NasalHash *)NewListMember->data)=*((NasalHash *)AppendData);
|
||||
|
@ -243,19 +356,19 @@ NasalList& NasalList::operator=(const NasalList &Source)
|
|||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
if(temp->Type=="long long int")
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
if(temp->Type=="string")
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
@ -296,46 +409,313 @@ NasalList& NasalList::operator=(const NasalList &Source)
|
|||
temp->data=new int;
|
||||
*((int *)temp->data)=*((int *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="float")
|
||||
else if(temp->Type=="float")
|
||||
{
|
||||
temp->data=new float;
|
||||
*((float *)temp->data)=*((float *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="double")
|
||||
else if(temp->Type=="double")
|
||||
{
|
||||
temp->data=new double;
|
||||
*((double *)temp->data)=*((double *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="char")
|
||||
else if(temp->Type=="char")
|
||||
{
|
||||
temp->data=new char;
|
||||
*((char *)temp->data)=*((char *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="long long int")
|
||||
else 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")
|
||||
else if(temp->Type=="string")
|
||||
{
|
||||
temp->data=new std::string;
|
||||
*((std::string *)temp->data)=*((std::string *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="array")
|
||||
else if(temp->Type=="array")
|
||||
{
|
||||
temp->data=new NasalList;
|
||||
*((NasalList *)temp->data)=*((NasalList *)SourceTemp->data);
|
||||
}
|
||||
if(temp->Type=="hash")
|
||||
else if(temp->Type=="hash")
|
||||
{
|
||||
temp->data=new NasalHash;
|
||||
*((NasalHash *)temp->data)=*((NasalHash *)SourceTemp->data);
|
||||
}
|
||||
else if(temp->Type=="null")
|
||||
{
|
||||
temp->data=NULL;
|
||||
}
|
||||
temp->next=NULL;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NasalList::SetSize(const int Size)
|
||||
{
|
||||
if(Size==0)
|
||||
{
|
||||
ListUnit *temp=head;
|
||||
ListUnit *DeleteNode;
|
||||
temp=temp->next;
|
||||
head->next=NULL;
|
||||
while(temp->next)
|
||||
{
|
||||
DeleteNode=temp;
|
||||
if(temp->data)
|
||||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
temp=temp->next;
|
||||
delete DeleteNode;
|
||||
}
|
||||
if(temp->data)
|
||||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
return;
|
||||
}
|
||||
int cnt=0;
|
||||
ListUnit *temp=head;
|
||||
while(temp->next)
|
||||
{
|
||||
temp=temp->next;
|
||||
++cnt;
|
||||
if(cnt==Size)
|
||||
{
|
||||
ListUnit *DeleteNode=temp->next;
|
||||
temp->next=NULL;
|
||||
temp=DeleteNode;
|
||||
while(DeleteNode->next)
|
||||
{
|
||||
DeleteNode=DeleteNode->next;
|
||||
if(temp->data)
|
||||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
temp=DeleteNode;
|
||||
}
|
||||
if(temp->data)
|
||||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
while(cnt<Size)
|
||||
{
|
||||
temp->next=new ListUnit;
|
||||
temp=temp->next;
|
||||
temp->Type="null";
|
||||
temp->data=NULL;
|
||||
++cnt;
|
||||
}
|
||||
temp->next=NULL;
|
||||
return;
|
||||
}
|
||||
NasalList NasalList::SubVec(const int start,const int length=nil)
|
||||
{
|
||||
int cnt=-1;
|
||||
ListUnit *temp=head;
|
||||
while(temp->next)
|
||||
{
|
||||
temp=temp->next;
|
||||
++cnt;
|
||||
if(cnt==start)
|
||||
{
|
||||
NasalList NewNasalList;
|
||||
while(temp->next)
|
||||
{
|
||||
NewNasalList.Append(temp->data,temp->Type);
|
||||
temp=temp->next;
|
||||
if(cnt==length)
|
||||
return NewNasalList;
|
||||
++cnt;
|
||||
}
|
||||
if(length!=nil&&cnt<length)
|
||||
std::cout<<"[Error] Length out of range: (length) "<<length<<"|(range) "<<cnt<<"."<<std::endl;
|
||||
NewNasalList.Append(temp->data,temp->Type);
|
||||
return NewNasalList;
|
||||
}
|
||||
}
|
||||
std::cout<<"[Error] Starting place out of range: (start) "<<start<<"|(range) "<<cnt<<"."<<std::endl;
|
||||
NasalList NullList;
|
||||
NullList.SetSize(1);
|
||||
return NullList;
|
||||
}
|
||||
|
||||
var NasalList::Pop()
|
||||
{
|
||||
ListUnit *temp=head;
|
||||
ListUnit *NewLastUnit;
|
||||
while(temp->next)
|
||||
{
|
||||
NewLastUnit=temp;
|
||||
temp=temp->next;
|
||||
}
|
||||
NewLastUnit->next=NULL;
|
||||
var TempVar;
|
||||
TempVar.Type=temp->Type;
|
||||
if(TempVar.Type=="int")
|
||||
{
|
||||
TempVar.data=new int;
|
||||
*((int *)TempVar.data)=*((int *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="float")
|
||||
{
|
||||
TempVar.data=new float;
|
||||
*((float *)TempVar.data)=*((float *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="double")
|
||||
{
|
||||
TempVar.data=new double;
|
||||
*((double *)TempVar.data)=*((double *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="char")
|
||||
{
|
||||
TempVar.data=new char;
|
||||
*((char *)TempVar.data)=*((char *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="long long int")
|
||||
{
|
||||
TempVar.data=new long long int;
|
||||
*((long long int *)TempVar.data)=*((long long int *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="string")
|
||||
{
|
||||
TempVar.data=new std::string;
|
||||
*((std::string *)TempVar.data)=*((std::string *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="array")
|
||||
{
|
||||
TempVar.data=new NasalList;
|
||||
*((NasalList *)TempVar.data)=*((NasalList *)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="hash")
|
||||
{
|
||||
TempVar.data=new NasalHash;
|
||||
*((NasalHash *)TempVar.data)=*((NasalHash*)temp->data);
|
||||
}
|
||||
else if(TempVar.Type=="null")
|
||||
TempVar.data=NULL;
|
||||
|
||||
if(temp->data)
|
||||
{
|
||||
if(temp->Type=="int")
|
||||
delete (int *)temp->data;
|
||||
else if(temp->Type=="float")
|
||||
delete (float *)temp->data;
|
||||
else if(temp->Type=="double")
|
||||
delete (double *)temp->data;
|
||||
else if(temp->Type=="char")
|
||||
delete (char *)temp->data;
|
||||
else if(temp->Type=="long long int")
|
||||
delete (long long int *)temp->data;
|
||||
else if(temp->Type=="string")
|
||||
delete (std::string *)temp->data;
|
||||
else if(temp->Type=="array")
|
||||
delete (NasalList *)temp->data;
|
||||
else if(temp->Type=="hash")
|
||||
delete (NasalHash *)temp->data;
|
||||
}
|
||||
delete temp;
|
||||
|
||||
return TempVar;
|
||||
}
|
||||
|
||||
void NasalList::Sort(bool _cmp_1,bool _cmp_2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var::~var()
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
if(Type=="int")
|
||||
delete (int *)data;
|
||||
else if(Type=="float")
|
||||
delete (float *)data;
|
||||
else if(Type=="double")
|
||||
delete (double *)data;
|
||||
else if(Type=="char")
|
||||
delete (char *)data;
|
||||
else if(Type=="long long int")
|
||||
delete (long long int *)data;
|
||||
else if(Type=="string")
|
||||
delete (std::string *)data;
|
||||
else if(Type=="array")
|
||||
delete (NasalList *)data;
|
||||
else if(Type=="hash")
|
||||
delete (NasalHash *)data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
22
nasal_list.h
22
nasal_list.h
|
@ -7,6 +7,11 @@
|
|||
|
||||
namespace nasal
|
||||
{
|
||||
#ifndef nil
|
||||
#define nil -1
|
||||
#endif
|
||||
|
||||
class var;
|
||||
|
||||
struct ListUnit
|
||||
{
|
||||
|
@ -25,7 +30,24 @@ class NasalList
|
|||
~NasalList();
|
||||
void PrintList();
|
||||
void Append(void *,const char *);
|
||||
void Append(void *,std::string &);
|
||||
NasalList& operator=(const NasalList &);
|
||||
void SetSize(const int);
|
||||
NasalList SubVec(const int,const int);
|
||||
var Pop();
|
||||
void Sort(bool,bool);
|
||||
};
|
||||
|
||||
class var
|
||||
{
|
||||
public:
|
||||
std::string Type;
|
||||
void *data;
|
||||
var()
|
||||
{
|
||||
data=NULL;
|
||||
}
|
||||
~var();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue