FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
Parser::FMTParser Class Reference

Main parent class of all the parsers in FMT. More...

#include <FMTParser.h>

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

Classes

class  FMTLineInfo
 Helper holding a line value, its number and its file, used during parsing. More...
 

Public Member Functions

 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)
 

Static Public Member Functions

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

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).
 

Protected Attributes

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

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.
 

Friends

class Testing::UnitTestFMTParser
 

Additional Inherited Members

- 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.
 

Detailed Description

Main parent class of all the parsers in FMT.

Provides many functions common to all parsers for validation and error handling when turning a string into something usable in FMT.

Constructor & Destructor Documentation

◆ FMTParser() [1/2]

Parser::FMTParser::FMTParser ( )

Default constructor for FMTParser.

◆ FMTParser() [2/2]

Parser::FMTParser::FMTParser ( const FMTParser rhs)

Copy constructor for FMTParser.

Parameters
[in]rhsthe FMTParser to copy.

◆ ~FMTParser()

virtual Parser::FMTParser::~FMTParser ( )
virtualdefault

Default destructor for FMTParser.

Member Function Documentation

◆ _clearComments()

void Parser::FMTParser::_clearComments ( std::string &  line) const
protected

Clear the comments from a line and fill up the comment member.

Parameters
[in,out]linethe line.

◆ _createBand()

GDALRasterBand * Parser::FMTParser::_createBand ( GDALDataset *  dataset,
const std::vector< std::string > &  categories,
int  bandid = 1 
) const
protected

Create a GDAL raster band in a dataset with categories.

Parameters
[in]datasetthe dataset.
[in]categoriesthe categories.
[in]bandidthe band id.
Returns
the raster band.

◆ _createDataset()

template<typename T >
GDALDataset * Parser::FMTParser::_createDataset ( const std::string &  location,
const Spatial::FMTLayer< T > &  layer,
const int  datatypeid,
std::string  format = "GTiff" 
) const
protected

Create an empty GDAL dataset for a layer.

Template Parameters
Tthe layer value type.
Parameters
[in]locationthe location.
[in]layerthe layer.
[in]datatypeidthe data type id.
[in]formatthe format.
Returns
the created dataset.

◆ _createVectorMemoryDs()

GDALDataset * Parser::FMTParser::_createVectorMemoryDs ( ) const
protected

Create a vector memory dataset.

Returns
the memory dataset.

◆ _getAllGDALDrivers()

std::vector< GDALDriver * > Parser::FMTParser::_getAllGDALDrivers ( const char *  spatialtype,
bool  testcreation = true 
) const
protected

Return the GDAL drivers for a given spatial type.

Parameters
[in]spatialtypethe spatial type (raster or vector).
[in]testcreationif true only returns drivers that support creation.
Returns
the GDAL drivers.

◆ _getAllLines()

std::queue< FMTLineInfo > Parser::FMTParser::_getAllLines ( std::ifstream &  p_stream) const
protected

Get all the lines of a file.

Parameters
[in,out]p_streamthe file stream.
Returns
a queue of lines to process.

◆ _getBand()

GDALRasterBand * Parser::FMTParser::_getBand ( GDALDataset *  dataset,
int  bandid = 1 
) const
protected

Open a GDAL raster band from a dataset.

Parameters
[in]datasetthe dataset.
[in]bandidthe band id.
Returns
the raster band.

◆ _getCat()

std::vector< std::string > Parser::FMTParser::_getCat ( GDALDataset *  dataset,
int  bandid = 1 
) const
protected

Return the categories of a dataset for a given band.

Parameters
[in]datasetthe dataset.
[in]bandidthe band id.
Returns
the categories.

◆ _getCleanLinewfor()

virtual std::queue< FMTLineInfo > Parser::FMTParser::_getCleanLinewfor ( std::ifstream &  p_stream,
const std::vector< Core::FMTTheme > &  p_themes,
const Core::FMTConstants p_cons 
) const
protectedvirtual

Get a clean line considering for loops when reading the file.

Parameters
[in,out]p_streamthe file stream.
[in]p_themesthe model themes.
[in]p_consthe model constants.
Returns
a queue of lines to process.

