almost complete all var types
This commit is contained in:
parent
7603ae21b6
commit
c582269683
36
lab.cpp
36
lab.cpp
|
@ -1,6 +1,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "var.h"
|
#include "var.h"
|
||||||
using namespace nasal;
|
using namespace nasal;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -33,11 +34,44 @@ int main()
|
||||||
n.PrintList();
|
n.PrintList();
|
||||||
std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
|
|
||||||
//n.Append(&n,"array","n");//cause infinite loop
|
|
||||||
n.Append(&n,"array");
|
n.Append(&n,"array");
|
||||||
n.Append(&n,"array");
|
n.Append(&n,"array");
|
||||||
n.PrintList();
|
n.PrintList();
|
||||||
std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
|
|
||||||
|
NasalList rm;
|
||||||
|
rm.Append(&a,"int");
|
||||||
|
rm.Append(&a,"int");
|
||||||
|
rm.Append(&a,"int");
|
||||||
|
rm.PrintList();
|
||||||
|
std::cout<<std::endl;
|
||||||
|
m.Append("fifth",&rm,"array");
|
||||||
|
m.Append("sixth",&m,"hash");
|
||||||
|
m.PrintHash();
|
||||||
|
std::cout<<std::endl;
|
||||||
|
|
||||||
|
NasalHash test1(m);
|
||||||
|
test1.PrintHash();
|
||||||
|
NasalList test2(n);
|
||||||
|
std::cout<<std::endl;
|
||||||
|
test2.PrintList();
|
||||||
|
std::cout<<std::endl;
|
||||||
|
|
||||||
|
n.Append(&m,"hash");
|
||||||
|
n.PrintList();
|
||||||
|
std::cout<<std::endl<<std::endl;
|
||||||
|
|
||||||
|
NasalList qt;
|
||||||
|
qt.Append(&a,"int");
|
||||||
|
a++;
|
||||||
|
qt.Append(&a,"int");
|
||||||
|
NasalHash qthash;
|
||||||
|
qthash.Append("testlist",&qt,"array");
|
||||||
|
qthash.PrintHash();
|
||||||
|
std::cout<<std::endl;
|
||||||
|
qthash.Append("int",&a,"int");
|
||||||
|
qt.Append(&qthash,"hash");
|
||||||
|
qt.PrintList();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,398 @@
|
||||||
|
#ifndef __NASAL_HASH_CPP__
|
||||||
|
#define __NASAL_HASH_CPP__
|
||||||
|
|
||||||
|
#include "nasal_hash.h"
|
||||||
|
#include "nasal_list.h"
|
||||||
|
namespace nasal
|
||||||
|
{
|
||||||
|
|
||||||
|
NasalHash::NasalHash()
|
||||||
|
{
|
||||||
|
head=new HashUnit;
|
||||||
|
head->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<<temp->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 \""<<VariaName<<"\"."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NasalHash& NasalHash::operator=(const NasalHash &Source)
|
||||||
|
{
|
||||||
|
HashUnit *temp=head;
|
||||||
|
HashUnit *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 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
|
203
nasal_hash.h
203
nasal_hash.h
|
@ -8,7 +8,6 @@
|
||||||
namespace nasal
|
namespace nasal
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
struct HashUnit
|
struct HashUnit
|
||||||
{
|
{
|
||||||
std::string VarName;
|
std::string VarName;
|
||||||
|
@ -22,199 +21,15 @@ class NasalHash
|
||||||
private:
|
private:
|
||||||
HashUnit *head;
|
HashUnit *head;
|
||||||
public:
|
public:
|
||||||
NasalHash()
|
NasalHash();
|
||||||
{
|
NasalHash(NasalHash&);
|
||||||
head=new HashUnit;
|
~NasalHash();
|
||||||
head->next=NULL;
|
void PrintHash();
|
||||||
}
|
void Append(const char *,void *,const char *);
|
||||||
~NasalHash()
|
int Contains(const char *);
|
||||||
{
|
NasalList Keys();
|
||||||
HashUnit *temp=head;
|
void Delete(const char *);
|
||||||
while(temp->next)
|
NasalHash& operator=(const NasalHash&);
|
||||||
{
|
|
||||||
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<<temp->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 \""<<VariaName<<"\"."<<std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,341 @@
|
||||||
|
#ifndef __NASAL_LIST_CPP__
|
||||||
|
#define __NASAL_LIST_CPP__
|
||||||
|
|
||||||
|
#include "nasal_list.h"
|
||||||
|
#include "nasal_hash.h"
|
||||||
|
namespace nasal
|
||||||
|
{
|
||||||
|
|
||||||
|
NasalList::NasalList()
|
||||||
|
{
|
||||||
|
head=new ListUnit;
|
||||||
|
head->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
|
269
nasal_list.h
269
nasal_list.h
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "nasal_hash.h"
|
|
||||||
|
|
||||||
namespace nasal
|
namespace nasal
|
||||||
{
|
{
|
||||||
|
@ -20,267 +20,12 @@ class NasalList
|
||||||
private:
|
private:
|
||||||
ListUnit *head;
|
ListUnit *head;
|
||||||
public:
|
public:
|
||||||
NasalList()
|
NasalList();
|
||||||
{
|
NasalList(NasalList &);
|
||||||
head=new ListUnit;
|
~NasalList();
|
||||||
head->data=NULL;
|
void PrintList();
|
||||||
head->next=NULL;
|
void Append(void *,const char *);
|
||||||
}
|
NasalList& operator=(const 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 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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<cstring>
|
#include<cstring>
|
||||||
#include "nasal_hash.h"
|
#include "nasal_hash.cpp"
|
||||||
#include "nasal_list.h"
|
#include "nasal_list.cpp"
|
||||||
|
|
||||||
namespace nasal
|
namespace nasal
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue