Pol  Revision:cb584c9
storage.h
Go to the documentation of this file.
1 
7 #ifndef H_STORAGE_H
8 #define H_STORAGE_H
9 
10 #include <map>
11 #include <string>
12 
13 #include "../clib/maputil.h"
14 
15 namespace Pol
16 {
17 namespace Items
18 {
19 class Item;
20 }
21 namespace Realms
22 {
23 class Realm;
24 }
25 namespace Clib
26 {
27 class ConfigFile;
28 class ConfigElem;
29 class StreamWriter;
30 }
31 namespace Core
32 {
34 {
35 public:
36  StorageArea( std::string name );
37  ~StorageArea();
38 
39  Items::Item* find_root_item( const std::string& name );
40  void insert_root_item( Items::Item* item );
41  bool delete_root_item( const std::string& name );
42  void on_delete_realm( Realms::Realm* realm );
43 
44  void print( Clib::StreamWriter& sw ) const;
45  void load_item( Clib::ConfigElem& elem );
46  size_t estimateSize() const;
47 
48 private:
49  std::string _name;
50 
51  // TODO: ref_ptr<Item> ?
52  typedef std::map<std::string, Items::Item*, Clib::ci_cmp_pred> Cont;
53  Cont _items; // owns its items.
54 
55  friend class StorageAreaImp;
56  friend class StorageAreaIterator;
58 };
59 
60 class Storage
61 {
62 public:
63  StorageArea* find_area( const std::string& name );
64  StorageArea* create_area( const std::string& name );
65  StorageArea* create_area( Clib::ConfigElem& elem );
66  void on_delete_realm( Realms::Realm* realm );
67 
68  void print( Clib::StreamWriter& sw ) const;
69  void read( Clib::ConfigFile& cf );
70  void clear();
71  size_t estimateSize() const;
72 
73 private:
74  // TODO: investigate if this could store objects. Does find()
75  // return object copies, or references?
76  typedef std::map<std::string, StorageArea*> AreaCont;
77  AreaCont areas;
78 
79  friend class StorageAreasImp;
80  friend class StorageAreasIterator;
82 };
83 }
84 }
85 #endif
void write_dirty_storage(Clib::StreamWriter &sw_data)
Definition: savedata.cpp:61
std::string _name
Definition: storage.h:49
std::map< std::string, Items::Item *, Clib::ci_cmp_pred > Cont
Definition: storage.h:52
std::map< std::string, StorageArea * > AreaCont
Definition: storage.h:76
AreaCont areas
Definition: storage.h:77
std::string name
Definition: osmod.cpp:943
Definition: berror.cpp:12