◆ _getDataset()

GDALDataset * Parser::FMTParser::_getDataset ( const std::string &  location) const
protected

Open a GDAL dataset in read only from a location, throwing on error.

Parameters
[in]locationthe location.
Returns
the dataset.

◆ _getFORELSpatialRef()

std::unique_ptr< OGRSpatialReference > Parser::FMTParser::_getFORELSpatialRef ( ) const
protected

Return the spatial reference used for FORELs in Quebec.

Returns
the FOREL spatial reference.

◆ _getForLoops()

std::map< std::string, std::vector< std::string > > Parser::FMTParser::_getForLoops ( const std::string &  p_line,
const std::vector< Core::FMTTheme > &  p_themes,
const Core::FMTConstants p_cons 
) const
protected

Fill up the for loops queue with the targeted variables.

Parameters
[in]p_linethe for loop header line.
[in]p_themesthe model themes.
[in]p_consthe model constants.
Returns
the for loop values with the target as key.

◆ _getLayer()

OGRLayer * Parser::FMTParser::_getLayer ( GDALDataset *  dataset,
int  id 
) const
protected

Open a GDAL layer from a vector dataset by its id, throwing on error.

Parameters
[in]datasetthe dataset.
[in]idthe layer id.
Returns
the layer.

◆ _getLine()

std::string Parser::FMTParser::_getLine ( std::queue< FMTLineInfo > &  p_Lines) const
protected

Get and pop the front line of a queue.

Parameters
[in,out]p_Linesthe queue of lines.
Returns
the front line value.

◆ _getNum() [1/2]

template<typename T >
T Parser::FMTParser::_getNum ( const std::string &  value,
bool  omitnumtest = false 
) const
protected

Return a numeric value from a string.

Template Parameters
Tthe numeric type.
Parameters
[in]valuethe value.
[in]omitnumtestif true omits the number test.
Returns
the numeric value.

◆ _getNum() [2/2]

template<typename T >
T Parser::FMTParser::_getNum ( const std::string &  value,
const Core::FMTConstants constant,
int  period = 0 
) const
protected

Return a numeric value from a string based on the constants and a period.

Template Parameters
Tthe numeric type.
Parameters
[in]valuethe value.
[in]constantthe constants.
[in]periodthe period.
Returns
the numeric value.

◆ _getOverview()

GDALRasterBand * Parser::FMTParser::_getOverview ( GDALRasterBand *  band,
int  view = 1 
) const
protected

Return an overview of a raster band.

Parameters
[in]bandthe raster band.
[in]viewthe overview index.
Returns
the overview raster band.

◆ _getPerBound()

Core::FMTPerBounds Parser::FMTParser::_getPerBound ( const std::string &  p_lower,
const std::string &  p_upper,
const Core::FMTConstants p_constants 
) const
protected

Return the period bound of an input.

Parameters
[in]p_lowerthe lower bound.
[in]p_upperthe upper bound.
[in]p_constantsthe constants.
Returns
the period bound.

◆ _getPrimary()

std::map< Core::FMTsection, std::string > Parser::FMTParser::_getPrimary ( const std::string &  primarylocation)
protected

Return the file locations of the different sections from a primary file.

Parameters
[in]primarylocationthe primary file location.
Returns
a map of section to file location.

◆ _getProjTransform()

OGRCoordinateTransformation * Parser::FMTParser::_getProjTransform ( OGRLayer *  baselayer,
bool  fittoforel = true 
) const
protected

Return a coordinate transformation for a layer, optionally fitting to FOREL.

Parameters
[in]baselayerthe base layer.
[in]fittoforelif true fits to FOREL.
Returns
the coordinate transformation.

◆ _getTransFormMemLayerCopy()

GDALDataset * Parser::FMTParser::_getTransFormMemLayerCopy ( OGRLayer *  baselayer,
const OGRSpatialReference *  newreference,
const std::string &  fieldname 
) const
protected

Create a memory dataset copying a layer with a new field, optionally with a new spatial reference.

