CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
yaml_parser.h
Go to the documentation of this file.
1
12
13/* ==============================================================================================================================
14
15 This file is part of CoastalME, the Coastal Modelling Environment.
16
17 CoastalME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23==============================================================================================================================*/
24#ifndef YAML_PARSER_H
25#define YAML_PARSER_H
26
27#include <string>
28#include <map>
29#include <vector>
30#include <fstream>
31
32using std::string;
33using std::map;
34using std::vector;
35using std::ifstream;
36
39{
40private:
41 string m_strValue;
42 map<string, CYamlNode> m_mapChildren;
43 vector<CYamlNode> m_vecChildren;
45
46public:
47 CYamlNode();
48 ~CYamlNode();
49
50 void SetValue(string const& strValue);
51 void AddChild(string const& strKey, CYamlNode const& node);
52 void AddSequenceItem(CYamlNode const& node);
53
54 string GetValue() const;
55 bool HasChild(string const& strKey) const;
56 CYamlNode GetChild(string const& strKey) const;
57 vector<CYamlNode> GetSequence() const;
58 bool IsSequence() const;
59 int GetSequenceSize() const;
60
61 // Convenience methods for common types
62 int GetIntValue(int nDefault = 0) const;
63 double GetDoubleValue(double dDefault = 0.0) const;
64 bool GetBoolValue(bool bDefault = false) const;
65 vector<string> GetStringSequence() const;
66};
67
70{
71private:
75 string m_strError;
76
77 // Helper methods
78 int nGetIndentLevel(string const& strLine) const;
79 string strTrimLeft(string const& strLine) const;
80 string strTrimRight(string const& strLine) const;
81 string strTrim(string const& strLine) const;
82 bool bIsComment(string const& strLine) const;
83 bool bIsEmpty(string const& strLine) const;
84 bool bParseLine(string const& strLine, string& strKey, string& strValue, bool& bIsSequence) const;
85 string strRemoveQuotes(string const& strValue) const;
86 CYamlNode ParseSection(ifstream& fileStream, int nBaseIndent);
87
88public:
91
92 bool bParseFile(string const& strFileName);
93 CYamlNode GetRoot() const;
94 string GetError() const;
95 bool bHasError() const;
96};
97
98#endif // YAML_PARSER_H
Simple YAML node class to represent parsed values.
Definition yaml_parser.h:39
map< string, CYamlNode > m_mapChildren
Definition yaml_parser.h:42
string m_strValue
Definition yaml_parser.h:41
bool m_bIsSequence
Definition yaml_parser.h:44
bool IsSequence() const
int GetSequenceSize() const
vector< string > GetStringSequence() const
vector< CYamlNode > m_vecChildren
Definition yaml_parser.h:43
string GetValue() const
vector< CYamlNode > GetSequence() const
bool HasChild(string const &strKey) const
void AddChild(string const &strKey, CYamlNode const &node)
bool GetBoolValue(bool bDefault=false) const
void AddSequenceItem(CYamlNode const &node)
double GetDoubleValue(double dDefault=0.0) const
CYamlNode GetChild(string const &strKey) const
int GetIntValue(int nDefault=0) const
void SetValue(string const &strValue)
string strRemoveQuotes(string const &strValue) const
CYamlNode m_RootNode
Definition yaml_parser.h:72
string strTrim(string const &strLine) const
string m_strFileName
Definition yaml_parser.h:73
string strTrimRight(string const &strLine) const
int m_nCurrentLine
Definition yaml_parser.h:74
bool bParseLine(string const &strLine, string &strKey, string &strValue, bool &bIsSequence) const
string m_strError
Definition yaml_parser.h:75
string GetError() const
bool bIsComment(string const &strLine) const
string strTrimLeft(string const &strLine) const
CYamlNode ParseSection(ifstream &fileStream, int nBaseIndent)
bool bParseFile(string const &strFileName)
bool bHasError() const
int nGetIndentLevel(string const &strLine) const
CYamlNode GetRoot() const
bool bIsEmpty(string const &strLine) const