Pol  Revision:cb584c9
proplist.h
Go to the documentation of this file.
1 
9 #ifndef PROPLIST_H
10 #define PROPLIST_H
11 
12 #include <array>
13 #include <boost/flyweight.hpp>
14 #include <iosfwd>
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <vector>
19 
20 #include "../clib/boostutils.h"
21 #include "../clib/rawtypes.h"
22 #include "../clib/spinlock.h"
23 
24 namespace Pol
25 {
26 namespace Bscript
27 {
28 class BObjectImp;
29 class Executor;
30 }
31 namespace Clib
32 {
33 class ConfigElem;
34 class StreamWriter;
35 }
36 namespace Core
37 {
38 class PropertyList;
39 
40 enum class UOBJ_CLASS : u8;
41 
48 {
49 public:
53  enum class Type : u8
54  {
55  // main types
56  ACCOUNT,
57  GUILD,
58  GLOBAL,
59  ITEM,
60  MOBILE,
61  MULTI,
62  PARTY,
63 
64  // ignored types
65  DATAFILEELEMENT,
66  REGION,
67 
69  UNKNOWN,
70  };
71 
72  static Type class_to_type( UOBJ_CLASS oclass );
73 
75  static CPropProfiler& instance();
76 
78  CPropProfiler( const CPropProfiler& ) = delete;
80  CPropProfiler& operator=( const CPropProfiler& ) = delete;
81 
82  void registerProplist( const PropertyList* proplist, const Type type );
83  void registerProplist( const PropertyList* proplist, const PropertyList* copiedFrom );
84  void unregisterProplist( const PropertyList* proplist );
85 
86  void clear();
87  void dumpProfile( std::ostream& os ) const;
88  size_t estimateSize() const;
89 
90 private:
92  {
93  public:
94  static const size_t READ = 0;
95  static const size_t WRITE = 1;
96  static const size_t ERASE = 2;
97 
98  HitsCounter();
99  u64& operator[]( size_t idx );
100  const u64& operator[]( size_t idx ) const;
101  size_t sizeEstimate() const;
102 
103  private:
105  std::array<u64, 3> hits;
106  };
107  typedef std::map<const PropertyList*, const Type> PropLists;
108  typedef std::map<const std::string, HitsCounter> HitsEntries;
109  typedef std::map<const Type, HitsEntries> Hits;
110 
111  CPropProfiler();
112 
113  Type getProplistType( const PropertyList* proplist ) const;
114  bool isIgnored( Type type ) const;
115  void cpropAction( const PropertyList* proplist, const std::string& name, const size_t key );
116 
117  std::unique_ptr<PropLists> _proplists;
118  std::unique_ptr<Hits> _hits;
121 
122 public:
123  void cpropRead( const PropertyList* proplist, const std::string& name );
124  void cpropWrite( const PropertyList* proplist, const std::string& name );
125  void cpropErase( const PropertyList* proplist, const std::string& name );
126 };
127 
128 
133 {
134 public:
135  PropertyList() = delete;
137  PropertyList( CPropProfiler::Type type, bool force );
138  PropertyList( const PropertyList& ); // dave added 1/26/3
139  bool getprop( const std::string& propname, std::string& propvalue ) const;
140  void setprop( const std::string& propname, const std::string& propvalue );
141  void eraseprop( const std::string& propname );
142  void copyprops( const PropertyList& proplist );
143  void getpropnames( std::vector<std::string>& propnames ) const;
144  void clear();
145  size_t estimatedSize() const;
146 
147  void printProperties( Clib::StreamWriter& sw ) const;
148  void printProperties( Clib::ConfigElem& elem ) const;
149  void readProperties( Clib::ConfigElem& elem );
150 
151  void printPropertiesAsStrings( Clib::StreamWriter& sw ) const;
152  void readRemainingPropertiesAsStrings( Clib::ConfigElem& elem );
153 
154  bool operator==( const PropertyList& ) const;
155  PropertyList& operator-( const std::set<std::string>& ); // dave added 1/26/3
156  void operator-=( const std::set<std::string>& ); // dave added 1/26/3
157 protected:
158  typedef std::map<boost_utils::cprop_name_flystring, boost_utils::cprop_value_flystring>
160 
162 
163 private:
164  // not implemented
165  PropertyList& operator=( const PropertyList& ) = delete;
166 };
167 
168 Bscript::BObjectImp* CallPropertyListMethod( PropertyList& proplist, const char* methodname,
169  Bscript::Executor& ex, bool& changed );
171  Bscript::Executor& ex, bool& changed );
172 }
173 }
174 #endif
unsigned char u8
Definition: rawtypes.h:25
std::map< boost_utils::cprop_name_flystring, boost_utils::cprop_value_flystring > Properties
Definition: proplist.h:159
std::unique_ptr< Hits > _hits
Definition: proplist.h:118
std::array< u64, 3 > hits
0=read, 1=write, 2=erase
Definition: proplist.h:105
Clib::SpinLock _hitsLock
Definition: proplist.h:120
bool operator==(T *ptr, const ref_ptr< T > &rptr)
Definition: refptr.h:311
std::unique_ptr< PropLists > _proplists
Definition: proplist.h:117
Bscript::BObjectImp * CallPropertyListMethod_id(PropertyList &proplist, const int id, Bscript::Executor &ex, bool &changed)
Definition: proplist.cpp:520
unsigned long long u64
Definition: rawtypes.h:38
Properties properties
Definition: proplist.h:161
std::map< const PropertyList *, const Type > PropLists
Definition: proplist.h:107
std::map< const std::string, HitsCounter > HitsEntries
Definition: proplist.h:108
std::map< const Type, HitsEntries > Hits
Definition: proplist.h:109
Clib::SpinLock _proplistsLock
Definition: proplist.h:119
std::string name
Definition: osmod.cpp:943
Bscript::BObjectImp * CallPropertyListMethod(PropertyList &proplist, const char *methodname, Bscript::Executor &ex, bool &changed)
Definition: proplist.cpp:591
Definition: berror.cpp:12