Page MenuHomec4science

lm_parsable_inline_impl.hh
No OneTemporary

File Metadata

Created
Sun, Jun 2, 17:18

lm_parsable_inline_impl.hh

/**
* @file lm_parsable_inline_impl.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Thu Feb 06 11:42:03 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_PARSABLE_INLINE_IMPL_HH__
#define __LIBMULTISCALE_PARSABLE_INLINE_IMPL_HH__
/* -------------------------------------------------------------------------- */
#include "lm_parameter.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename T>
void Parsable::parseKeyword(const std::string &keyword, T &var,
const default_val<T> def) {
this->declareParam<T>(keyword, var, def);
}
/* -------------------------------------------------------------------------- */
template <typename T, typename V>
void Parsable::parseKeyword(const std::string &keyword, T &var, V def) {
this->parseKeyword(keyword, var, make_default<T>(def));
}
/* -------------------------------------------------------------------------- */
template <typename T, typename V>
void Parsable::parseVectorKeyword(const std::string &keyword, UInt n, T &var,
V def) {
this->parseVectorKeyword(keyword, n, var, make_default<T>(def));
}
/* -------------------------------------------------------------------------- */
template <typename T>
void Parsable::parseVectorKeyword(const std::string &keyword, UInt n, T &var,
default_val<T> def) {
this->declareParam<T>(keyword, var, def, n);
}
/* -------------------------------------------------------------------------- */
// template <typename T,UInt nb>
// void parseVectorKeyword(const std::string & keyword, UInt n,T (& var)[nb],
// const std::initializer_list<T> def) {
// this->parseVectorKeyword(keyword,n,var,default_val<T[nb]>(def));
// }
/* -------------------------------------------------------------------------- */
// template <typename T, UInt nb>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n,
// T (&var)[nb], const std::vector<T> def) {
// this->parseVectorKeyword(keyword, n, var, default_val<T[nb]>(def));
// }
/* -------------------------------------------------------------------------- */
// template <typename T, UInt nb>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n,
// T (&var)[nb], const default_val<T[nb]> def)
// {
// if (n == nb) {
// this->parseKeyword(keyword, var, def);
// return;
// }
// switch (n) {
// case 1:
// this->parseKeyword(keyword, (T(&)[1])var, def);
// break;
// case 2:
// this->parseKeyword(keyword, (T(&)[2])var, def);
// break;
// case 3:
// this->parseKeyword(keyword, (T(&)[3])var, def);
// break;
// case 4:
// this->parseKeyword(keyword, (T(&)[4])var, def);
// break;
// case 5:
// this->parseKeyword(keyword, (T(&)[5])var, def);
// break;
// case 6:
// this->parseKeyword(keyword, (T(&)[6])var, def);
// break;
// default:
// LM_FATAL("internal error " << n << " " << nb);
// }
// }
/* -------------------------------------------------------------------------- */
// template <PhysicalQuantity q, UInt nb, typename T>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n,
// Quantity<q, nb, T> &var,
// const std::vector<T> def) {
// this->parseVectorKeyword(keyword, n, var,
// default_val<Quantity<q, nb, T>>(def));
// }
// /* --------------------------------------------------------------------------
// */
// template <UInt nb, typename T>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n,
// Vector<nb, T> &var,
// const std::vector<T> def) {
// this->parseVectorKeyword(keyword, n, var, default_val<Vector<nb, T>>(def));
// }
// /* --------------------------------------------------------------------------
// */
// template <PhysicalQuantity q, UInt nb, typename T>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n,
// Quantity<q, nb, T> &var,
// const default_val<Quantity<q, nb, T>> def)
// {
// if (n == nb) {
// this->parseKeyword(keyword, var, def);
// return;
// }
// switch (n) {
// case 1: {
// Quantity<q, 1, T> &smaller_var = var;
// this->parseKeyword(keyword, smaller_var, def);
// } break;
// case 2: {
// Quantity<q, 2, T> &smaller_var = var;
// this->parseKeyword(keyword, smaller_var, def);
// } break;
// case 3:
// this->parseKeyword(keyword, static_cast<Quantity<q, 3, T> &>(var), def);
// break;
// case 4:
// this->parseKeyword(keyword, static_cast<Quantity<q, 4, T> &>(var), def);
// break;
// case 5:
// this->parseKeyword(keyword, static_cast<Quantity<q, 5, T> &>(var), def);
// break;
// case 6:
// this->parseKeyword(keyword, static_cast<Quantity<q, 6, T> &>(var), def);
// break;
// default:
// LM_FATAL("internal error " << n << " " << nb);
// }
// }
// /* --------------------------------------------------------------------------
// */
// template <typename T>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n, T &var,
// const default_val<T> def) {
// this->parseKeyword(keyword, var, def);
// }
// /* --------------------------------------------------------------------------
// */
// template <typename T>
// void Parsable::parseVectorKeyword(const std::string &keyword, UInt n,
// std::vector<T> &var,
// const std::vector<T> def) {
// this->parseKeyword(keyword, var, def);
// }
// /* --------------------------------------------------------------------------
// */
template <typename T>
void Parsable::declareParam(const std::string &keyword, T &var,
const default_val<T> def, UInt n_entries) {
if (params.count(keyword) > 0)
LM_THROW("keyword " << keyword << " was already declared");
ParameterTyped<T> *param =
new ParameterTyped<T>(keyword, var, def, n_entries);
params[keyword] = param;
}
// /* --------------------------------------------------------------------------
// */
// template <typename T>
// void Parsable::setParam(const std::string &keyword, const T &value) {
// if (!are_parameters_declared) {
// declareParams();
// generateListKeywords();
// are_parameters_declared = true;
// }
// checkKeyword(keyword);
// for (UInt i = 0; i < forward_parsable.size(); ++i) {
// if (!forward_parsable[i]->doAcceptKeyword(keyword))
// continue;
// forward_parsable[i]->setParam(keyword, value);
// }
// if (!are_parameters_declared) {
// declareParams();
// are_parameters_declared = true;
// }
// if (params.count(keyword)) {
// Parameter *p = params[keyword];
// p->setParam(keyword, value);
// }
// }
/* -------------------------------------------------------------------------- */
// template <typename T>
// void Parsable::setParam(const std::string & keyword,T value, UInt ind){
// if (!are_parameters_declared) {
// declareParams();
// generateListKeywords();
// are_parameters_declared = true;
// }
// checkKeyword(keyword);
// for (UInt i = 0; i < forward_parsable.size(); ++i) {
// forward_parsable[i]->setParam(keyword,value, ind);
// }
// if (!are_parameters_declared) {
// declareParams();
// are_parameters_declared = true;
// }
// if (params.count(keyword)){
// Parameter * p = params[keyword];
// p->setParam(keyword,value, ind);
// }
// }
/* -------------------------------------------------------------------------- */
template <typename T>
void Parsable::getParam(const std::string &keyword, T &value) {
checkKeyword(keyword);
Parameter *p = params[keyword];
p->getParam(keyword, value);
}
/* -------------------------------------------------------------------------- */
template <typename T>
void Parsable::changeDefault(const std::string &keyword, const T &val) {
std::map<std::string, Parameter *>::iterator it = params.find(keyword);
std::map<std::string, Parameter *>::iterator end = params.end();
if (it == end)
LM_THROW("not registered " << keyword);
Parameter *p = it->second;
p->changeDefault(keyword, val);
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_PARSABLE_INLINE_IMPL_HH__ */

Event Timeline