17 #include "../../bscript/berror.h" 18 #include "../../bscript/bobject.h" 19 #include "../../bscript/bstruct.h" 20 #include "../../bscript/executor.h" 21 #include "../../bscript/impstr.h" 22 #include "../../bscript/objmethods.h" 23 #include "../../clib/cfgelem.h" 24 #include "../../clib/cfgfile.h" 25 #include "../../clib/fileutil.h" 26 #include "../../clib/rawtypes.h" 27 #include "../../clib/streamsaver.h" 28 #include "../../plib/pkg.h" 29 #include "../../plib/systemstate.h" 30 #include "../globals/ucfg.h" 31 #include "../proplist.h" 38 using namespace Module;
76 size += ele.first.capacity() +
sizeof(
DataFileElementRef ) + (
sizeof(
void* ) * 3 + 1 ) / 2;
77 if ( ele.second.get() != nullptr )
78 size += ele.second->proplist.estimatedSize();
80 size += (
sizeof( int ) +
sizeof(
DataFileElementRef ) + (
sizeof(
void* ) * 3 + 1 ) / 2 ) *
89 while ( cf.
read( elem ) )
108 sw() <<
"Element " << element.first <<
"\n" 110 element.second->printOn( sw );
117 sw() <<
"Element " << element.first <<
"\n" 119 element.second->printOn( sw );
137 dfelem = ( *itr ).second;
154 dfelem = ( *itr ).second;
227 return arr.release();
238 return "DataFileRef";
258 return new Bscript::BError(
"not enough parameters to datafile.createelement(key)" );
265 return new Bscript::BError(
"datafile.createelement(key): key must be an Integer" );
267 return obj_->methodCreateElement( key );
274 return new Bscript::BError(
"datafile.createelement(key): key must be a String" );
276 return obj_->methodCreateElement( key->
value() );
282 return new Bscript::BError(
"not enough parameters to datafile.findelement(key)" );
289 return new Bscript::BError(
"datafile.findelement(key): key must be an Integer" );
291 return obj_->methodFindElement( key );
298 return new Bscript::BError(
"datafile.findelement(key): key must be a String" );
300 return obj_->methodFindElement( key->
value() );
306 return new Bscript::BError(
"not enough parameters to datafile.deleteelement(key)" );
313 return new Bscript::BError(
"datafile.deleteelement(key): key must be an Integer" );
315 return obj_->methodDeleteElement( key );
322 return new Bscript::BError(
"datafile.deleteelement(key): key must be a String" );
324 return obj_->methodDeleteElement( key->
value() );
328 return obj_->methodKeys();
337 if ( objmethod !=
nullptr )
350 return "DataElemRef";
364 bool changed =
false;
367 obj_.dfcontents->dirty =
true;
373 bool changed =
false;
377 obj_.dfcontents->dirty =
true;
388 std::string descriptor;
391 std::string spec_filename;
396 if ( spec_pkg ==
nullptr )
399 descriptor =
"::" + spec_filename;
404 descriptor =
":" + spec_pkg->
name() +
":" + spec_filename;
431 file_list->addElement( file_name.release() );
433 return file_list.release();
444 std::string descriptor;
445 std::string directory;
447 const std::string& inspec = strob->
value();
450 std::string spec_filename;
455 if ( spec_pkg ==
nullptr )
458 descriptor =
"::" + spec_filename;
464 descriptor =
":" + spec_pkg->
name() +
":" + spec_filename;
480 dsf = ( *itr ).second;
485 dsf =
new DataStoreFile( descriptor, spec_pkg, spec_filename, flags );
490 if ( !dsf->loaded() )
495 catch ( std::exception& ex )
497 std::string message = std::string(
"An exception occurred: " ) + ex.what();
514 std::string descriptor;
516 const std::string& inspec = strob->
value();
519 std::string spec_filename;
524 if ( spec_pkg ==
nullptr )
527 descriptor =
"::" + spec_filename;
532 descriptor =
":" + spec_pkg->
name() +
":" + spec_filename;
549 catch ( std::exception& ex )
551 return new Bscript::BError( std::string(
"An exception occurred" ) + ex.what() );
579 : descriptor( elem.remove_string(
"Descriptor" ) ),
580 name( elem.remove_string(
"name" ) ),
581 pkgname( elem.remove_string(
"package",
"" ) ),
583 version( elem.remove_ushort(
"Version" ) ),
584 oldversion( elem.remove_ushort(
"OldVersion" ) ),
585 flags( elem.remove_ulong(
"Flags" ) ),
593 : descriptor( descriptor ),
603 if ( pkg !=
nullptr )
642 <<
"\tName\t" <<
name <<
"\n";
645 sw() <<
"\tPackage\t" <<
pkgname <<
"\n";
647 sw() <<
"\tFlags\t" <<
flags <<
"\n" 648 <<
"\tVersion\t" <<
version <<
"\n" 656 if (
pkg !=
nullptr )
670 std::ofstream ofs( fname.c_str(), std::ios::out );
679 + 3 *
sizeof(
unsigned )
712 while ( cf.
read( elem ) )
Bscript::BObjectImp * methodDeleteElement(int key)
DataFileContentsRef dfcontents
ElementsByInteger elements_by_integer
const EScriptProgram * prog() const
const std::string & value() const
std::vector< FunctionDef > FunctionTable
void MakeDirectory(const char *dir)
Bscript::BObjectImp * mf_UnloadDataFile()
DataFileContents(DataStoreFile *dsf)
Bscript::BApplicObjType datafileelem_type
std::string world_data_path
Bscript::BObjectImp * mf_CreateDataFile()
ElementsByString elements_by_string
bool getParam(unsigned param, int &value)
DataElemRefObjImp(DataFileContentsRef dfcontents, DataFileElementRef dflem)
Bscript::BObjectImp * methodFindElement(int key)
virtual Bscript::BObjectImp * call_method_id(const int id, Bscript::Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
Bscript::BObjectImp * methodCreateElement(int key)
const std::string & name() const
ref_ptr< DataFileElement > DataFileElementRef
ObjMethod * getKnownObjMethod(const char *token)
DataFileExecutorModule(Bscript::Executor &exec)
Package * find_package(const std::string &pkgname)
ref_ptr< DataFileContents > DataFileContentsRef
std::string filename() const
const char * rest() const
Bscript::BObjectImp * mf_OpenDataFile()
void readRemainingPropertiesAsStrings(Clib::ConfigElem &elem)
Bscript::BObjectImp * CallPropertyListMethod_id(PropertyList &proplist, const int id, Bscript::Executor &ex, bool &changed)
bool pkgdef_split(const std::string &spec, const Package *inpkg, const Package **outpkg, std::string *path)
virtual Bscript::BObjectImp * call_method_id(const int id, Bscript::Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
virtual const char * typeOf() const POL_OVERRIDE
void save(Clib::StreamWriter &sw)
DataStoreFile * GetDataStoreFile(const std::string &inspec)
size_t estimateSize() const
DataFileRefObjImp(DataFileContentsRef dfref)
ConfigurationBuffer configurationbuffer
Core::PropertyList proplist
std::string tostring(const Bscript::BTokenType &v)
virtual u8 typeOfInt() const POL_OVERRIDE
Bscript::BObjectImp * methodKeys() const
void load(Clib::ConfigFile &cf)
void printPropertiesAsStrings(Clib::StreamWriter &sw) const
DataStoreFile(Clib::ConfigElem &elem)
const Plib::Package * pkg
Bscript::BApplicObjType datafileref_type
Datastore.
virtual ~DataFileContents()
const String * getStringParam(unsigned param)
void write_datastore(Clib::StreamWriter &sw)
size_t estimateSize() const
Plib::Package const * pkg
virtual const char * typeOf() const POL_OVERRIDE
virtual Bscript::BObjectImp * call_method(const char *methodname, Bscript::Executor &ex) POL_OVERRIDE
const String * getStringParam(unsigned param)
virtual Bscript::BObjectImp * call_method(const char *methodname, Bscript::Executor &ex) POL_OVERRIDE
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
void RemoveFile(const std::string &fname)
Bscript::BObjectImp * mf_ListDataFiles()
void read_datastore_dat()
bool hasParams(unsigned howmany) const
Bscript::BObjectImp * CallPropertyListMethod(PropertyList &proplist, const char *methodname, Bscript::Executor &ex, bool &changed)
virtual u8 typeOfInt() const POL_OVERRIDE
bool FileExists(const char *filename)
const int DF_KEYTYPE_INTEGER
bool read(ConfigElem &elem)
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
void printOn(Clib::StreamWriter &sw) const
void printOn(Clib::StreamWriter &sw) const
bool getParam(unsigned param, int &value)