FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Parser::FMTConstantParser Class Reference

Parser reading and writing constants, used by the model parser. More...

#include <FMTConstantParser.h>

Inheritance diagram for Parser::FMTConstantParser:
[legend]
Collaboration diagram for Parser::FMTConstantParser:
[legend]

Public Member Functions

 FMTConstantParser ()
 Default constructor for FMTConstantParser.
 
 ~FMTConstantParser ()=default
 Default destructor for FMTConstantParser.
 
 FMTConstantParser (const FMTConstantParser &rhs)=default
 Copy constructor for FMTConstantParser.
 
FMTConstantParseroperator= (const FMTConstantParser &rhs)=default
 Copy assignment operator for FMTConstantParser.
 
Core::FMTConstants read (const std::string &location)
 Read a constants file.
 
void write (const Core::FMTConstants &constants, const std::string &location) const
 Write constants to a file.
 
- Public Member Functions inherited from Parser::FMTParser
 FMTParser ()
 Default constructor for FMTParser.
 
 FMTParser (const FMTParser &rhs)
 Copy constructor for FMTParser.
 
FMTParseroperator= (const FMTParser &rhs)
 Copy assignment operator for FMTParser.
 
virtual ~FMTParser ()=default
 Default destructor for FMTParser.
 
std::time_t getMostRecentFiletime () const
 Return the most recent file time of the files read by the parser.
 
void setHeader (const std::string &header)
 Set a string as the header written when the file is opened in write mode, replacing the comment attribute.
 
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.
 
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.
 
std::vector< std::string > getGDALRasterDriverNames (bool testcreation=true) const
 Return a vector of GDAL raster driver names.
 
std::vector< std::vector< std::string > > getGDALVectorDriverExtensions (bool testcreation=true) const
 Return a vector of GDAL vector driver extensions organized by driver.
 
std::vector< std::vector< std::string > > getGDALRasterDriverExtensions (bool testcreation=true) const
 Return a vector of GDAL raster driver extensions organized by driver.
 
bool tryOpening (const std::ifstream &stream, const std::string &location) const
 Open an input stream at a given location.
 
bool tryOpening (std::ofstream &stream, const std::string &location) const
 Open an output stream at a given location.
 
std::string getCleanLine (std::istream &stream) const
 Clean a line and make it ready to be read by a parser.
 
std::string getCleanLine (const std::string &p_input) const
 Clean a line and make it ready to be read by a parser.
 
std::string createSubDirectory (const std::string &p_Directory, const std::string &p_SubDirectory)
 Create a sub directory in directory.
 
- Public Member Functions inherited from Core::FMTObject
 FMTObject ()
 Default constructor for FMTObject.
 
virtual ~FMTObject ()
 Default virtual destructor for FMTObject.
 
 FMTObject (const std::unique_ptr< Exception::FMTExceptionHandler > exhandler)
 Construct a FMTObject passing in the exception handler of another FMTObject.
 
 FMTObject (const FMTObject &rhs)
 Copy constructor for FMTObject.
 
FMTObjectoperator= (const FMTObject &rhs)
 Copy assignment operator for FMTObject.
 
virtual void passInLogger (const std::unique_ptr< Logging::FMTLogger > &logger)
 Pass in the logger of another FMTObject.
 
void passInExceptionHandler (const std::unique_ptr< Exception::FMTExceptionHandler > &exhandler)
 Pass in the exception handler of another FMTObject.
 
void redirectLogToFile (const std::string &location)
 Redirect the log to a specific file, appending to it.
 
virtual void setDefaultLogger ()
 Create and set a default logger to the FMTObject.
 
virtual void setQuietLogger ()
 Create and set a quiet logger to the FMTObject.
 
virtual void setTaskLogger ()
 Create and set a task logger to the FMTObject.
 
virtual void setDebugLogger ()
 Create and set a debug logger to the FMTObject.
 
void setDefaultExceptionHandler ()
 Create and set a default exception handler to the FMTObject.
 
void setQuietExceptionHandler ()
 Create and set a quiet exception handler to the FMTObject.
 
void setDebugExceptionHandler ()
 Create and set a debug exception handler to the FMTObject.
 
void setFreeExceptionHandler ()
 Create and set a free exception handler to the FMTObject.
 