Parameters
[in]baselayerthe base layer.
[in]newreferencethe new spatial reference.
[in]fieldnamethe new field name.
Returns
the memory dataset.

◆ _getVectorDataset()

GDALDataset * Parser::FMTParser::_getVectorDataset ( const std::string &  location) const
protected

Open a GDAL vector dataset in read only from a location, throwing on error.

Parameters
[in]locationthe location.
Returns
the dataset.

◆ _getWSFields()

void Parser::FMTParser::_getWSFields ( OGRLayer *  layer,
std::map< int, int > &  themes,
int &  age,
int &  area,
int &  lock,
std::string  agefield = "",
std::string  areafield = "",
std::string  lockfield = "" 
) const
protected

Fill up the field ids of the themes, age, area and lock of a layer.

Parameters
[in]layerthe layer.
[in,out]themesthe theme field ids.
[in,out]agethe age field id.
[in,out]areathe area field id.
[in,out]lockthe lock field id.
[in]agefieldthe age field name.
[in]areafieldthe area field name.
[in]lockfieldthe lock field name.

◆ _isAct()

bool Parser::FMTParser::_isAct ( Core::FMTsection  section,
const std::vector< Core::FMTAction > &  actions,
std::string  action 
) const
protected

Check if a value is an action.

Parameters
[in]sectionthe section.
[in]actionsthe actions.
[in]actionthe value.
Returns
true if the value is an action else false.

◆ _isForLoops()

bool Parser::FMTParser::_isForLoops ( const std::string &  p_line) const
protected

Return true if a line is a for loop header.

Parameters
[in]p_linethe line.
Returns
true if the line is a for loop else false.

◆ _isForLoopsEnd()

bool Parser::FMTParser::_isForLoopsEnd ( const std::string &  p_line) const
protected

Return true if a line is the end of a for loop.

Parameters
[in]p_linethe line.
Returns
true if the line is the end of a for loop else false.

◆ _isNum() [1/2]

bool Parser::FMTParser::_isNum ( const std::string &  value,
const Core::FMTConstants constant,
bool  throwerror = true 
) const
protected

Return true if the value is a number, raising if it is not a valid number when throwerror is true.

Parameters
[in]valuethe value.
[in]constantthe constants.
[in]throwerrorif true raises on a non valid number.
Returns
true if the value is a number else false.

◆ _isNum() [2/2]

bool Parser::FMTParser::_isNum ( std::string  value) const
protected

Return true if the value is a number.

Parameters
[in]valuethe value.
Returns
true if the value is a number else false.

◆ _isValid()

bool Parser::FMTParser::_isValid ( const std::string &  line) const
protected

Check if a line is valid and clean it.

Parameters
[in]linethe line.
Returns
true if the line is valid else false.

◆ _isValidFile()

bool Parser::FMTParser::_isValidFile ( const std::string &  location) const
protected

Check if a file location is valid.

Parameters
[in]locationthe location.
Returns
true if the file is valid else false.

◆ _isYld()

bool Parser::FMTParser::_isYld ( const Core::FMTYields p_ylds,
const std::string &  p_value,
Core::FMTsection  pm_section,
bool  p_throwError = true 
) const
protected

Check if a value is a valid yield.

Parameters
[in]p_yldsthe yield section.
[in]p_valuethe value.
[in]pm_sectionthe section.
[in]p_throwErrorif true raises if the value is not a yield.
Returns
true if the value is a yield else false.

◆ _processForLoops()

void Parser::FMTParser::_processForLoops ( const std::vector< Core::FMTTheme > &  p_themes,
const Core::FMTConstants p_constants,
std::queue< FMTLineInfo > &  p_queue 
) const
protected

Unroll the for loops in the queue and set the results in the queue.

Parameters
[in]p_themesthe model themes.
[in]p_constantsthe model constants.
[in,out]p_queuethe resulting queue of lines.

◆ _processForLoopsNInclude()

std::queue< FMTLineInfo > Parser::FMTParser::_processForLoopsNInclude ( const std::vector< Core::FMTTheme > &  p_themes,
const Core::FMTConstants p_cons,
std::queue< FMTLineInfo p_AllLines 
) const
protected

