Pol  Revision:4b29d2b
ucfg.cpp
Go to the documentation of this file.
1 
2 #include "ucfg.h"
3 
4 #include <string.h>
5 
6 #include "../cfgrepos.h"
7 #include "../module/datastoreimp.h"
8 
9 namespace Pol
10 {
11 namespace Core
12 {
14 
16  : cfgfiles(), oldcfgfiles(), datastore(), file_access_rules()
17 {
18 }
19 
21 
23 {
24  // ToDo: we have to think over... it's a problem with script-inside references
25  oldcfgfiles.clear();
26  cfgfiles.clear();
27 
28  for ( Core::DataStore::iterator itr = datastore.begin(); itr != datastore.end(); ++itr )
29  {
30  Module::DataStoreFile* dsf = ( *itr ).second;
31  delete dsf;
32  }
33  datastore.clear();
34  file_access_rules.clear();
35 }
36 
38 {
39  Memory usage;
40  memset( &usage, 0, sizeof( usage ) );
41 
42  usage.misc = 3 * sizeof( std::string* );
43  for ( const auto& oldcfg : oldcfgfiles )
44  usage.misc += oldcfg.capacity();
45  usage.misc += 3 * sizeof( Module::FileAccess* );
46  for ( const auto& rule : file_access_rules )
47  usage.misc += rule.estimateSize();
48 
49 
50  usage.cfg_count = cfgfiles.size();
51  for ( const auto& pair : cfgfiles )
52  {
53  size_t cfgsize = 0;
54  if ( pair.second.get() != nullptr )
55  cfgsize += pair.second->estimateSize();
56  usage.cfg_size += ( pair.first.capacity() + cfgsize ) + ( sizeof( void* ) * 3 + 1 ) / 2;
57  }
58 
59  usage.datastore_count = datastore.size();
60  for ( const auto& data : datastore )
61  {
62  usage.datastore_size += ( data.first.capacity() + sizeof( Module::DataStoreFile* ) +
63  ( sizeof( void* ) * 3 + 1 ) / 2 );
64  if ( data.second != nullptr )
65  usage.datastore_size += data.second->estimateSize();
66  }
67  return usage;
68 }
69 }
70 }
OldCfgFiles oldcfgfiles
Definition: ucfg.h:50
std::vector< Module::FileAccess > file_access_rules
Definition: ucfg.h:52
Memory estimateSize() const
Definition: ucfg.cpp:37
ConfigurationBuffer configurationbuffer
Definition: ucfg.cpp:13
std::unordered_map< u64, ScriptDiffData > data
Definition: osmod.cpp:966
Definition: berror.cpp:12