26 #include "../bscript/bobject.h" 27 #include "../bscript/escrutil.h" 28 #include "../bscript/impstr.h" 29 #include "../clib/cfgelem.h" 30 #include "../clib/cfgfile.h" 31 #include "../clib/fileutil.h" 32 #include "../clib/logfacility.h" 33 #include "../clib/strutil.h" 34 #include "../plib/pkg.h" 35 #include "../plib/systemstate.h" 45 std::string propname, propval;
77 return ( *itr ).second.get();
83 PropImpList::const_iterator itr;
93 std::pair<StoredConfigElem::const_iterator, StoredConfigElem::const_iterator>
105 if ( pair.second.get() != nullptr )
106 elemsize = pair.second->sizeEstimate();
107 size += (
sizeof( pair.first ) + elemsize ) + (
sizeof(
void* ) * 3 + 1 ) / 2;
136 while ( cf.
read( elem ) )
140 if ( isdigit( elem.
rest()[0] ) )
142 unsigned int key = strtoul( elem.
rest(),
nullptr, 0 );
146 std::string key( elem.
rest() );
157 return ( *itr ).second;
166 return ( *itr ).second;
179 return ( *itr ).first;
191 std::string::size_type vstart = istr.find_first_not_of(
" [" );
192 std::string::size_type vend = istr.find_last_not_of(
"] " );
193 return istr.substr( vstart, vend );
198 std::ifstream ifs( filename.c_str() );
202 elements_bynum_.insert( ElementsByNum::value_type( count++, elemref ) );
205 while ( getline( ifs, strbuf ) )
207 if ( strbuf[0] ==
'[' )
210 elements_bynum_.insert( ElementsByNum::value_type( count++, elemref ) );
215 std::string propname, propvalue;
218 if ( propname ==
"" || propname.substr( 0, 2 ) ==
"//" )
223 elemref->addprop( propname, newimp );
229 size_t size =
sizeof( bool )
234 size_t elemsize =
sizeof(
ElemRef );
235 if ( pair.second.get() != nullptr )
236 elemsize = pair.second->estimateSize();
237 size += ( pair.first.capacity() + elemsize ) + (
sizeof(
void* ) * 3 + 1 ) / 2;
240 size += ( (
sizeof( int ) +
sizeof(
ElemRef ) ) + (
sizeof(
void* ) * 3 + 1 ) / 2 ) *
250 if ( ( *itr ).second->reload )
252 struct stat newcfgstat;
253 stat( filename.c_str(), &newcfgstat );
254 if ( ( *itr ).second->modified() != newcfgstat.st_mtime )
260 return ( *itr ).second;
263 return ( *itr ).second;
268 if ( !allpkgbase.empty() )
272 std::string main_cfg =
"config/" + allpkgbase +
".cfg";
276 scfg->load( cf_main );
281 pitr != pitrend; ++pitr )
304 DEBUGLOG <<
"Config File " << filename <<
" does not exist.\n";
317 catch ( std::exception& ex )
320 DEBUGLOG <<
"An exception was encountered while reading " << filename <<
": " << ex.what()
334 scfg->load_tus_scp( filename );
349 ( *itr ).second->reload =
true;
351 return ( *itr ).second->count() - 1;
360 void ConfigFiles_log_stuff()
bool remove_first_prop(std::string *propname, std::string *value)
ref_ptr< StoredConfigElem > ElemRef
boost::flyweight< std::string, boost::flyweights::tag< cfg_key_tag >, FLYWEIGHT_HASH_FACTORY > cfg_key_flystring
void splitnamevalue(const std::string &istr, std::string &propname, std::string &propvalue)
ref_ptr< StoredConfigFile > ConfigFileRef
void addprop(const std::string &propname, Bscript::BObjectImp *imp)
void CreateEmptyStoredConfigFile(const std::string &filename)
int UnloadConfigFile(const std::string &filename)
ElementsByName elements_byname_
virtual long contains(const BObjectImp &imp) const POL_OVERRIDE
void load(Clib::ConfigFile &cf)
StoredConfigElem()=default
const char * rest() const
virtual BObjectImp * copy() const POL_OVERRIDE
BObjectImp * bobject_from_string(const std::string &str, int radix)
ConfigurationBuffer configurationbuffer
Bscript::BObjectImp * listprops() const
size_t estimateSize() const
Bscript::BObjectImp * getimp(const std::string &propname) const
void load_tus_scp(const std::string &filename)
ElementsByNum elements_bynum_
unsigned int count() const
ElemRef findelem(int key)
void addElement(BObjectImp *imp)
size_t estimateSize() const
std::string GetPackageCfgPath(const Package *pkg, const std::string &filename)
std::string extractkey(const std::string &istr)
bool FileExists(const char *filename)
bool read(ConfigElem &elem)
ConfigFileRef FindConfigFile(const std::string &filename, const std::string &allpkgbase)
ConfigFileRef LoadTusScpFile(const std::string &filename)
std::pair< const_iterator, const_iterator > equal_range(const std::string &propname) const