Process the for loops and include lines.

Parameters
[in]p_themesthe model themes.
[in]p_consthe model constants.
[in]p_AllLinesall the lines read from the file.
Returns
a queue of lines to process.

◆ _sameAs()

std::vector< std::string > Parser::FMTParser::_sameAs ( const std::string &  allset) const
protected

Handle the _sameAs keyword.

Parameters
[in]allsetthe set string.
Returns
the resulting strings.

◆ _setCategories()

void Parser::FMTParser::_setCategories ( GDALRasterBand *  band,
const std::vector< std::string > &  categories 
) const
protected

Write the categories in the band information.

Parameters
[in,out]bandthe raster band.
[in]categoriesthe categories.

◆ _setPeriods()

bool Parser::FMTParser::_setPeriods ( Core::FMTSpec &  p_spec,
const std::string &  p_periods,
const Core::FMTConstants p_constants 
) const
protected

Set the periods of a spec from a parsed period string.

Parameters
[in,out]p_specthe spec.
[in]p_periodsthe period string.
[in]p_constantsthe constants.
Returns
true if the periods are set else false.

◆ _setPeriodWithBounds()

void Parser::FMTParser::_setPeriodWithBounds ( Core::FMTSpec &  p_spec,
const std::string &  p_lower,
const std::string &  p_upper,
const Core::FMTConstants p_constants 
) const
protected

Set the periods of a spec from a lower and upper bound.

Parameters
[in,out]p_specthe spec.
[in]p_lowerthe lower bound.
[in]p_upperthe upper bound.
[in]p_constantsthe constants.

◆ _setSection()

void Parser::FMTParser::_setSection ( const Core::FMTsection section) const
protected

Set the section member of the parser.

Parameters
[in]sectionthe section to set.

◆ _setSpec()

std::string Parser::FMTParser::_setSpec ( Core::FMTsection  section,
Core::FMTkwor  key,
const Core::FMTYields ylds,
const Core::FMTConstants constants,
Core::FMTSpec &  spec,
const std::string &  line 
)
protected

Set the specification of a spec and return the rest of the line.

Parameters
[in]sectionthe section.
[in]keythe keyword.
[in]yldsthe yields.
[in]constantsthe constants.
[in,out]specthe specification.
[in]linethe line.
Returns
the rest of the line.

◆ _setSpecs()

std::string Parser::FMTParser::_setSpecs ( Core::FMTsection  section,
Core::FMTkwor  key,
const Core::FMTYields ylds,
const Core::FMTConstants constants,
std::vector< Core::FMTSpec > &  specs,
const std::string &  line 
)
protected

Set the specifications of one or multiple specs and return the rest of the line.

Parameters
[in]sectionthe section.
[in]keythe keyword.
[in]yldsthe yields.
[in]constantsthe constants.
[in,out]specsthe specifications.
[in]linethe line.
Returns
the rest of the line.

◆ _tryFillNumber()

template<typename T >
bool Parser::FMTParser::_tryFillNumber ( T &  number,
const std::string &  value,
const Core::FMTConstants constant,
int  period = 0 
) const
protected

Try to get a number from a string, returning false on failure.

Template Parameters
Tthe numeric type.
Parameters
[out]numberthe number.
[in]valuethe value.
[in]constantthe constants.
[in]periodthe period.
Returns
true if the number is filled else false.

◆ _tryInclude()

virtual std::queue< FMTLineInfo > Parser::FMTParser::_tryInclude ( const std::vector< Core::FMTTheme > &  p_themes,
const Core::FMTConstants p_cons,
std::queue< FMTLineInfo p_ForOut 
) const
protectedvirtual

Return the next lines to be read by the parser, considering included files.

Parameters
[in]p_themesthe model themes.
[in]p_consthe model constants.
[in]p_ForOutthe output of the for loops unroll.
Returns
a queue of lines to process.

◆ _upper()

std::string Parser::FMTParser::_upper ( const std::string &  lowercases) const
protected

Convert a string to upper case.

Parameters
[in]lowercasesthe string to convert.
Returns
the upper case string.

