You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.6 KiB

#include "globals.h"
// Variables definitions
G_varsType G_vars;
// Functions addresses
G_funcsType G_funcs;
// List of objects to save
G_toType G_tosave;
// List of objects to print
G_toType G_toprint;
void ClearGlobals()
{
for(auto& it:G_vars) delete it.second;
for(auto& it:G_tosave) delete it;
for(auto& it:G_toprint) delete it;
G_vars.clear();
G_tosave.clear();
G_toprint.clear();
}
void RegisterFunction(const std::string& name, Func func)
{
G_funcs.emplace(name,func);
}
bool Save(const ObjectList* input)
{
ObjectList::ListValues::size_type sz=input->Size(), i;
if(sz<2 || sz%2==1 )
{
COUT(ERROR)<<"Number of save arguments must not be "<<sz<<std::endl;
return false;
}
// Check arguments types
const ObjectBase* arg1;
const ObjectString* arg2;
for(i=0;i<sz/2;i++)
{
arg1=input->At(i*2+1);
if(!IS_OTYPE(arg1,ObjectString))
{
COUT(ERROR)<<"Save format is save(object_1,file_1,...,object_n,file_n) where file_i is string"<<std::endl;
return false;
}
}
// Save
for(i=0;i<sz/2;i++)
{
arg1=input->At(i*2);
arg2=dynamic_cast<const ObjectString*>(input->At(i*2+1));
if(!arg1->Save(arg2->Value().c_str()))
{
COUT(ERROR)<<"Can't save object "<<arg1->Dump()<<" to file "<<arg2->Value()<<std::endl;
return false;
}
}
return true;
}
bool Print(const ObjectList* input)
{
ObjectList::ListValues::size_type sz=input->Size(), i;
if(sz==0) return true;
// Print
for(i=0;i<sz;i++)
{
if(!input->At(i)->Print())
{
COUT(ERROR)<<"Unprintable object "<<input->At(i)->Dump()<<std::endl;
return false;
}
}
return true;
}