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

#include <FMTparser.hpp>

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

Public Member Functions

 FMTparser ()
 
 FMTparser (const FMTparser &rhs)
 
FMTparseroperator= (const FMTparser &rhs)
 
virtual ~FMTparser ()=default
 
std::time_t getmostrecentfiletime () const
 
void setheader (const std::string &header)
 
bool tryopening (const std::ifstream &stream, const std::string &location) const
 
bool tryopening (std::ofstream &stream, const std::string &location) const
 
bool isvalidfile (const std::string &location) const
 
bool isvalid (const std::string &line) const
 
std::vector< std::string > regexloop (const boost::regex &cutregex, std::string &str) const
 
std::vector< std::string > spliter (std::string strmask, const boost::regex &xspliter) const
 
void clearcomments (std::string &line)
 
std::string upper (const std::string &lowercases) const
 
std::string getcleanline (std::ifstream &stream)
 
std::queue< std::string > tryinclude (const std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
std::string returninclude (const std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
bool getforloops (std::string &line, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons, std::vector< std::string > &allvalues, std::string &target)
 
std::string getcleanlinewfor (std::ifstream &stream, const std::vector< Core::FMTtheme > &themes, const Core::FMTconstants &cons)
 
bool isnum (std::string value) const
 
bool isnum (const std::string &value, const Core::FMTconstants &constant, bool throwerror=true) const
 
template<typename T >
getnum (const std::string &value, const Core::FMTconstants &constant, int period=0) const
 
template<typename T >
getnum (const std::string &value, bool omitnumtest=false) const
 
template<typename T >
bool tryfillnumber (T &number, const std::string &value, const Core::FMTconstants &constant, int period=0) const
 
template<typename T >
Core::FMTbounds< T > bounds (const Core::FMTconstants &constants, const std::string &value, const std::string &ope, Core::FMTsection section) const
 
GDALDataset * createOGRdataset (std::string location=std::string(), std::string gdaldrivername="CSV") const
 
OGRLayer * createlayer (GDALDataset *dataset, const std::string &name, std::vector< std::string > creationoptions=std::vector< std::string >()) const
 
std::vector< std::string > getGDALvectordrivernames (bool testcreation=true) const
 
std::vector< std::string > getGDALrasterdrivernames (bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALvectordriverextensions (bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALrasterdriverextensions (bool testcreation=true) const
 
- Public Member Functions inherited from Core::FMTobject
 FMTobject ()
 
virtual ~FMTobject ()
 
 FMTobject (const std::shared_ptr< Exception::FMTexceptionhandler > exhandler)
 
 FMTobject (const FMTobject &rhs)
 
FMTobjectoperator= (const FMTobject &rhs)
 
virtual void passinlogger (const std::shared_ptr< Logging::FMTlogger > &logger)
 
void passinexceptionhandler (const std::shared_ptr< Exception::FMTexceptionhandler > &exhandler)
 
void redirectlogtofile (const std::string &location)
 
virtual void setdefaultlogger ()
 
virtual void setquietlogger ()
 
virtual void settasklogger ()
 
virtual void setdebuglogger ()
 
void setdefaultexceptionhandler ()
 
void setquietexceptionhandler ()
 
void setdebugexceptionhandler ()
 
void setfreeexceptionhandler ()
 
void disablenestedexceptions ()
 
void enablenestedexceptions ()
 
void seterrorstowarnings (const std::vector< Exception::FMTexc > &errors)
 
void setmaxwarningsbeforesilenced (const size_t &maxwarningcount)
 

Static Public Attributes

static const boost::regex rxseparator
 A regex for splitting general string.
 

Protected Member Functions

void setsection (const Core::FMTsection &section) const
 
std::vector< GDALDriver * > getallGDALdrivers (const char *spatialtype, bool testcreation=true) const
 
std::vector< std::vector< std::string > > getGDALextensions (const char *spatialtype, bool testcreation=true) const
 
void setcategories (GDALRasterBand *band, const std::vector< std::string > &categories) const
 
OGRCoordinateTransformation * getprojtransform (OGRLayer *baselayer, bool fittoforel=true) const
 
GDALDataset * gettransformmemlayercopy (OGRLayer *baselayer, const OGRSpatialReference *newreference, const std::string &fieldname) const
 
std::unique_ptr< OGRSpatialReference > getFORELspatialref () const
 
template<typename T >
GDALDataset * createdataset (const std::string &location, const Spatial::FMTlayer< T > &layer, const int datatypeid, std::string format="GTiff") const
 
GDALDataset * getdataset (const std::string &location) const
 
GDALDataset * getvectordataset (const std::string &location) const
 
OGRLayer * getlayer (GDALDataset *dataset, int id) const
 
GDALRasterBand * getband (GDALDataset *dataset, int bandid=1) const
 
GDALRasterBand * createband (GDALDataset *dataset, const std::vector< std::string > &categories, int bandid=1) const
 
std::vector< std::string > getcat (GDALDataset *dataset, int bandid=1) const
 
GDALRasterBand * getoverview (GDALRasterBand *band, int view=1) const
 
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
 
GDALDataset * createvectormemoryds () const
 
std::array< std::string, 5 > getbaseoperators () const
 
std::vector< std::string > sameas (const std::string &allset) const
 
std::map< Core::FMTsection, std::string > getprimary (const std::string &primarylocation)
 
bool isyld (const Core::FMTyields &ylds, const std::string &value, Core::FMTsection section) const
 
bool isact (Core::FMTsection section, const std::vector< Core::FMTaction > &actions, std::string action) const
 
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)
 
std::string setspec (Core::FMTsection section, Core::FMTkwor key, const Core::FMTyields &ylds, const Core::FMTconstants &constants, Core::FMTspec &spec, const std::string &line)
 
Core::FMTsection from_extension (const std::string &ext) const
 
std::vector< std::vector< std::string > > readcsv (const std::string &location, const char &separator)
 
- Protected Member Functions inherited from Core::FMTobject
template<class Archive >
void forcesave (Archive &ar, const unsigned int version) const
 
template<class Archive >
void forceload (Archive &ar, const unsigned int version)
 
void checksignals () const
 
void setCPLhandler ()
 

Protected Attributes

boost::recursive_mutex mtx
 Mutex for multi-threading.
 
Core::FMTsection _section
 The section in which the child class is in.
 
int _constreplacement
 Number of constant replaced by a numerical number.
 
int _line
 Line id at which the parser is reading the values.
 
std::string _comment
 Comment found in the actual line read by the parser.
 
std::string _location
 File location of the section read by the parser.
 
std::time_t mostrecentfile
 The most recent file time read by this parser.
 

Static Protected Attributes

static const boost::regex rxayld
 A regex for capturing age/period/yield specification.
 
static const boost::regex rxaage
 A regex for capturing age specificaiton.
 
static const boost::regex rxayldage
 A regex for capturing age or yield specification.
 
static const boost::regex rxbounds
 A regex for capturing bounds for yield or age specification.
 
static const boost::regex rxoperators
 A regex for capturing simple operators.
 
static const boost::regex rxprimary
 A regex for capturing the primary file.
 
- Static Protected Attributes inherited from Core::FMTobject
static std::shared_ptr< Exception::FMTexceptionhandler_exhandler
 A shared pointer to the exception handler.
 
static std::shared_ptr< Logging::FMTlogger_logger
 A shared pointer to the logger.
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::FMTobject
static std::string getruntimelocation ()
 
static unsigned long long getavailablememory ()
 
- Static Protected Member Functions inherited from Core::FMTobject
static std::chrono::time_point< std::chrono::high_resolution_clock > getclock ()
 
template<class chrono >
static double getduration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 
static std::string getdurationinseconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 

Detailed Description

The FMTparser is the main parent class of all the other FMTparser available in FMT. It has alot of usefull function common to all parser for validation and error throw when turning a std::string to something usefull in FMT.

Constructor & Destructor Documentation

◆ FMTparser() [1/2]

Parser::FMTparser::FMTparser ( )

Default constructor for FMTparser.

◆ FMTparser() [2/2]

Parser::FMTparser::FMTparser ( const FMTparser rhs)

Default copy constructor for FMTparser.

◆ ~FMTparser()

virtual Parser::FMTparser::~FMTparser ( )
virtualdefault

Default destructor for FMTparser.

Member Function Documentation

◆ 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

Templated function to get a FMTbounds from a (value) base on constants and a (section).

◆ clearcomments()

void Parser::FMTparser::clearcomments ( std::string &  line)

Clear comments from a line and fill up the _comment private value.

◆ createband()

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

Create a GDALrasterband in a GDALdataset where you can add categories.

◆ 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

The function create an empty GDALDataset for a given FMTlayer.

◆ createlayer()

OGRLayer * Parser::FMTparser::createlayer ( GDALDataset *  dataset,
const std::string &  name,
std::vector< std::string >  creationoptions = std::vector< std::string >() 
) const

Create a layer with from a dataset, it will delete layer with the same name before creation if it exist in the dataset

◆ createOGRdataset()

GDALDataset * Parser::FMTparser::createOGRdataset ( std::string  location = std::string(),
std::string  gdaldrivername = "CSV" 
) const

Will Create a OGR vector file based on a given drivername and a location.

◆ createvectormemoryds()

GDALDataset * Parser::FMTparser::createvectormemoryds ( ) const
protected

◆ from_extension()

Core::FMTsection Parser::FMTparser::from_extension ( const std::string &  ext) const
protected

Return the FMTsection given the extension of the file.

◆ getallGDALdrivers()

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

Return a vector of GDAL drivers for a given spatialtype (raster/vector)

◆ getband()

GDALRasterBand * Parser::FMTparser::getband ( GDALDataset *  dataset,
int  bandid = 1 
) const
protected

Open a GDALrasterband from a given GDALdataset and a (bandid).

◆ getbaseoperators()

std::array< std::string, 5 > Parser::FMTparser::getbaseoperators ( ) const
protected

Gives a vector of operators normaly found in the different sections.

◆ getcat()

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

Get categories of a GDALdataset for a given (bandid).

◆ getcleanline()

std::string Parser::FMTparser::getcleanline ( std::ifstream &  stream)

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

◆ getcleanlinewfor()

std::string Parser::FMTparser::getcleanlinewfor ( std::ifstream &  stream,
const std::vector< Core::FMTtheme > &  themes,
const Core::FMTconstants cons 
)

Get a clean line and consider for loops when reading the file.

◆ getdataset()

GDALDataset * Parser::FMTparser::getdataset ( const std::string &  location) const
protected

Open in readonly a GDALdataset from a given (location), will throw if anything went wrong.

◆ getFORELspatialref()

std::unique_ptr< OGRSpatialReference > Parser::FMTparser::getFORELspatialref ( ) const
protected

Return and OGRspatialReference corresponding to the one used for FORELs in Quebec.

◆ getforloops()

bool Parser::FMTparser::getforloops ( std::string &  line,
const std::vector< Core::FMTtheme > &  themes,
const Core::FMTconstants cons,
std::vector< std::string > &  allvalues,
std::string &  target 
)

Fill up the for loops queue.

◆ getGDALextensions()

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

Return a vector(organize the extentions by drivers) of vector of GDAL extensions accepted for the given spatialtype.

◆ getGDALrasterdriverextensions()

std::vector< std::vector< std::string > > Parser::FMTparser::getGDALrasterdriverextensions ( bool  testcreation = true) const

Return a vector(organize the extentions by drivers) of vector of GDAL raster driver extensions

◆ getGDALrasterdrivernames()

std::vector< std::string > Parser::FMTparser::getGDALrasterdrivernames ( bool  testcreation = true) const

Return a vector of GDAL raster driver names

◆ getGDALvectordriverextensions()

std::vector< std::vector< std::string > > Parser::FMTparser::getGDALvectordriverextensions ( bool  testcreation = true) const

Return a vector(organize the extentions by drivers) of vector of GDAL vector driver extensions

◆ getGDALvectordrivernames()

std::vector< std::string > Parser::FMTparser::getGDALvectordrivernames ( bool  testcreation = true) const

Return a vector of GDAL vector driver names

◆ getlayer()

OGRLayer * Parser::FMTparser::getlayer ( GDALDataset *  dataset,
int  id 
) const
protected

Open a GDALlayer from a vector GDALdataset for a given layer (id) and a actual (dataset), will throw if anything went wrong.

◆ getmostrecentfiletime()

std::time_t Parser::FMTparser::getmostrecentfiletime ( ) const

Get the most recentfiletime of the files read by ther parser.

◆ getnum() [1/2]

template<typename T >
T Parser::FMTparser::getnum ( const std::string &  value,
bool  omitnumtest = false 
) const

Template function to get a numeric value from a string (value).

◆ getnum() [2/2]

template<typename T >
T Parser::FMTparser::getnum ( const std::string &  value,
const Core::FMTconstants constant,
int  period = 0 
) const

Template function to get a numeric value from a string (value) based on constant and period.

◆ getoverview()

GDALRasterBand * Parser::FMTparser::getoverview ( GDALRasterBand *  band,
int  view = 1 
) const
protected

Get an overview of a GDALraserband.

◆ getprimary()

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

Using a primaryfile it returns the path to the different sections file locations.

◆ getprojtransform()

OGRCoordinateTransformation * Parser::FMTparser::getprojtransform ( OGRLayer *  baselayer,
bool  fittoforel = true 
) const
protected

Create a memory layer with a new int field named fieldname based on forel. Based on the baselayer.

◆ gettransformmemlayercopy()

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

Create a memory layer with a new int field named fieldname based on forel. Based on the baselayer. With a new spatial reference or can be the same has baselayer.

◆ getvectordataset()

GDALDataset * Parser::FMTparser::getvectordataset ( const std::string &  location) const
protected

Open in readonly a GDALdataset from a given (location) of a vector file, will throw if anything went wrong.

◆ 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

Will fill up all the fields id of the themes,age,area,lock of a given (layer).

◆ isact()

bool Parser::FMTparser::isact ( Core::FMTsection  section,
const std::vector< Core::FMTaction > &  actions,
std::string  action 
) const
protected

Test if a value (action) is actualy an action.

◆ isnum() [1/2]

bool Parser::FMTparser::isnum ( const std::string &  value,
const Core::FMTconstants constant,
bool  throwerror = true 
) const

Return true if the value is a number else it will raise (if throwerror = true) being non valid number.

◆ isnum() [2/2]

bool Parser::FMTparser::isnum ( std::string  value) const

Return true if the value is a number.

◆ isvalid()

bool Parser::FMTparser::isvalid ( const std::string &  line) const

Check if line is valid and clean it.

◆ isvalidfile()

bool Parser::FMTparser::isvalidfile ( const std::string &  location) const

Check if a file location is valid.

◆ isyld()

bool Parser::FMTparser::isyld ( const Core::FMTyields ylds,
const std::string &  value,
Core::FMTsection  section 
) const
protected

Test if a value is actualy a yield.

◆ operator=()

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

Default copy assignment for 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) and returns a vector of vector of lines.

◆ regexloop()

std::vector< std::string > Parser::FMTparser::regexloop ( const boost::regex &  cutregex,
std::string &  str 
) const

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

◆ returninclude()

std::string Parser::FMTparser::returninclude ( const std::string &  line,
const std::vector< Core::FMTtheme > &  themes,
const Core::FMTconstants cons 
)

return the next line to be read by the parser considering included files.

◆ sameas()

std::vector< std::string > Parser::FMTparser::sameas ( const std::string &  allset) const
protected

Used to deal with the _SAMEAS keyword.

◆ setcategories()

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

Write the categories in the band information

◆ setheader()

void Parser::FMTparser::setheader ( const std::string &  header)

Taking a string has argument set this string has an header in write mode when the file is opened. It will replace the _comment attribute with the header string.

◆ setsection()

void Parser::FMTparser::setsection ( const Core::FMTsection section) const
protected

It sets the section member of the FMTobject.

◆ 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 specifications of a given (spec) and return the rest of 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 a given or multiple (specs) and return the rest of line.

◆ spliter()

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

Split a string into multiple strings.

◆ tryfillnumber()

template<typename T >
bool Parser::FMTparser::tryfillnumber ( T &  number,
const std::string &  value,
const Core::FMTconstants constant,
int  period = 0 
) const

Try to get a number from a string (value) return false if failed.

◆ tryinclude()

std::queue< std::string > Parser::FMTparser::tryinclude ( const std::string &  line,
const std::vector< Core::FMTtheme > &  themes,
const Core::FMTconstants cons 
)

Read an included file and put the results into a queue.

◆ tryopening() [1/2]

bool Parser::FMTparser::tryopening ( const std::ifstream &  stream,
const std::string &  location 
) const

Open a input stream at a given location.

◆ tryopening() [2/2]

bool Parser::FMTparser::tryopening ( std::ofstream &  stream,
const std::string &  location 
) const

Open a output stream at a given location.

◆ upper()

std::string Parser::FMTparser::upper ( const std::string &  lowercases) const

Convert a string to upper case string.

Member Data Documentation

◆ _comment

std::string Parser::FMTparser::_comment
protected

Comment found in the actual line read by the parser.

◆ _constreplacement

int Parser::FMTparser::_constreplacement
mutableprotected

Number of constant replaced by a numerical number.

◆ _line

int Parser::FMTparser::_line
mutableprotected

Line id at which the parser is reading the values.

◆ _location

std::string Parser::FMTparser::_location
mutableprotected

File location of the section read by the parser.

◆ _section

Core::FMTsection Parser::FMTparser::_section
mutableprotected

The section in which the child class is in.

◆ mostrecentfile

std::time_t Parser::FMTparser::mostrecentfile
mutableprotected

The most recent file time read by this parser.

◆ mtx

boost::recursive_mutex Parser::FMTparser::mtx
mutableprotected

Mutex for multi-threading.

◆ rxaage

const boost::regex Parser::FMTparser::rxaage
staticprotected

A regex for capturing age specificaiton.

◆ rxayld

const boost::regex Parser::FMTparser::rxayld
staticprotected

A regex for capturing age/period/yield specification.

◆ rxayldage

const boost::regex Parser::FMTparser::rxayldage
staticprotected

A regex for capturing age or yield specification.

◆ rxbounds

const boost::regex Parser::FMTparser::rxbounds
staticprotected

A regex for capturing bounds for yield or age specification.

◆ rxoperators

const boost::regex Parser::FMTparser::rxoperators
staticprotected

A regex for capturing simple operators.

◆ rxprimary

const boost::regex Parser::FMTparser::rxprimary
staticprotected

A regex for capturing the primary file.

◆ rxseparator

const boost::regex Parser::FMTparser::rxseparator
static

A regex for splitting general string.


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