Pol  Revision:4b29d2b
datastoreimp.h
Go to the documentation of this file.
1 
7 #ifndef DATASTOREIMP_H
8 #define DATASTOREIMP_H
9 
10 #include "../../bscript/bobject.h"
11 
12 #include "../proplist.h"
13 
14 #include <map>
15 #include <string>
16 
17 namespace Pol
18 {
19 namespace Clib
20 {
21 class ConfigElem;
22 class ConfigFile;
23 class StreamWriter;
24 }
25 namespace Plib
26 {
27 class Package;
28 }
29 namespace Module
30 {
32 {
33 public:
35  explicit DataFileElement( Clib::ConfigElem& elem );
36  void printOn( Clib::StreamWriter& sw ) const;
37 
39 };
41 
42 // const int DF_KEYTYPE_STRING = 0x00; // currently unneeded
43 const int DF_KEYTYPE_INTEGER = 0x01;
44 
46 {
47 public:
49  virtual ~DataFileContents();
50  size_t estimateSize() const;
51 
52  void load( Clib::ConfigFile& cf );
53  void save( Clib::StreamWriter& sw );
54 
55  Bscript::BObjectImp* methodCreateElement( int key );
56  Bscript::BObjectImp* methodCreateElement( const std::string& key );
57 
58  Bscript::BObjectImp* methodFindElement( int key );
59  Bscript::BObjectImp* methodFindElement( const std::string& key );
60 
61  Bscript::BObjectImp* methodDeleteElement( int key );
62  Bscript::BObjectImp* methodDeleteElement( const std::string& key );
63 
64  Bscript::BObjectImp* methodKeys() const;
65 
67  bool dirty;
68 
69 private:
70  typedef std::map<std::string, DataFileElementRef, Clib::ci_cmp_pred> ElementsByString;
71  typedef std::map<int, DataFileElementRef> ElementsByInteger;
72 
73  ElementsByString elements_by_string;
74  ElementsByInteger elements_by_integer;
75 };
77 
78 
80 
81 class DataFileRefObjImp : public DataFileRefObjImpBase
82 {
83 public:
84  explicit DataFileRefObjImp( DataFileContentsRef dfref );
85 
86  virtual const char* typeOf() const POL_OVERRIDE;
87  virtual u8 typeOfInt() const POL_OVERRIDE;
88  virtual Bscript::BObjectImp* copy() const POL_OVERRIDE;
89 
90  virtual Bscript::BObjectImp* call_method( const char* methodname,
92  virtual Bscript::BObjectImp* call_method_id( const int id, Bscript::Executor& ex,
93  bool forcebuiltin = false ) POL_OVERRIDE;
94 };
95 
96 
98 {
99 public:
100  DataFileElemObj( DataFileContentsRef dfcontents, DataFileElementRef dfelem )
101  : dfcontents( dfcontents ), dfelem( dfelem )
102  {
103  }
104 
105 public:
106  DataFileContentsRef dfcontents;
107  DataFileElementRef dfelem;
108 };
109 
111 class DataElemRefObjImp : public DataElemRefObjImpBase
112 {
113 public:
114  DataElemRefObjImp( DataFileContentsRef dfcontents, DataFileElementRef dflem );
115  virtual const char* typeOf() const POL_OVERRIDE;
116  virtual u8 typeOfInt() const POL_OVERRIDE;
117  virtual Bscript::BObjectImp* copy() const POL_OVERRIDE;
118 
119  virtual Bscript::BObjectImp* call_method( const char* methodname,
121  virtual Bscript::BObjectImp* call_method_id( const int id, Bscript::Executor& ex,
122  bool forcebuiltin = false ) POL_OVERRIDE;
123 };
124 
126 {
127 public:
128  explicit DataStoreFile( Clib::ConfigElem& elem );
129  DataStoreFile( const std::string& descriptor, const Plib::Package* pkg, const std::string& name,
130  int flags );
131  virtual ~DataStoreFile();
132  size_t estimateSize() const;
133  bool loaded() const;
134  void load();
135  void save() const;
136  std::string filename() const;
137  std::string filename( unsigned ver ) const;
138  void printOn( Clib::StreamWriter& sw ) const;
139 
140  std::string descriptor;
141  std::string name;
142 
143  std::string pkgname;
145  unsigned version;
146  unsigned oldversion;
147  int flags;
148  bool unload;
149 
150  unsigned delversion;
151 
152  DataFileContentsRef dfcontents;
153 };
154 }
155 }
156 
157 #endif
unsigned char u8
Definition: rawtypes.h:25
DataFileContentsRef dfcontents
Definition: datastoreimp.h:152
ElementsByInteger elements_by_integer
Definition: datastoreimp.h:74
#define POL_OVERRIDE
Bscript::BApplicObj< DataFileElemObj > DataElemRefObjImpBase
Definition: datastoreimp.h:110
std::map< int, DataFileElementRef > ElementsByInteger
Definition: datastoreimp.h:71
ElementsByString elements_by_string
Definition: datastoreimp.h:73
Bscript::BApplicObj< DataFileContentsRef > DataFileRefObjImpBase
Definition: datastoreimp.h:79
std::map< std::string, DataFileElementRef, Clib::ci_cmp_pred > ElementsByString
Definition: datastoreimp.h:70
ref_ptr< DataFileElement > DataFileElementRef
Definition: datastoreimp.h:40
ref_ptr< DataFileContents > DataFileContentsRef
Definition: datastoreimp.h:76
Core::PropertyList proplist
Definition: datastoreimp.h:38
const Plib::Package * pkg
Definition: datastoreimp.h:144
DataFileElemObj(DataFileContentsRef dfcontents, DataFileElementRef dfelem)
Definition: datastoreimp.h:100
std::string name
Definition: osmod.cpp:943
DataFileElementRef dfelem
Definition: datastoreimp.h:107
const int DF_KEYTYPE_INTEGER
Definition: datastoreimp.h:43
DataFileContentsRef dfcontents
Definition: datastoreimp.h:106
Definition: berror.cpp:12