FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTLandscapeParser.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Qu�bec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTlandscapeparser_Hm_included
9#define FMTlandscapeparser_Hm_included
10
11
12#include "FMTParser.h"
13#include "FMTutility.h"
14#include <boost/regex.hpp>
15#include <string>
16#include <map>
17#include <vector>
18
19namespace Core
20{
21 class FMTTheme;
22 class FMTConstants;
23}
24
25
26namespace Parser
27{
28// DocString: FMTLandscapeParser
34 {
35 public:
36 // DocString: FMTLandscapeParser::FMTLandscapeParser()
41 // DocString: FMTLandscapeParser::~FMTLandscapeParser()
46 // DocString: FMTLandscapeParser::FMTLandscapeParser(const FMTLandscapeParser&)
52 // DocString: FMTLandscapeParser::operator=
58 FMTLandscapeParser& operator = (const FMTLandscapeParser& rhs)=default;
59 // DocString: FMTLandscapeParser::read
66 std::vector<Core::FMTTheme>read(const Core::FMTConstants& constants,const std::string& location);
67 #ifdef FMTWITHGDAL
68 // DocString: FMTLandscapeParser::readVectors
74 std::vector<Core::FMTTheme>readVectors(const std::string& location);
75 // DocString: FMTLandscapeParser::readRasters
81 std::vector<Core::FMTTheme>readRasters(const std::vector< std::string>& locations);
82 #endif
83 // DocString: FMTLandscapeParser::write
89 void write(const std::vector<Core::FMTTheme>& themes,const std::string& location) const;
90 private:
91 // DocString: FMTLandscapeParser::m_rxcleanlans
93 const static boost::regex m_rxcleanlans;
94 // DocString: FMTLandscapeParser::m_rxindex
96 const static boost::regex m_rxindex;
97 // DocString: FMTLandscapeParser::m_rxparameter
99 const static boost::regex m_rxparameter;
100 // DocString: FMTLandscapeParser::m_rxPreAttributes
101 const static boost::regex m_rxPreAttributes;
102 // DocString: FMTLandscapeParser::m_rxPreAggregate
103 const static boost::regex m_rxPreAggregate;
104 // DocString: FMTLandscapeParser::_getIndexes
111 std::map<std::string, double> _getIndexes(
112 std::string indexm_line,
113 const Core::FMTConstants& constants);
114 // DocString: FMTLandscapeParser::ParseState
118 enum class ParseState {NORMAL = 0, IN_PRE_DECLARATION = 1};
119 // DocString: FMTLandscapeParser::preDeclarationContext
123 struct preDeclarationContext {
124 ParseState state;
125 std::string currentKey;
126 std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string>>> declarations;
127
128 // DocString: FMTLandscapeParser::preDeclarationContext()
132 preDeclarationContext();
133 // DocString: FMTLandscapeParser::preDeclarationContext::clearTheme
138 void clearTheme(std::string nameID);
139 };
140 // DocString: FMTLandscapeParser::_processPreDeclarationLine
148 bool _processPreDeclarationLine(
149 const std::string& line,
150 preDeclarationContext& context,
151 const Core::FMTConstants& constants);
152 // DocString: FMTLandscapeParser::themeParsingContext
156 struct themeParsingContext {
157 std::vector<std::string> attributes;
158 std::vector<std::string> attributenames;
159 std::vector<std::string> aggregates;
160 std::vector<std::vector<std::string>> aggregatenames;
161 std::vector<std::map<std::string, double>> indexes_values;
162 std::string themename;
163 std::string aggregatename;
164 size_t id;
165 size_t start;
166 size_t stop;
167 int pasttheme;
168 bool aggregate_redefinition;
169
170 // DocString: FMTLandscapeParser::themeParsingContext()
174 themeParsingContext();
175 // DocString: FMTLandscapeParser::themeParsingContext::clear
179 void clear();
180 };
181 // DocString: FMTLandscapeParser::_processThemeLine
191 void _processThemeLine(
192 const boost::smatch& kmatch,
193 themeParsingContext& ctx,
194 preDeclarationContext& preContext,
195 std::vector<Core::FMTTheme>& themes,
196 const Core::FMTConstants& constants,
197 size_t& unknownID);
198 // DocString: FMTLandscapeParser::_processAggregateLine
206 void _processAggregateLine(
207 const boost::smatch& kmatch,
208 themeParsingContext& ctx,
209 std::vector<Core::FMTTheme>& themes,
210 const Core::FMTConstants& constants);
211 // DocString: FMTLandscapeParser::_processAggregateValueLine
218 void _processAggregateValueLine(
219 const std::string& line,
220 themeParsingContext& ctx,
221 std::vector<Core::FMTTheme>& themes);
222 // DocString: FMTLandscapeParser::_processAttributeLine
229 void _processAttributeLine(
230 const std::string& line,
231 themeParsingContext& ctx,
232 const Core::FMTConstants& constants);
233 };
234}
235
236
237#endif // FMTlandscapeparser_Hm_included
#define FMTEXPORT
Definition: FMTutility.h:125
Class holding the constants defined in the constants section of a model, used by the parsers.
Definition: FMTConstants.h:28
Parser reading and writing the landscape section, and generating themes from vector or raster files.
Definition: FMTLandscapeParser.h:34
~FMTLandscapeParser()=default
Default destructor for FMTLandscapeParser.
std::vector< Core::FMTTheme > readRasters(const std::vector< std::string > &locations)
Return the themes present in a vector of raster files, one theme per raster.
std::vector< Core::FMTTheme > readVectors(const std::string &location)
Return the themes present in a spatial vector file.
FMTLandscapeParser(const FMTLandscapeParser &rhs)=default
Copy constructor for FMTLandscapeParser.
FMTLandscapeParser()
Default constructor for FMTLandscapeParser.
std::vector< Core::FMTTheme > read(const Core::FMTConstants &constants, const std::string &location)
Read the landscape section and return the themes.
void write(const std::vector< Core::FMTTheme > &themes, const std::string &location) const
Write a landscape section from a vector of themes.
Main parent class of all the parsers in FMT.
Definition: FMTParser.h:72
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27