|
|
|
#include "object.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
template<> EXPORT std::string ObjectSimple<bool>::type="bool";
|
|
|
|
template<> EXPORT std::string ObjectSimple<int64_t>::type="integer";
|
|
|
|
template<> EXPORT std::string ObjectSimple<double>::type="real";
|
|
|
|
template<> EXPORT std::string ObjectSimple<std::string>::type="string";
|
|
|
|
|
|
|
|
bool ObjectBase::Save(const char* fname) const
|
|
|
|
{
|
|
|
|
size_t size,offset=0,wr;
|
|
|
|
const int8_t* dptr;
|
|
|
|
FILE* fd;
|
|
|
|
int serrno;
|
|
|
|
|
|
|
|
fd=fopen(fname,"w");
|
|
|
|
serrno=errno;
|
|
|
|
if(0==fd)
|
|
|
|
{
|
|
|
|
COUT(ERROR)<<"Can't open file "<<fname<<" for writing: "<<strerror(serrno)<<std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dptr=Blob(&size);
|
|
|
|
if(0==dptr)
|
|
|
|
{
|
|
|
|
COUT(ERROR)<<"Can't get blob for writing to "<<fname<<std::endl;
|
|
|
|
fclose(fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while(offset!=size)
|
|
|
|
{
|
|
|
|
wr=fwrite(dptr+offset,1,size-offset,fd);
|
|
|
|
if(0==wr)
|
|
|
|
{
|
|
|
|
COUT(ERROR)<<"Failed to write in file "<<fname<<std::endl;
|
|
|
|
fclose(fd); DeallocBlob(dptr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
offset+=wr;
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
DeallocBlob(dptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ObjectBase* OFunc::Evaluate(bool* err)
|
|
|
|
{
|
|
|
|
*err=false;
|
|
|
|
if(G_funcs.find(name)==G_funcs.end())
|
|
|
|
{
|
|
|
|
*err=true;
|
|
|
|
COUT(ERROR)<<"Function "<<name<< " not found"<<std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
args->Evaluate(err);
|
|
|
|
if(*err)
|
|
|
|
{
|
|
|
|
COUT(ERROR)<<" in function call "<<Dump()<<std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectBase* ret;
|
|
|
|
auto p=G_funcs.equal_range(name);
|
|
|
|
for(auto f=p.first;f!=p.second;f++)
|
|
|
|
{
|
|
|
|
ret=(*(f->second))(args);
|
|
|
|
if(ret!=0) return ret;
|
|
|
|
}
|
|
|
|
*err=true;
|
|
|
|
COUT(ERROR)<<"Function "<<name<<" can't evaluate expression "<<args->Dump()<<std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|