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::ifstream;
33using std::map;
34using std::string;
35using std::vector;
36
39{
40 private:
41 string m_strValue;
42 map<string, CYamlNode> m_mapChildren;
43 vector<CYamlNode> m_vecChildren;
45
46 public:
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 unsigned long GetULongValue(unsigned long nDefault = 0) const;
64 double GetDoubleValue(double dDefault = 0.0) const;
65 bool GetBoolValue(bool bDefault = false) const;
66 vector<string> GetStringSequence() const;
67};
68
71{
72 private:
76 string m_strError;
77
78 // Helper methods
79 int nGetIndentLevel(string const& strLine) const;
80 string strTrimLeft(string const& strLine) const;
81 string strTrimRight(string const& strLine) const;
82 string strTrim(string const& strLine) const;
83 bool bIsComment(string const& strLine) const;
84 bool bIsEmpty(string const& strLine) const;
85 bool bParseLine(string const& strLine, string& strKey, string& strValue, bool& bIsSequence) const;
86 string strRemoveQuotes(string const& strValue) const;
87 CYamlNode ParseSection(ifstream& fileStream, int nBaseIndent);
88
89 public:
92
93 bool bParseFile(string const& strFileName);
94 CYamlNode GetRoot() const;
95 string GetError() const;
96 bool bHasError() const;
97};
98
99#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
unsigned long GetULongValue(unsigned long nDefault=0) 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:73
string strTrim(string const &strLine) const
string m_strFileName
Definition yaml_parser.h:74
string strTrimRight(string const &strLine) const
int m_nCurrentLine
Definition yaml_parser.h:75
bool bParseLine(string const &strLine, string &strKey, string &strValue, bool &bIsSequence) const
string m_strError
Definition yaml_parser.h:76
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