void disableNestedExceptions ()
 Disable the nested exception throw of the exception handler.
 
void enableNestedExceptions ()
 Enable the nested exception throw of the exception handler.
 
void setErrorsToWarnings (const std::vector< Exception::FMTexc > &errors)
 Set a list of errors to be cast to warnings on the exception handler.
 
void setMaxWarningsBeforeSilenced (const size_t &maxwarningcount)
 Set the number of warnings raised before being silenced.
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Additional Inherited Members

- Static Public Member Functions inherited from Parser::FMTParser
static Core::FMTsection fromExtension (const std::string &p_Extension)
 Return the FMTsection matching the extension of a file.
 
- Static Public Member Functions inherited from Core::FMTObject
static Logging::FMTLoggergetLogger ()
 get a pointer to the actual logger.
 
static Exception::FMTExceptionHandlergetExceptionHandler ()
 get a pointer to the actual exception handler.
 
static std::string getRuntimeLocation ()
 Return the location of the FMT shared library.
 
static unsigned long long getAvailableMemory ()
 Return the available memory in bytes.
 
static void setTerminateStack ()
 will write the stack in the log when terminate called and raise a function failed.
 
static void setAbortStack ()
 will write the stack in the log when abort called with SIGABRT and raise a function failed.
 
- Protected Member Functions inherited from Parser::FMTParser
void _setSection (const Core::FMTsection &section) const
 Set the section member of the parser.
 
std::vector< GDALDriver * > _getAllGDALDrivers (const char *spatialtype, bool testcreation=true) const
 Return the GDAL drivers for a given spatial type.
 
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 _setCategories (GDALRasterBand *band, const std::vector< std::string > &categories) const
 Write the categories in the band information.
 
OGRCoordinateTransformation * _getProjTransform (OGRLayer *baselayer, bool fittoforel=true) const
 Return a coordinate transformation for a layer, optionally fitting to FOREL.
 
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.
 
std::unique_ptr< OGRSpatialReference > _getFORELSpatialRef () const
 Return the spatial reference used for FORELs in Quebec.
 
template<typename T >
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.
 
GDALDataset * _getDataset (const std::string &location) const
 Open a GDAL dataset in read only from a location, throwing on error.
 
GDALDataset * _getVectorDataset (const std::string &location) const
 Open a GDAL vector dataset in read only from a location, throwing on error.
 
OGRLayer * _getLayer (GDALDataset *dataset, int id) const
 Open a GDAL layer from a vector dataset by its id, throwing on error.
 
GDALRasterBand * _getBand (GDALDataset *dataset, int bandid=1) const
 Open a GDAL raster band from a dataset.
 
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 > _getCat (GDALDataset *dataset, int bandid=1) const
 Return the categories of a dataset for a given band.
 
GDALRasterBand * _getOverview (GDALRasterBand *band, int view=1) const
 Return an overview of a raster band.
 
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.
 
GDALDataset * _createVectorMemoryDs () const
 Create a vector memory dataset.
 
bool _isValidFile (const std::string &location) const
 Check if a file location is valid.
 
bool _isValid (const std::string &line) const
 Check if a line is valid and clean it.
 
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.
 
std::vector< std::string > spliter (std::string strmask, const boost::regex &xspliter) const
 Split a string into multiple strings.
 
void _clearComments (std::string &line) const
 Clear the comments from a line and fill up the comment member.
 
std::string _upper (const std::string &lowercases) const
 Convert a string to upper case.
 
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.
 
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.
 
std::queue< FMTLineInfo_getAllLines (std::ifstream &p_stream) const
 Get all the lines of a file.
 
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.
 
bool _isNum (std::string value) const
 Return true if the value is a number.
 
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.
 
template<typename 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.
 
template<typename T >
_getNum (const std::string &value, bool omitnumtest=false) const
 Return a numeric value from a string.
 
template<typename T >
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.
 
template<typename T >
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.
 
std::array< std::string, 5 > getBaseOperators () const
 Return the operators normally found in the different sections.
 
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.
 
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 _isAct (Core::FMTsection section, const std::vector< Core::FMTAction > &actions, std::string action) const
 Check if a value is an action.
 
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.
 
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::vector< std::vector< std::string > > readCsv (const std::string &location, const char &separator)
 Read a CSV file from a location using a separator.
 
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 _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.
 
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.
 
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.
 
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.
 
