14 #include "../bscript/berror.h" 15 #include "../bscript/bobject.h" 16 #include "../bscript/contiter.h" 17 #include "../bscript/impstr.h" 18 #include "../clib/cfgelem.h" 19 #include "../clib/cfgfile.h" 20 #include "../clib/clib.h" 21 #include "../clib/compilerspecifics.h" 22 #include "../clib/logfacility.h" 23 #include "../clib/rawtypes.h" 24 #include "../clib/streamsaver.h" 25 #include "../plib/systemstate.h" 41 using namespace Bscript;
49 Cont::iterator itr =
_items.begin();
58 size_t size =
_name.capacity();
59 for (
const auto& item :
_items )
60 size += item.first.capacity() +
sizeof(
Items::Item* ) + (
sizeof(
void* ) * 3 + 1 ) / 2;
68 Cont::iterator itr =
_items.find( name );
71 return ( *itr ).second;
78 Cont::iterator itr =
_items.find( name );
93 _items.insert( make_pair( item->
name(), item ) );
107 u32 container_serial = 0;
108 (void)elem.
remove_prop(
"CONTAINER", &container_serial );
112 if ( item ==
nullptr )
117 if ( container_serial == 0 )
137 AreaCont::iterator itr = areas.find( name );
138 if ( itr == areas.end() )
141 return ( *itr ).second;
146 AreaCont::iterator itr = areas.find( name );
147 if ( itr == areas.end() )
155 return ( *itr ).second;
161 const char* rest = elem.
rest();
162 if ( rest !=
nullptr && rest[0] )
164 return create_area( rest );
169 return create_area( name );
176 for (
const auto& cont_item :
_items )
186 for ( Cont::const_iterator itr =
_items.begin(), itrend =
_items.end(); itr != itrend; ++itr )
203 for ( AreaCont::const_iterator itr = areas.begin(), itrend = areas.end(); itr != itrend; ++itr )
205 itr->second->on_delete_realm( realm );
211 static int num_until_dot = 1000;
212 unsigned int nobjects = 0;
217 clock_t start = clock();
219 while ( cf.
read( elem ) )
221 if ( --num_until_dot == 0 )
224 num_until_dot = 1000;
226 if ( elem.
type_is(
"StorageArea" ) )
228 area = create_area( elem );
230 else if ( elem.
type_is(
"Item" ) )
232 if ( area !=
nullptr )
238 catch ( std::exception& )
246 ERROR_PRINT <<
"Storage: Got an ITEM element, but don't have a StorageArea to put it.\n";
247 throw std::runtime_error(
"Data file integrity error" );
252 ERROR_PRINT <<
"Unexpected element type " << elem.
type() <<
" in storage file.\n";
253 throw std::runtime_error(
"Data file integrity error" );
258 clock_t end = clock();
259 int ms =
static_cast<int>( ( end - start ) * 1000.0 / CLOCKS_PER_SEC );
261 INFO_PRINT <<
" " << nobjects <<
" elements in " << ms <<
" ms.\n";
266 for (
const auto& area : areas )
268 sw() <<
"StorageArea" <<
'\n' 270 <<
"\tName\t" << area.first <<
'\n' 273 area.second->print( sw );
280 while ( !areas.empty() )
282 delete ( ( *areas.begin() ).second );
283 areas.erase( areas.begin() );
290 for (
const auto& area : areas )
292 size += area.first.capacity() + (
sizeof(
void* ) * 3 + 1 ) / 2;
293 if ( area.second !=
nullptr )
294 size += area.second->estimateSize();
312 :
ContIterator(), m_pIterVal( pIter ), key(
"" ), _area( area )
318 StorageArea::Cont::iterator itr =
_area->
_items.lower_bound(
key );
327 key = ( *itr ).first;
353 if ( stricmp( membername,
"count" ) == 0 )
357 else if ( stricmp( membername,
"totalcount" ) == 0 )
359 unsigned int total = 0;
399 key = ( *itr ).first;
429 if ( stricmp( membername,
"count" ) == 0 )
virtual BObjectImp * copy() const POL_OVERRIDE
virtual BObjectRef get_member(const char *membername)
void warn_with_line(const std::string &errmsg) const
ContIterator * createIterator(BObject *pIterVal) POL_OVERRIDE
const std::string & value() const
std::string remove_string(const char *propname)
void get_prop(const char *propname, unsigned int *plong) const
void add_loaded_item(Items::Item *cont_item, Items::Item *item)
StorageAreaImp(StorageArea *area)
void on_delete_realm(Realms::Realm *realm)
BObjectRef get_member(const char *membername) POL_OVERRIDE
virtual std::string name() const POL_OVERRIDE
bool delete_root_item(const std::string &name)
virtual BObject * step() POL_OVERRIDE
StorageArea * create_area(const std::string &name)
unsigned current_incremental_save
Bscript::BObjectImp * CreateStorageAreasImp()
bool isa(BObjectImp::BObjectType type) const
virtual std::string getStringRep() const POL_OVERRIDE
void print(Clib::StreamWriter &sw) const
ContIterator * createIterator(BObject *pIterVal) POL_OVERRIDE
size_t estimateSize() const
void print(Clib::StreamWriter &sw) const
virtual BObjectImp * copy() const POL_OVERRIDE
const char * rest() const
StorageArea * find_area(const std::string &name)
StorageAreasIterator(BObject *pIter)
void on_delete_realm(Realms::Realm *realm)
virtual BObjectRef OperSubscript(const BObject &obj)
static UninitObject * create()
BObjectRef get_member(const char *membername) POL_OVERRIDE
virtual unsigned int item_count() const
Items::Item * read_item(Clib::ConfigElem &elem)
bool remove_prop(const char *propname, std::string *value)
Bscript::BObjectImp * make_itemref(Items::Item *item)
void read(Clib::ConfigFile &cf)
Items::Item * system_find_item(u32 serial)
virtual size_t sizeEstimate() const POL_OVERRIDE
void setrealmif(Item *item, void *arg)
BObjectRef OperSubscript(const BObject &obj) POL_OVERRIDE
bool type_is(const char *name) const
void insert_root_item(Items::Item *item)
ObjectStorageManager objStorageManager
StorageAreaIterator(StorageArea *area, BObject *pIter)
bool isa(UOBJ_CLASS uobj_class) const
void load_item(Clib::ConfigElem &elem)
virtual size_t sizeEstimate() const POL_OVERRIDE
void defer_item_insertion(Items::Item *item, pol_serial_t container_serial)
friend class StorageAreaIterator
bool read(ConfigElem &elem)
const char * type() const
size_t estimateSize() const
unsigned get_save_index(pol_serial_t serial)
Items::Item * find_root_item(const std::string &name)
virtual std::string getStringRep() const POL_OVERRIDE
StorageArea(std::string name)
virtual BObject * step() POL_OVERRIDE
virtual void for_each_item(void(*f)(Item *item, void *a), void *arg)