Pol  Revision:cb584c9
realmdescriptor.cpp
Go to the documentation of this file.
1 
7 #include "realmdescriptor.h"
8 
9 #include "../clib/cfgelem.h"
10 #include "../clib/cfgfile.h"
11 #include "../clib/strutil.h"
12 
13 
14 namespace Pol
15 {
16 namespace Plib
17 {
18 RealmDescriptor RealmDescriptor::Load( const std::string& realm_name,
19  const std::string& realm_path )
20 {
21  std::string realm_cfg_filename;
22  if ( realm_path == "" )
23  realm_cfg_filename = "realm/" + realm_name + "/realm.cfg";
24  else
25  realm_cfg_filename = realm_path + "/realm.cfg";
26 
27  Clib::ConfigFile cf( realm_cfg_filename, "REALM" );
28  Clib::ConfigElem elem;
29  if ( !cf.read( elem ) )
30  elem.throw_error( "Unable to read configuration file " + realm_cfg_filename );
31 
32  return RealmDescriptor( realm_name, realm_path, elem );
33 }
34 
35 namespace
36 {
37 unsigned short calc_grid_size( const unsigned size )
38 {
39  unsigned grid_size = size / WGRID_SIZE;
40  // Tokuno-Fix
41  if ( grid_size * WGRID_SIZE < size )
42  grid_size++;
43  return static_cast<unsigned short>( grid_size );
44 }
45 }
46 
47 RealmDescriptor::RealmDescriptor( const std::string& realm_name, const std::string& realm_path,
48  Clib::ConfigElem& elem )
49  : name( realm_name ),
50  file_path( realm_path ),
51  width( elem.remove_ushort( "width" ) ),
52  height( elem.remove_ushort( "height" ) ),
53  uomapid( elem.remove_unsigned( "uomapid", 0 ) ),
54  uodif( elem.remove_bool( "uodif", false ) ),
55  num_map_patches( elem.remove_unsigned( "num_map_patches", 0 ) ),
56  num_static_patches( elem.remove_unsigned( "num_static_patches", 0 ) ),
57  season( elem.remove_unsigned( "season", 1 ) ),
58  mapserver_type( Clib::strlower( elem.remove_string( "mapserver", "memory" ) ) ),
59  grid_width( calc_grid_size( width ) ),
60  grid_height( calc_grid_size( height ) )
61 {
62 }
63 
65 {
66  size_t size = sizeof( *this );
67  size += name.capacity() + file_path.capacity() + mapserver_type.capacity();
68  return size;
69 }
70 
71 std::string RealmDescriptor::path( const std::string& filename ) const
72 {
73  if ( file_path == "" )
74  return "realm/" + name + "/" + filename;
75  else
76  return file_path + "/" + filename;
77 }
78 }
79 }
static RealmDescriptor Load(const std::string &realm_name, const std::string &realm_path="")
POL_NORETURN void throw_error(const std::string &errmsg) const
Definition: cfgfile.cpp:285
std::string path(const std::string &filename) const
std::string strlower(const std::string &str)
Definition: strutil.cpp:276
const unsigned WGRID_SIZE
RealmDescriptor(const std::string &realm_name, const std::string &realm_path, Clib::ConfigElem &elem)
bool read(ConfigElem &elem)
Definition: cfgfile.cpp:1015
Definition: berror.cpp:12