16 #include "../../bscript/berror.h" 17 #include "../../bscript/bobject.h" 18 #include "../../bscript/bstruct.h" 19 #include "../../bscript/dict.h" 20 #include "../../bscript/execmodl.h" 21 #include "../../bscript/executor.h" 22 #include "../../bscript/impstr.h" 23 #include "../../bscript/objmembers.h" 24 #include "../../clib/rawtypes.h" 25 #include "../../clib/refptr.h" 26 #include "../../clib/strutil.h" 27 #include "../../plib/pkg.h" 28 #include "../cfgrepos.h" 37 using namespace Module;
77 celem =
obj_->findelem( strval );
82 celem =
obj_->findelem( key );
85 if ( celem.
get() != nullptr )
97 return "ConfigFileRef";
115 return "ConfigElemRef";
135 if ( imp !=
nullptr )
147 std::string* errmsg, std::string* allpkgbase )
153 if ( cfgdesc[0] ==
':' )
155 if ( cfgdesc[1] ==
':' )
161 if ( cfgdesc.substr( 2, 8 ) ==
"regions/" )
163 *cfgfile = cfgdesc.substr( 2, std::string::npos ) +
".cfg";
169 *cfgfile =
"config/" + cfgdesc.substr( 2, std::string::npos ) +
".cfg";
175 std::string::size_type second_colon = cfgdesc.find(
':', 2 );
176 if ( second_colon != std::string::npos )
178 std::string pkgname = cfgdesc.substr( 1, second_colon - 1 );
179 std::string cfgbase = cfgdesc.substr( second_colon + 1, std::string::npos );
181 if ( pkgname ==
"*" )
186 *allpkgbase = cfgbase;
196 if ( dstpkg !=
nullptr )
203 *errmsg =
"Unable to find package " + pkgname;
209 *errmsg =
"Poorly formed config file descriptor: " + cfgdesc;
216 if ( pkg !=
nullptr )
218 *cfgfile =
GetPackageCfgPath( const_cast<Plib::Package*>( pkg ), cfgdesc +
".cfg" );
223 *cfgfile =
"config/" + cfgdesc +
".cfg";
235 const std::string& cfgdesc = cfgdesc_str->
value();
238 std::string allpkgbase;
246 if ( cfile.
get() != nullptr )
263 while ( filename && *filename )
265 if ( !isalnum( *filename ) )
282 return new Bscript::BError(
"Filename cannot include path information or special characters" );
288 if ( cfile.
get() == nullptr )
316 Core::StoredConfigFile::ElementsByName::const_iterator itr = cfile->
byname_begin(),
318 for ( ; itr != end; ++itr )
322 return arr.release();
326 return new Bscript::BError(
"GetConfigStringKeys param 0 must be a Config File" );
336 Core::StoredConfigFile::ElementsByNum::const_iterator itr = cfile->
bynum_begin(),
338 for ( ; itr != end; ++itr )
342 return arr.release();
346 return new Bscript::BError(
"GetConfigIntKeys param 0 must be a Config File" );
372 return new Bscript::BError(
"Param 1 must be an Integer or a String" );
375 if ( celem.
get() != nullptr )
398 if ( imp !=
nullptr )
420 std::pair<Core::StoredConfigElem::const_iterator, Core::StoredConfigElem::const_iterator> pr =
426 for ( ; itr != end; ++itr )
450 std::pair<Core::StoredConfigElem::const_iterator, Core::StoredConfigElem::const_iterator> pr =
456 for ( ; itr != end; ++itr )
461 if ( line_str.length() < 1 )
472 std::string prop_name, prop_value;
478 return dict.release();
495 if ( imp !=
nullptr )
513 return new Bscript::BError(
"Invalid type in config file! (internal error)" );
539 for ( ; itr != end; ++itr )
549 ar->addElement( imp );
579 if ( imp !=
nullptr )
597 return new Bscript::BError(
"Invalid type in config file! (internal error)" );
638 std::string pathname, errmsg;
639 const std::string& cfgdesc = filename->
value();
645 std::ofstream ofs( pathname.c_str(), std::ios::app );
646 ofs << std::endl << elemtype->
value() <<
" " << elemkey << std::endl <<
"{" << std::endl;
657 if ( inarr->
ref_arr.size() == 2 )
666 ofs <<
"\t" << namestr->
value() <<
"\t" << value << std::endl;
680 ofs <<
"\t" << namestr->
value() <<
"\t" << value << std::endl;
685 ofs <<
"}" << std::endl;
697 const std::string& cfgdesc = filename->
value();
700 std::string allpkgbase;
718 if ( ao_cfile_base !=
nullptr )
722 cfile = ao_cfile->
value().get();
736 if ( ao_celem_base !=
nullptr )
740 celem = ao_celem->
value().get();
ConfigFileExecutorModule(Bscript::Executor &exec)
Bscript::BObjectImp * mf_LoadTusScpFile()
virtual Bscript::BObjectRef get_member_id(const int id) POL_OVERRIDE
virtual u8 typeOfInt() const POL_OVERRIDE
virtual std::string getStringRep() const =0
const EScriptProgram * prog() const
const std::string & value() const
std::vector< FunctionDef > FunctionTable
ElementsByNum::const_iterator bynum_end()
virtual const char * typeOf() const POL_OVERRIDE
Bscript::BApplicObjType cfgelem_type
Bscript::BObjectImp * mf_GetConfigStringKeys()
void splitnamevalue(const std::string &istr, std::string &propname, std::string &propvalue)
bool isa(BObjectType type) const
Bscript::BObjectImp * mf_UnloadConfigFile()
int UnloadConfigFile(const std::string &filename)
StoredConfigElem::PropImpList::const_iterator const_iterator
virtual u8 typeOfInt() const POL_OVERRIDE
Bscript::BObjectImp * mf_GetConfigString()
Bscript::BObjectImp * mf_GetConfigIntArray()
BObjectImp * getParamImp(unsigned param)
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
ElementsByName::const_iterator byname_begin()
Bscript::BObjectImp * mf_GetConfigInt()
Package * find_package(const std::string &pkgname)
Bscript::BObjectImp * mf_GetConfigStringArray()
virtual Bscript::BObjectRef get_member(const char *membername) POL_OVERRIDE
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
Cont::const_iterator const_iterator
Bscript::BObjectImp * mf_GetConfigMaxIntKey()
Bscript::BObjectImp * mf_AppendConfigFileElem()
Bscript::BObjectImp * mf_FindConfigElement()
EConfigFileRefObjImp(ref_ptr< Core::StoredConfigFile > rcfile)
Bscript::BObjectImp * listprops() const
Bscript::BObjectImp * mf_ConfigFile()
ObjMember * getObjMember(int id)
bool getStoredConfigElemParam(Bscript::ExecutorModule &exmod, unsigned param, Core::StoredConfigElem *&celem)
bool get_cfgfilename(const std::string &cfgdesc, std::string *cfgfile, std::string *errmsg, std::string *allpkgbase=nullptr)
Bscript::BApplicObjType cfgfile_type
Bscript::BObjectImp * getimp(const std::string &propname) const
Bscript::BObjectImp * mf_GetConfigReal()
const String * getStringParam(unsigned param)
bool getStoredConfigFileParam(Bscript::ExecutorModule &exmod, unsigned param, Core::StoredConfigFile *&cfile)
std::unordered_map< u64, ScriptDiffData > data
virtual Bscript::BObjectRef OperSubscript(const Bscript::BObject &obj) POL_OVERRIDE
ElemRef findelem(int key)
Bscript::BObjectImp * mf_ListConfigElemProps()
BApplicObjBase * getApplicObjParam(unsigned param, const BApplicObjType *object_type)
Plib::Package const * pkg
virtual const char * typeOf() const POL_OVERRIDE
const String * getStringParam(unsigned param)
bool legal_scp_filename(const char *filename)
Bscript::BObjectImp * mf_GetConfigStringDictionary()
std::string GetPackageCfgPath(const Package *pkg, const std::string &filename)
Bscript::BObjectImp * mf_GetConfigIntKeys()
EConfigElemRefObjImp(ref_ptr< Core::StoredConfigElem > rcelem)
ConfigFileRef FindConfigFile(const std::string &filename, const std::string &allpkgbase)
ElementsByName::const_iterator byname_end()
bool getObjArrayParam(unsigned param, ObjArray *&pobjarr)
ConfigFileRef LoadTusScpFile(const std::string &filename)
const char * data() const
const BObjectImp * FindMember(const char *name)
ElementsByNum::const_iterator bynum_begin()
BObjectImp * getParamImp(unsigned param)
std::pair< const_iterator, const_iterator > equal_range(const std::string &propname) const