Namespaces | |
| namespace | fsfc |
Functions | |
| template<class T> | |
| void | fsfc::parse (T &s, std::istream &is) |
| Fill a structure from an input stream. | |
| template<class T> | |
| void | fsfc::parseFile (T &s, const std::string &fileName) |
| Conveniance function similar to parse() taking a file name as input. | |
| template<class T> | |
| void | fsfc::output (T &s, std::ostream &os) |
| Write the structure contente into an output stream. | |
| template<class T> | |
| void | fsfc::outputFile (T &s, const std::string &fileName) |
| Conveniance function similar to output() taking a file name as input. | |
libfsf, generating code to fill structures from configuration files.
Copyright (C) 2007 Matthieu Nottale.
This file is part of libfsfc.
libfsfc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3,
as published by the Free Software Foundation.
libfsfc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libfsfc. If not, see <http://www.gnu.org/licenses/>.
class Point { public: int x; int y; };
Point p;
parse(p, myStream);
This code will successfuly fill p, if myStream contains a representation of a Point, such as "x 1 y 2", "1 2", "x:1 y:2" ...
Your structure can have fields of any type that operator >>(std::istream&is, const YourType&) can handle, and of types for which you ran fsfcgen. std::list and std::vector are also handled.
The parser can be configured using keywords in the Doxygen commentary of your class. Either in the class description, or in the field descriptions. There are two types of options: boolean, or tri-stated. Booleans can be either true or false. Boolean option <opt> can be set to true by the keyword <opt>, enable<opt> or allow<opt>; it can be set to false by no<opt>, not<opt>, disable<opt>, or deny<opt>. Tri-stated options can have a value of ALLOW, REQUIRE or DENY.
They can be set by <opt> <val> (or <opt>:<val>). A specific value can also be set by using allow<opt>, require<opt>, or deny<opt>
The supported options are:
The options are also used to control the output format: the output will use the format dictated by the options with a REQUIRE value.
Here is a simple hypothetical experiment control structure:
///A point,parse options: singleLine fieldName:deny as this struct is simple
class Point
{
public:
float x;
float y;
};
///Class describing an algorithm
class Algorithm
{
public:
std::string name;
bool needsReloading; ///< Reload the module after each run?
std::string extraParameters; ///< extra parameters to pass, optional
};
class Experiment
{
public:
///name of the experiment
std::string name;
/// starting point
Point startingPoint;
/// algorithm to use
Algorithm algorithm;
///optional: frame numbers for which to log
std::list<int> logFrame;
};
#comments start with '#' and spawn until end of line.
name="experiment 12" # strings can be quoted
startingPoint = 0 0
logFrame = 10 20 30
algorithm = # order does not matter if field name are given
name = "von schtroumpf"
needsReloading = 0
#notice the missing optional field
name: "experiment \"12\"" #escaping is supported
startingPoint: 0 0
algorithm: {
name "bucher"
needsReloading 1
extraParameters "hiiiiiiiiiiiii"
}
logFrame:
10
20
30
name experiment_12
startingPoint { 0 0}
algorithm { name:Voight-Kampf needsReloading:0}
logFrame 10 #std::list support multipleWrite by default.
logFrame 20
logFrame 30
CLASS_BEGIN(classname)
FIELD(classname, field1name, field1type)
FIELD(classname, field2name, field2type)
CLASS_END(classname)
1.5.4