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
configxml.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 /*
23  * xml Configuration written by Alexander Rawass <alexannika@users.sourceforge.net>
24  */
25 
26 #ifndef _VEGASIMPLECONFIG_H_
27 #define _VEGASIMPLECONFIG_H_
28 
29 #include <expat.h>
30 #include <string>
31 #include "xml_support.h"
32 #include "easydom.h"
33 #include <map>
34 
35 using std::string;
36 using std::map;
37 
39 
40 class vColor
41 {
42 public:
43  string name;
44  float r, g, b, a;
45 };
46 
47 class configNode : public easyDomNode
48 {
49 public:
51 };
52 
54 
55 class configNodeFactory : public easyDomFactory< configNode >
56 {};
57 
59 {
60 public:
61  explicit VegaConfig( const char *configfile );
62  virtual ~VegaConfig();
63 #define MAX_AXIS 32
67 #define MAX_HATSWITCHES 16
68 #define MAX_VALUES 12
73  void getColor( configNode*node, string name, float color[4], bool have_color = false );
74  void getColor( string section, string name, float color[4], bool have_color = false );
75  void gethColor( string section, string name, float color[4], int hexcolor );
76  void getColor( string name, float color[4], bool have_color = false )
77  {
78  getColor( "default", name, color, have_color );
79  }
80  string getVariable( string section, string name, string defaultvalue );
81  string getVariable( string section, string subsection, string name, string defaultvalue );
82  configNode * findSection( string section, configNode *startnode );
83  configNode * findEntry( string name, configNode *startnode );
84  void setVariable( configNode *entry, string value );
85  bool setVariable( string section, string name, string value );
86  bool setVariable( string section, string subsection, string name, string value );
88  {
89  return variables;
90  }
91  virtual void bindKeys() {}
92 protected:
93  string getVariable( configNode *section, string name, string defaultval );
97  map< string, string >map_variables;
98  map< string, vColor >map_colors;
100 //vector<vColor *> colors;
101  bool checkConfig( configNode *node );
102  void doVariables( configNode *node );
103  void checkSection( configNode *node, enum section_t section_type );
104  void checkVar( configNode *node );
105  void doSection( string prefix, configNode *node, enum section_t section_type );
106  void doVar( string prefix, configNode *node );
107  void doColors( configNode *node );
108  bool checkColor( string prefix, configNode *node );
109  virtual void doBindings( configNode *node ) {}
110  virtual void checkBind( configNode *node ) {}
111  virtual void doAxis( configNode *node ) {}
112  virtual void checkHatswitch( int nr, configNode *node ) {}
113 };
114 
115 #endif //_VEGACONFIG_H_
116