FMT 1.3.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTParser.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 FMTparser_Hm_included
9#define FMTparser_Hm_included
10
11#include <boost/regex.hpp>
12#include <iterator>
13#include <iostream>
14#include <fstream>
15#include <string>
16#include <vector>
17#include <queue>
18#include "FMTutility.h"
19#include <array>
20#include <ctime>
21#include <mutex>
22
23
24#include <boost/thread/recursive_mutex.hpp>
25
26
27
28#include "FMTObject.h"
29#if defined FMTWITHGDAL
30 class OGRSpatialReference;
31 class GDALDataset;
32 class OGRLayer;
33 class GDALRasterBand;
34 class GDALDriver;
35 class OGRSpatialReference;
36 class OGRCoordinateTransformation;
37#endif
38
39
40
41namespace Core {
42 class FMTTheme;
43 class FMTAction;
44 class FMTYields;
45 class FMTSpec;
46 class FMTPerBounds;
47 class FMTConstants;
48 template<typename T>
49 class FMTBounds;
50}
51
52namespace Spatial
53{
54 template<typename T>
55 class FMTLayer;
56}
57
58namespace Testing
59{
60 class UnitTestFMTParser;
61}
62
63
65namespace Parser
66{
67// DocString: FMTParser
73 {
74 public:
75 // DocString: FMTParser()
80 // DocString: FMTParser(const FMTParser&)
85 FMTParser(const FMTParser& rhs);
86 // DocString: FMTParser::operator=
92 FMTParser& operator = (const FMTParser& rhs);
93 // DocString: ~FMTParser()
97 virtual ~FMTParser()=default;
98 // DocString: FMTParser::getMostRecentFiletime
103 std::time_t getMostRecentFiletime() const;
104 // DocString: FMTParser::setHeader
109 void setHeader(const std::string& header);
110 #ifdef FMTWITHGDAL
111 // DocString: FMTParser::_getWSFields
118 GDALDataset* createOGRDataset(
119 std::string location = std::string(),
120 std::string gdaldrivername = "CSV") const;
121 // DocString: FMTParser::createLayer()
129 OGRLayer* createLayer(GDALDataset* dataset,
130 const std::string& name, std::vector<std::string> creationoptions = std::vector<std::string>()) const;
131 // DocString: FMTParser::getGDALVectorDriverNames
137 std::vector<std::string>getGDALVectorDriverNames(bool testcreation = true) const;
138 // DocString: FMTParser::getGDALRasterDriverNames
144 std::vector<std::string>getGDALRasterDriverNames(bool testcreation = true) const;
145 // DocString: FMTParser::getGDALVectorDriverExtensions
151 std::vector<std::vector<std::string>>getGDALVectorDriverExtensions(bool testcreation = true) const;
152 // DocString: FMTParser::getGDALRasterDriverExtensions
158 std::vector<std::vector<std::string>>getGDALRasterDriverExtensions(bool testcreation = true) const;
159 #endif
160 // DocString: FMTParser::tryOpening
167 bool tryOpening(const std::ifstream& stream, const std::string& location) const;
168 // DocString: FMTParser::tryOpening
175 bool tryOpening(std::ofstream& stream, const std::string& location) const;
176 // DocString: FMTParser::getCleanLine
182 std::string getCleanLine(std::istream& stream) const;
183 // DocString: FMTParser::getCleanLine
189 std::string getCleanLine(const std::string& p_input) const;
190 // DocString: FMTParser::fromExtension
196 static Core::FMTsection fromExtension(const std::string& p_Extension);
197 // DocString: FMTParser::createSubDirectory
204 std::string createSubDirectory(const std::string& p_Directory, const std::string& p_SubDirectory);
205 protected:
206 // DocString: FMTParser::FMTLineInfo
211 {
212 public:
213 // DocString: FMTParser::FMTLineInfo(const std::string, int, const std::string&)
220 FMTLineInfo(const std::string p_line,
221 int p_number, const std::string& p_file, const std::string& p_comment);
222 std::string m_lineValue;
224 std::string m_file;
225 std::string m_comment;
226 };
227 // DocString: FMTParser::m_SEPARATOR
229 const static boost::regex m_SEPARATOR;
230 // DocString: FMTParser::m_MTX
232 mutable boost::recursive_mutex m_MTX;
233 // DocString: FMTParser::FMTsection
236 // DocString: FMTParser::m_AYLD
238 const static boost::regex m_AYLD;
239 // DocString: FMTParser::m_AAGE
241 const static boost::regex m_AAGE;
242 // DocString: FMTParser::m_AYLD_AGE
244 const static boost::regex m_AYLD_AGE;
245 // DocString: FMTParser::m_BOUNDS
247 const static boost::regex m_BOUNDS;
248 // DocString: FMTParser::m_OPERATORS
250 const static boost::regex m_OPERATORS;
251 // DocString: FMTParser::m_PRIMARY
253 const static boost::regex m_PRIMARY;
254 // DocString: FMTParser::m_constrePlacement
257 // DocString: FMTParser::m_line
259 mutable int m_line;
260 // DocString: FMTParser::m_comment
262 mutable std::string m_comment;
263 // DocString: FMTParser::m_location
265 mutable std::string m_location;
266 // DocString: FMTParser::m_MostRecentFile
268 mutable std::time_t m_MostRecentFile;
269 // DocString: FMTParser::_setSection
274 void _setSection(const Core::FMTsection& section) const;
275 #ifdef FMTWITHGDAL
276 // DocString: FMTParser::getallGDALdrivernames
283 std::vector<GDALDriver*> _getAllGDALDrivers(const char* spatialtype, bool testcreation = true) const;
284 // DocString: FMTParser::getGDALExtensions
291 std::vector<std::vector<std::string>>getGDALExtensions(const char* spatialtype, bool testcreation = true) const;
292 // DocString: FMTParser::_setCategories
298 void _setCategories(GDALRasterBand* band, const std::vector<std::string>& categories) const;
299 // DocString: FMTAreaParser::_getProjTransform
306 OGRCoordinateTransformation* _getProjTransform(OGRLayer* baselayer, bool fittoforel = true) const;
307 // DocString: FMTAreaParser::_getTransFormMemLayerCopy
315 GDALDataset* _getTransFormMemLayerCopy(OGRLayer* baselayer, const OGRSpatialReference* newreference, const std::string& fieldname) const;
316 // DocString: FMTParser::_getFORELSpatialRef
321 std::unique_ptr<OGRSpatialReference> _getFORELSpatialRef() const;
322 // DocString: FMTParser::_createDataset
332 template<typename T>
333 GDALDataset* _createDataset(const std::string& location, const Spatial::FMTLayer<T>& layer, const int datatypeid, std::string format = "GTiff") const;
334 // DocString: FMTParser::_getDataset
340 GDALDataset* _getDataset(const std::string& location) const;
341 // DocString: FMTParser::_getVectorDataset
347 GDALDataset* _getVectorDataset(const std::string& location) const;
348 // DocString: FMTParser::_getLayer
355 OGRLayer* _getLayer(GDALDataset* dataset, int id) const;
356 // DocString: FMTParser::_getBand
363 GDALRasterBand* _getBand(GDALDataset* dataset, int bandid = 1) const;
364 // DocString: FMTParser::_createBand
372 GDALRasterBand* _createBand(GDALDataset* dataset, const std::vector<std::string>& categories, int bandid = 1) const;
373 // DocString: FMTParser::_getCat
380 std::vector<std::string> _getCat(GDALDataset* dataset, int bandid = 1) const;
381 // DocString: FMTParser::_getOverview
388 GDALRasterBand* _getOverview(GDALRasterBand* band, int view = 1) const;
389 // DocString: FMTParser::_getWSFields
401 void _getWSFields(OGRLayer* layer, std::map<int, int>& themes, int& age, int& area, int& lock, std::string agefield = "", std::string areafield = "", std::string lockfield = "") const;
402 // DocString: FMTParser::_createVectorMemoryDs
407 GDALDataset* _createVectorMemoryDs() const;
408 #endif
409
410 // DocString: FMTParser::_isValidFile
416 bool _isValidFile(const std::string& location) const;
417 // DocString: FMTParser::_isValid
423 bool _isValid(const std::string& line) const;
424 // DocString: FMTParser::regexLoop
431 std::vector<std::string>regexLoop(const boost::regex& cutregex, std::string& str) const;
432 // DocString: FMTParser::spliter
439 std::vector<std::string>spliter(std::string strmask, const boost::regex& xspliter) const;
440 // DocString: FMTParser::_clearComments
445 void _clearComments(std::string& line) const;
446 // DocString: FMTParser::_upper
452 std::string _upper(const std::string& lowercases) const;
453 // DocString: FMTParser::returnInclude
461 virtual std::queue<FMTLineInfo> _tryInclude(const std::vector<Core::FMTTheme>& p_themes, const Core::FMTConstants& p_cons,
462 std::queue<FMTLineInfo>p_ForOut) const;
463
464 // DocString: FMTParser::_getCleanLinewfor
472 virtual std::queue<FMTLineInfo> _getCleanLinewfor(std::ifstream& p_stream, const std::vector<Core::FMTTheme>& p_themes,
473 const Core::FMTConstants& p_cons) const;
474 // DocString: FMTParser::_getAllLines
480 std::queue<FMTLineInfo> _getAllLines(std::ifstream& p_stream) const;
481 // DocString: FMTParser::_processForLoopsNInclude
489 std::queue<FMTLineInfo> _processForLoopsNInclude(
490 const std::vector<Core::FMTTheme>& p_themes,
491 const Core::FMTConstants& p_cons,
492 std::queue<FMTLineInfo>p_AllLines) const;
493 // DocString: FMTParser::_isNum
499 bool _isNum(std::string value) const;
500 // DocString: FMTParser::_isNum
508 bool _isNum(const std::string& value, const Core::FMTConstants& constant, bool throwerror = true) const;
509 // DocString: FMTParser::_getNum
518 template<typename T>
519 T _getNum(const std::string& value, const Core::FMTConstants& constant, int period = 0) const;
520 // DocString: FMTParser::_getNum
528 template<typename T>
529 T _getNum(const std::string& value, bool omitnumtest = false) const;
530 // DocString: FMTParser::_tryFillNumber
540 template<typename T>
541 bool _tryFillNumber(T& number, const std::string& value, const Core::FMTConstants& constant, int period = 0) const;
542 // DocString: FMTParser::bounds
552 template<typename T>
553 Core::FMTBounds<T>bounds(const Core::FMTConstants& constants, const std::string& value, const std::string& ope, Core::FMTsection section) const;
554 // DocString: FMTParser::getBaseOperators
559 std::array<std::string, 5>getBaseOperators() const;
560 // DocString: FMTParser::_sameAs
566 std::vector<std::string> _sameAs(const std::string& allset) const;
567 // DocString: FMTParser::_getPrimary
573 std::map<Core::FMTsection, std::string> _getPrimary(const std::string& primarylocation);
574 // DocString: FMTParser::_isYld
583 bool _isYld(const Core::FMTYields& p_ylds, const std::string& p_value,
584 Core::FMTsection pm_section, bool p_throwError = true) const;
585 // DocString: FMTParser::_isAct
593 bool _isAct(Core::FMTsection section, const std::vector<Core::FMTAction>& actions, std::string action) const;
594 // DocString: FMTParser::_setSpecs
605 std::string _setSpecs(Core::FMTsection section, Core::FMTkwor key, const Core::FMTYields& ylds, const Core::FMTConstants& constants, std::vector<Core::FMTSpec>& specs, const std::string& line);
606 // DocString: FMTParser::_setSpec
617 std::string _setSpec(Core::FMTsection section, Core::FMTkwor key, const Core::FMTYields& ylds, const Core::FMTConstants& constants, Core::FMTSpec& spec, const std::string& line);
618 // DocString: FMTParser::readCsv
625 std::vector<std::vector<std::string>>readCsv(const std::string& location, const char& separator);
626 // DocString: FMTParser::_getPerBound
634 Core::FMTPerBounds _getPerBound(const std::string& p_lower,
635 const std::string& p_upper,
636 const Core::FMTConstants& p_constants) const;
637 // DocString: FMTParser::_setPeriodWithBounds
645 void _setPeriodWithBounds(Core::FMTSpec& p_spec,
646 const std::string& p_lower,
647 const std::string& p_upper,
648 const Core::FMTConstants& p_constants) const;
649 // DocString: FMTParser::_setPeriods
657 bool _setPeriods(Core::FMTSpec& p_spec,
658 const std::string& p_periods,
659 const Core::FMTConstants& p_constants) const;
660 // DocString: FMTParser::_getForLoops
668 std::map<std::string, std::vector<std::string>> _getForLoops(const std::string& p_line,
669 const std::vector<Core::FMTTheme>& p_themes,
670 const Core::FMTConstants& p_cons) const;
671 // DocString: FMTParser::_getForLoops
678 void _processForLoops(const std::vector<Core::FMTTheme>& p_themes,
679 const Core::FMTConstants& p_constants,
680 std::queue<FMTLineInfo>& p_queue) const;
681 // DocString: FMTParser::_isForLoops
687 bool _isForLoops(const std::string& p_line) const;
688 // DocString: FMTParser::_isForLoopsEnd
694 bool _isForLoopsEnd(const std::string& p_line) const;
695 // DocString: FMTParser:::getLine
702 std::string _getLine(std::queue<FMTLineInfo>& p_Lines,
703 bool p_ToCapital = true) const;
704 private:
705 friend class Testing::UnitTestFMTParser;
706 // DocString: FMTParser::m_VECTOR_THEME
708 const static boost::regex m_VECTOR_THEME;
709 // DocString: FMTParser::m_NUMBER
711 const static boost::regex m_NUMBER;
712 // DocString: FMTParser::m_REMOVE_COMMENT
714 const static boost::regex m_REMOVE_COMMENT;
715 // DocString: FMTParser::m_VALID
717 const static boost::regex m_VALID;
718 // DocString: FMTParser::m_INCLUDE
720 const static boost::regex m_INCLUDE;
721 // DocString: FMTParser::m_FOR
723 const static boost::regex m_FOR;
724 // DocString: FMTParser::m_END
726 const static boost::regex m_END;
727 // DocString: FMTParser::m_PERIODS
729 const static boost::regex m_PERIODS;
730 // DocString: FMTParser::primarym_sections
732 static std::map<Core::FMTsection, std::string>primarym_sections;
733 // DocString: FMTParser::m_inComment
735 mutable bool m_inComment;
736 // DocString: FMTParser::m_ForValues
738 //std::queue<std::string>m_ForValues;
739 // DocString: FMTParser::m_included
741 //std::queue<std::string>m_included;
742 // DocString: FMTParser::_safeGetline
749 std::istream& _safeGetline(std::istream& is, std::string& t) const;
750 #ifdef FMTWITHGDAL
751 // DocString: FMTParser::gdalInitFlag;
753 static std::once_flag gdalInitFlag;
754 static void _tryToInitializeGDAL();
755 static void _initializeGDAL();
756 // DocString: FMTParser::_queryDatabase
764 std::map<std::string, std::vector<std::string>>_queryDatabase(
765 const std::string& p_DataBaseLocation,
766 const std::string& p_VariableName,
767 const std::string& p_Query) const;
768 // DocString: FMTParser::_getGDALProjVersion
773 static std::string _getGDALProjVersion();
774 #endif
775 // DocString: FMTParser::_getAbsolutePath
781 std::string _getAbsolutePath(std::string p_Path) const;
782 // DocString: FMTParser::_setForLoopLines
788 FMTLineInfo _setForLoopLines(std::queue<FMTLineInfo>& p_queue) const;
789 // DocString: FMTParser:: _processConstants
796 std::string _processConstants(std::string p_input,
797 const Core::FMTConstants& p_constants) const;
798 };
799
800}
801
802#endif
#define FMTEXPORT
Definition: FMTutility.h:125
Definition: FMTParser.h:49
Class holding the constants defined in the constants section of a model, used by the parsers.
Definition: FMTConstants.h:28
Base class of multiple FMT classes holding a shared exception handler pointer and logger.
Definition: FMTObject.h:49
FMTList containing multiple yield handlers as seen in the yield section, holding the information rela...
Definition: FMTYields.h:44
Helper holding a line value, its number and its file, used during parsing.
Definition: FMTParser.h:211
int m_lineNumber
Definition: FMTParser.h:223
std::string m_file
Definition: FMTParser.h:224
std::string m_comment
Definition: FMTParser.h:225
FMTLineInfo(const std::string p_line, int p_number, const std::string &p_file, const std::string &p_comment)
Construct a line info from a line, its number and its file.
std::string m_lineValue
Definition: FMTParser.h:222
Main parent class of all the parsers in FMT.
Definition: FMTParser.h:73
GDALDataset * _getDataset(const std::string &location) const
Open a GDAL dataset in read only from a location, throwing on error.
GDALRasterBand * _createBand(GDALDataset *dataset, const std::vector< std::string > &categories, int bandid=1) const
Create a GDAL raster band in a dataset with categories.
std::vector< std::string > _sameAs(const std::string &allset) const
Handle the _sameAs keyword.
std::map< Core::FMTsection, std::string > _getPrimary(const std::string &primarylocation)
Return the file locations of the different sections from a primary file.
GDALDataset * _getVectorDataset(const std::string &location) const
Open a GDAL vector dataset in read only from a location, throwing on error.
std::time_t m_MostRecentFile
The most recent file time read by this parser.
Definition: FMTParser.h:268
std::vector< std::string > spliter(std::string strmask, const boost::regex &xspliter) const
Split a string into multiple strings.
static const boost::regex m_AAGE
A regex for capturing age specificaiton.
Definition: FMTParser.h:241
std::string _setSpecs(Core::FMTsection section, Core::FMTkwor key, const Core::FMTYields &ylds, const Core::FMTConstants &constants, std::vector< Core::FMTSpec > &specs, const std::string &line)
Set the specifications of one or multiple specs and return the rest of the line.
FMTParser()
Default constructor for FMTParser.
std::string getCleanLine(const std::string &p_input) const
Clean a line and make it ready to be read by a parser.
std::vector< std::string > getGDALRasterDriverNames(bool testcreation=true) const
Return a vector of GDAL raster driver names.
GDALDataset * _createVectorMemoryDs() const
Create a vector memory dataset.
std::unique_ptr< OGRSpatialReference > _getFORELSpatialRef() const
Return the spatial reference used for FORELs in Quebec.
std::map< std::string, std::vector< std::string > > _getForLoops(const std::string &p_line, const std::vector< Core::FMTTheme > &p_themes, const Core::FMTConstants &p_cons) const
Fill up the for loops queue with the targeted variables.
Core::FMTsection m_section
The section in which the child class is in.
Definition: FMTParser.h:235
OGRCoordinateTransformation * _getProjTransform(OGRLayer *baselayer, bool fittoforel=true) const
Return a coordinate transformation for a layer, optionally fitting to FOREL.
std::vector< GDALDriver * > _getAllGDALDrivers(const char *spatialtype, bool testcreation=true) const
Return the GDAL drivers for a given spatial type.
std::string _getLine(std::queue< FMTLineInfo > &p_Lines, bool p_ToCapital=true) const
Get and pop the front line of a queue.
std::vector< std::vector< std::string > > getGDALVectorDriverExtensions(bool testcreation=true) const
Return a vector of GDAL vector driver extensions organized by driver.
std::string getCleanLine(std::istream &stream) const
Clean a line and make it ready to be read by a parser.
std::string m_location
File location of the section read by the parser.
Definition: FMTParser.h:265
T _getNum(const std::string &value, const Core::FMTConstants &constant, int period=0) const
Return a numeric value from a string based on the constants and a period.
std::queue< FMTLineInfo > _getAllLines(std::ifstream &p_stream) const
Get all the lines of a file.
GDALRasterBand * _getBand(GDALDataset *dataset, int bandid=1) const
Open a GDAL raster band from a dataset.
bool _isNum(std::string value) const
Return true if the value is a number.
Core::FMTBounds< T > bounds(const Core::FMTConstants &constants, const std::string &value, const std::string &ope, Core::FMTsection section) const
Return a FMTBounds from a value based on the constants and a section.
bool _isValidFile(const std::string &location) const
Check if a file location is valid.
std::vector< std::string > _getCat(GDALDataset *dataset, int bandid=1) const
Return the categories of a dataset for a given band.
std::time_t getMostRecentFiletime() const
Return the most recent file time of the files read by the parser.
GDALDataset * _getTransFormMemLayerCopy(OGRLayer *baselayer, const OGRSpatialReference *newreference, const std::string &fieldname) const
Create a memory dataset copying a layer with a new field, optionally with a new spatial reference.
bool _setPeriods(Core::FMTSpec &p_spec, const std::string &p_periods, const Core::FMTConstants &p_constants) const
Set the periods of a spec from a parsed period string.
static const boost::regex m_AYLD
A regex for capturing age/period/yield specification.
Definition: FMTParser.h:238
bool _isValid(const std::string &line) const
Check if a line is valid and clean it.
FMTParser(const FMTParser &rhs)
Copy constructor for FMTParser.
void _processForLoops(const std::vector< Core::FMTTheme > &p_themes, const Core::FMTConstants &p_constants, std::queue< FMTLineInfo > &p_queue) const
Unroll the for loops in the queue and set the results in the queue.
virtual std::queue< FMTLineInfo > _tryInclude(const std::vector< Core::FMTTheme > &p_themes, const Core::FMTConstants &p_cons, std::queue< FMTLineInfo >p_ForOut) const
Return the next lines to be read by the parser, considering included files.
void _setSection(const Core::FMTsection &section) const
Set the section member of the parser.
bool _isYld(const Core::FMTYields &p_ylds, const std::string &p_value, Core::FMTsection pm_section, bool p_throwError=true) const
Check if a value is a valid yield.
bool tryOpening(std::ofstream &stream, const std::string &location) const
Open an output stream at a given location.
std::string _setSpec(Core::FMTsection section, Core::FMTkwor key, const Core::FMTYields &ylds, const Core::FMTConstants &constants, Core::FMTSpec &spec, const std::string &line)
Set the specification of a spec and return the rest of the line.
std::string createSubDirectory(const std::string &p_Directory, const std::string &p_SubDirectory)
Create a sub directory in directory.
bool tryOpening(const std::ifstream &stream, const std::string &location) const
Open an input stream at a given location.
static const boost::regex m_OPERATORS
A regex for capturing simple operators.
Definition: FMTParser.h:250
std::vector< std::vector< std::string > > readCsv(const std::string &location, const char &separator)
Read a CSV file from a location using a separator.
bool _isAct(Core::FMTsection section, const std::vector< Core::FMTAction > &actions, std::string action) const
Check if a value is an action.
void _setPeriodWithBounds(Core::FMTSpec &p_spec, const std::string &p_lower, const std::string &p_upper, const Core::FMTConstants &p_constants) const
Set the periods of a spec from a lower and upper bound.
std::array< std::string, 5 > getBaseOperators() const
Return the operators normally found in the different sections.
static const boost::regex m_PRIMARY
A regex for capturing the primary file.
Definition: FMTParser.h:253
std::string _upper(const std::string &lowercases) const
Convert a string to upper case.
void _getWSFields(OGRLayer *layer, std::map< int, int > &themes, int &age, int &area, int &lock, std::string agefield="", std::string areafield="", std::string lockfield="") const
Fill up the field ids of the themes, age, area and lock of a layer.
T _getNum(const std::string &value, bool omitnumtest=false) const
Return a numeric value from a string.
void _clearComments(std::string &line) const
Clear the comments from a line and fill up the comment member.
OGRLayer * createLayer(GDALDataset *dataset, const std::string &name, std::vector< std::string > creationoptions=std::vector< std::string >()) const
Create a layer in a dataset, deleting any existing layer with the same name.
std::vector< std::string > getGDALVectorDriverNames(bool testcreation=true) const
Return a vector of GDAL vector driver names.
boost::recursive_mutex m_MTX
Mutex for multi-threading.
Definition: FMTParser.h:232
bool _isForLoops(const std::string &p_line) const
Return true if a line is a for loop header.
std::vector< std::vector< std::string > > getGDALExtensions(const char *spatialtype, bool testcreation=true) const
Return the GDAL extensions organized by driver for a given spatial type.
void setHeader(const std::string &header)
Set a string as the header written when the file is opened in write mode, replacing the comment attri...
GDALRasterBand * _getOverview(GDALRasterBand *band, int view=1) const
Return an overview of a raster band.
std::vector< std::vector< std::string > > getGDALRasterDriverExtensions(bool testcreation=true) const
Return a vector of GDAL raster driver extensions organized by driver.
OGRLayer * _getLayer(GDALDataset *dataset, int id) const
Open a GDAL layer from a vector dataset by its id, throwing on error.
std::queue< FMTLineInfo > _processForLoopsNInclude(const std::vector< Core::FMTTheme > &p_themes, const Core::FMTConstants &p_cons, std::queue< FMTLineInfo >p_AllLines) const
Process the for loops and include lines.
static Core::FMTsection fromExtension(const std::string &p_Extension)
Return the FMTsection matching the extension of a file.
static const boost::regex m_AYLD_AGE
A regex for capturing age or yield specification.
Definition: FMTParser.h:244
std::vector< std::string > regexLoop(const boost::regex &cutregex, std::string &str) const
Capture a for loop from a line and return the variables to loop on.
bool _isNum(const std::string &value, const Core::FMTConstants &constant, bool throwerror=true) const
Return true if the value is a number, raising if it is not a valid number when throwerror is true.
GDALDataset * _createDataset(const std::string &location, const Spatial::FMTLayer< T > &layer, const int datatypeid, std::string format="GTiff") const
Create an empty GDAL dataset for a layer.
virtual std::queue< FMTLineInfo > _getCleanLinewfor(std::ifstream &p_stream, const std::vector< Core::FMTTheme > &p_themes, const Core::FMTConstants &p_cons) const
Get a clean line considering for loops when reading the file.
int m_constrePlacement
Number of constant replaced by a numerical number.
Definition: FMTParser.h:256
Core::FMTPerBounds _getPerBound(const std::string &p_lower, const std::string &p_upper, const Core::FMTConstants &p_constants) const
Return the period bound of an input.
void _setCategories(GDALRasterBand *band, const std::vector< std::string > &categories) const
Write the categories in the band information.
int m_line
Line id at which the parser is reading the values.
Definition: FMTParser.h:259
GDALDataset * createOGRDataset(std::string location=std::string(), std::string gdaldrivername="CSV") const
Create an OGR vector dataset based on a driver name and a location.
static const boost::regex m_BOUNDS
A regex for capturing bounds for yield or age specification.
Definition: FMTParser.h:247
bool _tryFillNumber(T &number, const std::string &value, const Core::FMTConstants &constant, int period=0) const
Try to get a number from a string, returning false on failure.
static const boost::regex m_SEPARATOR
A regex for splitting general string.
Definition: FMTParser.h:229
bool _isForLoopsEnd(const std::string &p_line) const
Return true if a line is the end of a for loop.
std::string m_comment
Comment found in the actual line read by the parser.
Definition: FMTParser.h:262
virtual ~FMTParser()=default
Default destructor for FMTParser.
Definition: FMTParser.h:55
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
FMTsection
Enumerator describing the sections of a Woodstock model.
Definition: FMTutility.h:32
FMTkwor
Enumerator describing the source or target keyword of a transition.
Definition: FMTutility.h:52
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27
Definition: FMTAreaParser.h:40
Definition: FMTParser.h:59