fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fg_config.hxx
Go to the documentation of this file.
1 /**
2  * @file fg_config.hxx
3  * @author Oliver Schroeder
4  */
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U$
19 //
20 // Copyright (C) 2005 Oliver Schroeder
21 //
22 
23 /**
24  * @class FG_CONFIG
25  * @brief Simple config file parser
26  *
27  * * The FG_CONFIG class, loads and parses, if it can, the \ref fgms_conf file.
28  * * An instance is created the ::ProcessConfig function if main.cxx
29  */
30 
31 //////////////////////////////////////////////////////////////////////
32 //
33 // Simple configfile parser for fg_server
34 //
35 //////////////////////////////////////////////////////////////////////
36 
37 #ifndef FG_CONFIG_HEADER
38 #define FG_CONFIG_HEADER
39 
40 #include <string>
41 #include <iostream>
42 #include <fstream>
43 #include <list>
44 #include <utility>
45 
46 class FG_CONFIG
47 {
48 public:
49  int Read ( const std::string &ConfigName );
50  void Dump ();
51  void SetStart ();
52  int Next ();
53  std::string Get ( const std::string &VarName );
54  std::string GetName ();
55  std::string GetValue ();
56  std::string GetNext ();
57  int SetSection ( const std::string &SecName );
58  int SecNext ();
59  std::string GetSecNextVar ();
60  std::string GetSecNextVal ();
61 private:
62  typedef std::pair<std::string,std::string> mT_VarValue;
63  typedef std::list<mT_VarValue> mT_VarList;
64  int ParseLine ( const std::string &ConfigLine );
65  mT_VarList m_VarList;
66  mT_VarList::iterator m_CurrentVar;
67  std::string m_CurrentSection;
68 };
69 
70 #endif
71 
Simple config file parser.
Definition: fg_config.hxx:46
int Read(const std::string &ConfigName)
Read in the config file.
Definition: fg_config.cxx:42
void Dump()
Just for debugging to cout.
Definition: fg_config.cxx:290
std::string GetSecNextVal()
Return variable value of next variable in section.
Definition: fg_config.cxx:250
int Next()
Set internal pointer to the next var.
Definition: fg_config.cxx:118
int SecNext()
Set internal pointer to next variable in a section.
Definition: fg_config.cxx:205
void SetStart()
Set internal pointer to the first variable in list.
Definition: fg_config.cxx:105
std::string GetSecNextVar()
Get the next variable name in current section.
Definition: fg_config.cxx:227
std::string m_CurrentSection
Definition: fg_config.hxx:67
mT_VarList::iterator m_CurrentVar
Definition: fg_config.hxx:66
std::string GetValue()
Returns the current variable's value.
Definition: fg_config.cxx:159
std::pair< std::string, std::string > mT_VarValue
Definition: fg_config.hxx:62
int SetSection(const std::string &SecName)
Set internal pointer to the first variable of a section.
Definition: fg_config.cxx:179
std::string GetName()
Returns the complete name of the current variable.
Definition: fg_config.cxx:141
std::string GetNext()
Get the value of the next variable in list.
Definition: fg_config.cxx:273
std::list< mT_VarValue > mT_VarList
Definition: fg_config.hxx:63
std::string Get(const std::string &VarName)
Find a variable in the internal list and return its value.
Definition: fg_config.cxx:81
int ParseLine(const std::string &ConfigLine)
Parse the given line, split it into name/value pairs and put in the internal list.
Definition: fg_config.cxx:318
mT_VarList m_VarList
Definition: fg_config.hxx:65