◆ bounds()

template<typename T >
Core::FMTBounds< T > Parser::FMTParser::bounds ( const Core::FMTConstants constants,
const std::string &  value,
const std::string &  ope,
Core::FMTsection  section 
) const
protected

Return a FMTBounds from a value based on the constants and a section.

Template Parameters
Tthe bounded value type.
Parameters
[in]constantsthe constants.
[in]valuethe value.
[in]opethe operator.
[in]sectionthe section.
Returns
the bounds.

◆ createLayer()

OGRLayer * Parser::FMTParser::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.

Parameters
[in]datasetthe dataset.
[in]namethe layer name.
[in]creationoptionsthe creation options.
Returns
the created layer.

◆ createOGRDataset()

GDALDataset * Parser::FMTParser::createOGRDataset ( std::string  location = std::string(),
std::string  gdaldrivername = "CSV" 
) const

Create an OGR vector dataset based on a driver name and a location.

Parameters
[in]locationthe location of the dataset.
[in]gdaldrivernamethe GDAL driver name.
Returns
the created dataset.

◆ createSubDirectory()

std::string Parser::FMTParser::createSubDirectory ( const std::string &  p_Directory,
const std::string &  p_SubDirectory 
)

Create a sub directory in directory.

Parameters
[in]p_Directorythe base directory
[in]p_SubDirectorythe sub directory
Returns
full directory path

◆ fromExtension()

static Core::FMTsection Parser::FMTParser::fromExtension ( const std::string &  p_Extension)
static

Return the FMTsection matching the extension of a file.

Parameters
[in]p_Extensionthe file extension.
Returns
the FMTsection matching the extension.

◆ getBaseOperators()

std::array< std::string, 5 > Parser::FMTParser::getBaseOperators ( ) const
protected

Return the operators normally found in the different sections.

Returns
the base operators.

◆ getCleanLine() [1/2]

std::string Parser::FMTParser::getCleanLine ( const std::string &  p_input) const

Clean a line and make it ready to be read by a parser.

Parameters
[in]p_inputthe input line.
Returns
the cleaned line.

◆ getCleanLine() [2/2]

std::string Parser::FMTParser::getCleanLine ( std::istream &  stream) const

Clean a line and make it ready to be read by a parser.

Parameters
[in,out]streamthe input stream.
Returns
the cleaned line.

◆ getGDALExtensions()

std::vector< std::vector< std::string > > Parser::FMTParser::getGDALExtensions ( const char *  spatialtype,
bool  testcreation = true 
) const
protected

Return the GDAL extensions organized by driver for a given spatial type.

Parameters
[in]spatialtypethe spatial type (raster or vector).
[in]testcreationif true only returns drivers that support creation.
Returns
the GDAL extensions organized by driver.

◆ getGDALRasterDriverExtensions()

std::vector< std::vector< std::string > > Parser::FMTParser::getGDALRasterDriverExtensions ( bool  testcreation = true) const

Return a vector of GDAL raster driver extensions organized by driver.

Parameters
[in]testcreationif true only returns drivers that support creation.
Returns
the GDAL raster driver extensions organized by driver.

◆ getGDALRasterDriverNames()

std::vector< std::string > Parser::FMTParser::getGDALRasterDriverNames ( bool  testcreation = true) const

Return a vector of GDAL raster driver names.

Parameters
[in]testcreationif true only returns drivers that support creation.
Returns
the GDAL raster driver names.

◆ getGDALVectorDriverExtensions()

std::vector< std::vector< std::string > > Parser::FMTParser::getGDALVectorDriverExtensions ( bool  testcreation = true) const

Return a vector of GDAL vector driver extensions organized by driver.

Parameters
[in]testcreationif true only returns drivers that support creation.
Returns
the GDAL vector driver extensions organized by driver.

◆ getGDALVectorDriverNames()

std::vector< std::string > Parser::FMTParser::getGDALVectorDriverNames ( bool  testcreation = true) const

Return a vector of GDAL vector driver names.

Parameters
[in]testcreationif true only returns drivers that support creation.
Returns
the GDAL vector driver names.

