mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
Add files via upload
Add more functions.
This commit is contained in:
+131
-3
@@ -1,8 +1,10 @@
|
||||
#ifndef __NASAL_HASH_H__
|
||||
#define __NASAL_HASH_H__
|
||||
|
||||
#include<iostream>
|
||||
#include<cstring>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include "nasal_list.h"
|
||||
|
||||
namespace nasal
|
||||
{
|
||||
|
||||
@@ -31,6 +33,25 @@ class NasalHash
|
||||
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;
|
||||
}
|
||||
@@ -56,6 +77,18 @@ class NasalHash
|
||||
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
|
||||
{
|
||||
@@ -69,6 +102,12 @@ class NasalHash
|
||||
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<<"}";
|
||||
@@ -82,11 +121,100 @@ class NasalHash
|
||||
}
|
||||
HashUnit *NewHashMember=new HashUnit;
|
||||
temp->next=NewHashMember;
|
||||
NewHashMember->data=AppendData;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user