Add files via upload

This commit is contained in:
Valk Richard Li 2019-07-25 02:18:20 +08:00 committed by GitHub
parent 9e6b7a4f97
commit d4e3e1868b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 320 additions and 0 deletions

Binary file not shown.

94
nasal_hash.h Normal file
View File

@ -0,0 +1,94 @@
#ifndef __NASAL_HASH_H__
#define __NASAL_HASH_H__
#include<iostream>
#include<cstring>
namespace nasal
{
struct HashUnit
{
std::string VarName;
std::string Type;
void *data;
HashUnit* next;
};
class NasalHash
{
private:
HashUnit *head;
public:
NasalHash()
{
head=new HashUnit;
head->next=NULL;
}
~NasalHash()
{
HashUnit *temp=head;
while(temp->next)
{
head=temp->next;
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)<<", ";
}
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);
}
}
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->data=AppendData;
NewHashMember->VarName=VariaName;
NewHashMember->Type=TypeName;
NewHashMember->next=NULL;
}
};
}
#endif

91
nasal_list.h Normal file
View File

@ -0,0 +1,91 @@
#ifndef __NASAL_LIST_H__
#define __NASAL_LIST_H__
#include<iostream>
#include<cstring>
namespace nasal
{
struct ListUnit
{
std::string Type;
void *data;
ListUnit* next;
};
class NasalList
{
private:
ListUnit *head;
public:
NasalList()
{
head=new ListUnit;
head->next=NULL;
}
~NasalList()
{
ListUnit *temp=head;
while(temp->next)
{
head=temp->next;
delete temp;
temp=head;
}
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)<<", ";
}
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);
}
}
std::cout<<"]";
}
void Append(void *AppendData,const char *TypeName)
{
ListUnit *temp=head;
while(temp->next)
{
temp=temp->next;
}
ListUnit *NewListMember=new ListUnit;
temp->next=NewListMember;
NewListMember->data=AppendData;
NewListMember->Type=TypeName;
NewListMember->next=NULL;
}
};
}
#endif

135
nasal_print.h Normal file
View File

@ -0,0 +1,135 @@
#ifndef __NASAL_PRINT_H__
#define __NASAL_PRINT_H__
#include<iostream>
#include<cstring>
#include "nasal_hash.h"
#include "nasal_list.h"
namespace nasal
{
void PrintVar(int Var)
{
std::cout<<Var;
}
void PrintVar(float Var)
{
std::cout<<Var;
}
void PrintVar(double Var)
{
std::cout<<Var;
}
void PrintVar(char Var)
{
std::cout<<Var;
}
void PrintVar(long long int Var)
{
std::cout<<Var;
}
void PrintString(std::string &PrintInfo)
{
for(int i=0;i<(int)PrintInfo.length();++i)
{
if(PrintInfo[i]=='\\' && i+1<(int)PrintInfo.length())
{
switch(PrintInfo[i+1])
{
case 'n':
std::cout<<"\n";
++i;
break;
case 't':
std::cout<<"\t";
++i;
break;
case 'r':
std::cout<<"\r";
++i;
break;
case '\\':
std::cout<<"\\";
++i;
break;
case '\'':
std::cout<<"\'";
++i;
break;
case '\"':
std::cout<<"\"";
++i;
break;
default:
//error occurred
std::cout<<std::endl<<"[Error]: Incorrect escape character \'"<<PrintInfo[i]<<PrintInfo[i+1]<<"\' .";
++i;
break;
}
}
else if(PrintInfo[i]=='\\' && i+1>=(int)PrintInfo.length())
{
//error occurred
std::cout<<std::endl<<"[Error]: Missing character after \'\\\'";
}
else
std::cout<<PrintInfo[i];
}
return;
}
void PrintString(const char *PrintInfo)
{
for(int i=0;i<strlen(PrintInfo);++i)
{
if(PrintInfo[i]=='\\' && i+1<strlen(PrintInfo))
{
switch(PrintInfo[i+1])
{
case 'n':
std::cout<<"\n";
++i;
break;
case 't':
std::cout<<"\t";
++i;
break;
case 'r':
std::cout<<"\r";
++i;
break;
case '\\':
std::cout<<"\\";
++i;
break;
case '\'':
std::cout<<"\'";
++i;
break;
case '\"':
std::cout<<"\"";
++i;
break;
default:
//error occurred
std::cout<<std::endl<<"[Error]: Incorrect escape character \'"<<PrintInfo[i]<<PrintInfo[i+1]<<"\' .";
++i;
break;
}
}
else if(PrintInfo[i]=='\\' && i+1>=strlen(PrintInfo))
{
//error occurred
std::cout<<std::endl<<"[Error]: Missing character after \'\\\'";
}
else
std::cout<<PrintInfo[i];
}
return;
}
}
#endif