Page MenuHomec4science

lm_parsable.hh
No OneTemporary

File Metadata

Created
Mon, Jul 1, 09:35

lm_parsable.hh

/**
* @file lm_parsable.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Thu Sep 18 16:13:19 2014
*
* @brief Common mother for parsable objects
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __LIBMULTISCALE_LM_PARSABLE_HH__
#define __LIBMULTISCALE_LM_PARSABLE_HH__
/* -------------------------------------------------------------------------- */
#include "lm_defaults.hh"
#include "lm_macros.hh"
#include "parse_result.hh"
#include <set>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
class Parsable {
/* ------------------------------------------------------------------------ */
/* Typedefs */
/* ------------------------------------------------------------------------ */
public:
template <typename T> class ParameterTyped;
class Parameter;
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
Parsable(const Parsable &p);
Parsable();
virtual ~Parsable();
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
/* LMDESC PARSABLE
TODO
*/
public:
//! parse an entire line
virtual ParseResult parseLine(const std::string &buffer);
//! check that all the keywords are parsed
void checkAllKeywordsAreParsed();
//! add a parsable to receive keywords
void addSubParsableObject(Parsable *ptr);
//! add a parsable to receive keywords
void addSubParsableObject(Parsable &obj);
//! set parameters by direct access
template <typename T>
void setParam(const std::string &keyword, const T &value);
// template <typename T>
// void setParam(const std::string & keyword,T value, UInt ind);
//! get parameters by direct access
template <typename T> void getParam(const std::string &keyword, T &value);
protected:
//! declare parameters
virtual void declareParams() = 0;
//! declare parameters
template <typename T>
void declareParam(const std::string &keyword, T &var,
const default_val<T> def);
//! set parameters
virtual ParseResult setParam(const std::string &keyword,
std::stringstream &line);
template <typename T>
void parseKeyword(const std::string &keyword, T &var,
const default_val<T> def = default_val<T>());
template <typename T, typename V>
void parseKeyword(const std::string &keyword, T &var, const V &def);
template <typename T, UInt nb>
void parseVectorKeyword(const std::string &keyword, UInt n, T (&var)[nb],
const std::vector<T> def);
template <typename T, UInt nb>
void parseVectorKeyword(const std::string &keyword, UInt n, T (&var)[nb],
const default_val<T[nb]> def = default_val<T[nb]>());
template <PhysicalQuantity q, UInt nb, typename T>
void parseVectorKeyword(const std::string &keyword, UInt n,
Quantity<q, nb, T> &var, const std::vector<T> def);
template <UInt nb, typename T>
void parseVectorKeyword(const std::string &keyword, UInt n,
Vector<nb, T> &var, const std::vector<T> def);
template <typename T>
void parseVectorKeyword(const std::string &keyword, UInt n,
std::vector<T> &var, const std::vector<T> def);
template <PhysicalQuantity q, UInt nb, typename T>
void parseVectorKeyword(const std::string &keyword, UInt n,
Quantity<q, nb, T> &var,
const default_val<Quantity<q, nb, T>> def =
default_val<Quantity<q, nb, T>>());
template <typename T>
void parseVectorKeyword(const std::string &keyword, UInt n, T &var,
const default_val<T> def = default_val<T>());
void parseTag(const std::string &keyword, bool &var,
const default_val<bool> def = default_val<bool>());
template <typename T>
void changeDefault(const std::string &keyword, const T &val);
private:
//! check if parameter is existing
void checkKeyword(const std::string &keyword);
//! return a list of registered keywords
std::string listKeywordsToStr();
//! generate the list of registered keywords
void generateListKeywords();
//! simply answer if is accepting the keyword
bool doAcceptKeyword(const std::string &keyword);
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
std::map<std::string, Parameter *> params;
bool are_parameters_declared;
std::vector<Parsable *> forward_parsable;
std::set<std::string> list_keywords;
};
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_LM_PARSABLE_HH__ */

Event Timeline