◆ getMostRecentFiletime()

std::time_t Parser::FMTParser::getMostRecentFiletime ( ) const

Return the most recent file time of the files read by the parser.

Returns
the most recent file time.

◆ operator=()

FMTParser & Parser::FMTParser::operator= ( const FMTParser rhs)

Copy assignment operator for FMTParser.

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

◆ readCsv()

std::vector< std::vector< std::string > > Parser::FMTParser::readCsv ( const std::string &  location,
const char &  separator 
)
protected

Read a CSV file from a location using a separator.

Parameters
[in]locationthe location.
[in]separatorthe separator.
Returns
a vector of vector of lines.

◆ regexLoop()

std::vector< std::string > Parser::FMTParser::regexLoop ( const boost::regex &  cutregex,
std::string &  str 
) const
protected

Capture a for loop from a line and return the variables to loop on.

Parameters
[in]cutregexthe regex.
[in,out]strthe line.
Returns
the variables to loop on.

◆ setHeader()

void Parser::FMTParser::setHeader ( const std::string &  header)

Set a string as the header written when the file is opened in write mode, replacing the comment attribute.

Parameters
[in]headerthe header string.

◆ spliter()

std::vector< std::string > Parser::FMTParser::spliter ( std::string  strmask,
const boost::regex &  xspliter 
) const
protected

Split a string into multiple strings.

Parameters
[in]strmaskthe string to split.
[in]xspliterthe splitting regex.
Returns
the split strings.

◆ tryOpening() [1/2]

bool Parser::FMTParser::tryOpening ( const std::ifstream &  stream,
const std::string &  location 
) const

Open an input stream at a given location.

Parameters
[in]streamthe input stream.
[in]locationthe location.
Returns
true if the stream is opened else false.

◆ tryOpening() [2/2]

bool Parser::FMTParser::tryOpening ( std::ofstream &  stream,
const std::string &  location 
) const

Open an output stream at a given location.

Parameters
[in,out]streamthe output stream.
[in]locationthe location.
Returns
true if the stream is opened else false.

Friends And Related Function Documentation

◆ Testing::UnitTestFMTParser

friend class Testing::UnitTestFMTParser
friend

Member Data Documentation

◆ m_AAGE

const boost::regex Parser::FMTParser::m_AAGE
staticprotected

A regex for capturing age specificaiton.

◆ m_AYLD

const boost::regex Parser::FMTParser::m_AYLD
staticprotected

A regex for capturing age/period/yield specification.

◆ m_AYLD_AGE

const boost::regex Parser::FMTParser::m_AYLD_AGE
staticprotected

A regex for capturing age or yield specification.

◆ m_BOUNDS

const boost::regex Parser::FMTParser::m_BOUNDS
staticprotected

A regex for capturing bounds for yield or age specification.

◆ m_comment

std::string Parser::FMTParser::m_comment
mutableprotected

Comment found in the actual line read by the parser.

◆ m_constrePlacement

int Parser::FMTParser::m_constrePlacement
mutableprotected

Number of constant replaced by a numerical number.

◆ m_line

int Parser::FMTParser::m_line
mutableprotected

Line id at which the parser is reading the values.

◆ m_location

std::string Parser::FMTParser::m_location
mutableprotected

File location of the section read by the parser.

◆ m_MostRecentFile

std::time_t Parser::FMTParser::m_MostRecentFile
mutableprotected

The most recent file time read by this parser.

◆ m_MTX

boost::recursive_mutex Parser::FMTParser::m_MTX
mutableprotected

Mutex for multi-threading.

◆ m_OPERATORS

const boost::regex Parser::FMTParser::m_OPERATORS
staticprotected

A regex for capturing simple operators.

◆ m_PRIMARY

const boost::regex Parser::FMTParser::m_PRIMARY
staticprotected

A regex for capturing the primary file.

◆ m_section

Core::FMTsection Parser::FMTParser::m_section
mutableprotected

The section in which the child class is in.

◆ m_SEPARATOR

const boost::regex Parser::FMTParser::m_SEPARATOR
staticprotected

A regex for splitting general string.


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