bool _isForLoops (const std::string &p_line) const
 Return true if a line is a for loop header.
 
bool _isForLoopsEnd (const std::string &p_line) const
 Return true if a line is the end of a for loop.
 
std::string _getLine (std::queue< FMTLineInfo > &p_Lines) const
 Get and pop the front line of a queue.
 
- Protected Member Functions inherited from Core::FMTObject
template<class Archive >
void forceSave (Archive &ar, const unsigned int version) const
 Force the serialization to save useful information, which the default FMTObject serialization does not.
 
template<class Archive >
void forceLoad (Archive &ar, const unsigned int version)
 Force the serialization to load useful information, which the default FMTObject serialization does not.
 
void checkSignals () const
 Check if the user has sent a ctrl-c signal using boost::python to FMT.
 
void setCplHandler ()
 Pass the FMT exception handler to the GDAL exception handler (GDAL only).
 
- Static Protected Member Functions inherited from Core::FMTObject
static std::chrono::time_point< std::chrono::high_resolution_clock > getClock ()
 Return a clock of the current time.
 
template<class chrono >
static double getDuration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock as a double.
 
static std::string getDurationInSeconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock in seconds as a string.
 
static void _logStack ()
 Log the stack trace...
 
static void _terminate ()
 Raise an error with the boost stacktrace.
 
static void _abort (int p_signal)
 Raise an error with the boost stacktrace on abort.
 
- Protected Attributes inherited from Parser::FMTParser
boost::recursive_mutex m_MTX
 Mutex for multi-threading.
 
Core::FMTsection m_section
 The section in which the child class is in.
 
int m_constrePlacement
 Number of constant replaced by a numerical number.
 
int m_line
 Line id at which the parser is reading the values.
 
std::string m_comment
 Comment found in the actual line read by the parser.
 
std::string m_location
 File location of the section read by the parser.
 
std::time_t m_MostRecentFile
 The most recent file time read by this parser.
 
- Static Protected Attributes inherited from Parser::FMTParser
static const boost::regex m_SEPARATOR
 A regex for splitting general string.
 
static const boost::regex m_AYLD
 A regex for capturing age/period/yield specification.
 
static const boost::regex m_AAGE
 A regex for capturing age specificaiton.
 
static const boost::regex m_AYLD_AGE
 A regex for capturing age or yield specification.
 
static const boost::regex m_BOUNDS
 A regex for capturing bounds for yield or age specification.
 
static const boost::regex m_OPERATORS
 A regex for capturing simple operators.
 
static const boost::regex m_PRIMARY
 A regex for capturing the primary file.
 
- Static Protected Attributes inherited from Core::FMTObject
static std::unique_ptr< Exception::FMTExceptionHandler_exhandler
 A shared pointer to the exception handler.
 
static std::unique_ptr< Logging::FMTLogger_logger
 A shared pointer to the logger.
 

Detailed Description

Parser reading and writing constants, used by the model parser.

Constructor & Destructor Documentation

◆ FMTConstantParser() [1/2]

Parser::FMTConstantParser::FMTConstantParser ( )

Default constructor for FMTConstantParser.

◆ ~FMTConstantParser()

Parser::FMTConstantParser::~FMTConstantParser ( )
default

Default destructor for FMTConstantParser.

◆ FMTConstantParser() [2/2]

Parser::FMTConstantParser::FMTConstantParser ( const FMTConstantParser rhs)
default

Copy constructor for FMTConstantParser.

Parameters
[in]rhsthe FMTConstantParser to copy.

Member Function Documentation

◆ operator=()

FMTConstantParser & Parser::FMTConstantParser::operator= ( const FMTConstantParser rhs)
default

Copy assignment operator for FMTConstantParser.

Parameters
[in]rhsthe FMTConstantParser to copy.
Returns
a reference to this FMTConstantParser.

◆ read()

Core::FMTConstants Parser::FMTConstantParser::read ( const std::string &  location)

Read a constants file.

Parameters
[in]locationthe file location.
Returns
the constants.

◆ write()

void Parser::FMTConstantParser::write ( const Core::FMTConstants constants,
const std::string &  location 
) const

Write constants to a file.

Parameters
[in]constantsthe constants.
[in]locationthe file location.

The documentation for this class was generated from the following file: