Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
galaxy_xml.h
Go to the documentation of this file.
1 #ifndef GALAXY_XML_H_
2 #define GALAXY_XML_H_
3 
4 #include <string>
5 #include <map>
6 #include <vector>
7 #include "gfx/vec.h"
8 #include "vsfilesystem.h"
9 
10 void ComputeSerials( std::vector< std::string > &stak );
11 
12 namespace GalaxyXML
13 {
14 using std::string;
15 typedef std::map< std::string, std::string >StringMap;
16 class SubHeirarchy;
17 class SGalaxy
18 {
19 protected:
20  friend class Galaxy;
23  SGalaxy & operator=( const SGalaxy &a );
24 
25 public: SGalaxy()
26  {
27  subheirarchy = NULL;
28  }
29  SGalaxy( const char *configfile );
30  SGalaxy( const SGalaxy &g );
31  void writeGalaxy( VSFileSystem::VSFile &f ) const;
32  void writeSector( VSFileSystem::VSFile &f, int tabs, const string &sectorType, SGalaxy *planet_types ) const;
33 
34  void processGalaxy( const string &sys );
35  void processSystem( const string &sys, const QVector &suggested_coordinates );
36 
37  ~SGalaxy();
38  const string& getVariable( const std::vector< string > &section, const string &name, const string &default_value ) const;
39  const string& getRandSystem( const string &section, const string &default_value ) const;
40  const string& getVariable( const string &section, const string &name, const string &defaultvalue ) const;
41  const string& getVariable( const string &section, const string &subsection, const string &name,
42  const string &defaultvalue ) const;
43  bool setVariable( const string &section, const string &name, const string &value );
44  bool setVariable( const string &section, const string &subsection, const string &name, const string &value );
45  void addSection( const std::vector< string > &section );
46  void setVariable( const std::vector< string > &section, const string &name, const string &value );
48  const std::string&operator[]( const std::string &s ) const
49  {
50  static std::string empty_string;
51  StringMap::const_iterator it = data.find( s );
52  if ( it != data.end() )
53  return it->second;
54 
55  else
56  return empty_string;
57  }
58 };
59 class Galaxy : public SGalaxy
60 {
61  SGalaxy * getInitialPlanetTypes();
62  SGalaxy *planet_types;
63  SGalaxy & operator=( const SGalaxy &a );
64  StringMap initial2name;
65  StringMap texture2name;
66  void setupPlanetTypeMaps();
67 public:
68 
69  const string& getPlanetNameFromInitial( const string &abbrev ) const
70  {
71  static std::string empty_string;
72  StringMap::const_iterator it = initial2name.find( abbrev );
73  if ( it != initial2name.end() )
74  return it->second;
75 
76  else
77  return empty_string;
78  }
79  const string& getPlanetNameFromTexture( const string &tex ) const
80  {
81  static std::string empty_string;
82  StringMap::const_iterator it = texture2name.find( tex );
83  if ( it != texture2name.end() )
84  return it->second;
85 
86  else
87  return empty_string;
88  }
89  const string& getPlanetVariable( const string &name, const string &defaultvalue ) const;
90  const string& getPlanetVariable( const string &planet, const string &name, const string &defaultvalue ) const;
91  void writeGalaxy( VSFileSystem::VSFile &f ) const;
93  bool setPlanetVariable( const string &name, const string &value );
94  void addPlanetSection( const std::vector< string > &section );
95  bool setPlanetVariable( const string &planet, const string &name, const string &value );
97  {
98  subheirarchy = NULL;
99  planet_types = NULL;
100  }
101  Galaxy( const char *configfile );
102  Galaxy( const SGalaxy &g );
103 };
104 
105 class SubHeirarchy : public vsUMap< std::string, class SGalaxy >
106 {};
107 }
108 
109 string getStarSystemFileName( const string &input );
110 string getStarSystemName( const string &in );
111 string getStarSystemSector( const string &in );
112 #endif
113