Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79504136
parameter_registry.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Aug 26, 19:13
Size
5 KB
Mime Type
text/x-c
Expires
Wed, Aug 28, 19:13 (2 d)
Engine
blob
Format
Raw Data
Handle
19994370
Attached To
rAKA akantu
parameter_registry.cc
View Options
/**
* @file parameter_registry.cc
*
* @author Nicolas Richart <nicolas.richart@epfl.ch>
*
* @date creation: Wed Nov 13 2013
* @date last modification: Thu Nov 19 2015
*
* @brief Parameter Registry and derived classes implementation
*
* @section LICENSE
*
* Copyright (©) 2014, 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* Akantu 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.
*
* Akantu 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 Akantu. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "parameter_registry.hh"
/* -------------------------------------------------------------------------- */
namespace akantu {
Parameter::Parameter() : name(""), description(""), param_type(_pat_internal) {}
/* -------------------------------------------------------------------------- */
Parameter::Parameter(std::string name, std::string description,
ParameterAccessType param_type)
: name(name), description(description), param_type(param_type) {}
/* -------------------------------------------------------------------------- */
bool Parameter::isWritable() const { return param_type & _pat_writable; }
/* -------------------------------------------------------------------------- */
bool Parameter::isReadable() const { return param_type & _pat_readable; }
/* -------------------------------------------------------------------------- */
bool Parameter::isInternal() const { return param_type & _pat_internal; }
/* -------------------------------------------------------------------------- */
bool Parameter::isParsable() const { return param_type & _pat_parsable; }
/* -------------------------------------------------------------------------- */
void Parameter::setAccessType(ParameterAccessType ptype) {
this->param_type = ptype;
}
/* -------------------------------------------------------------------------- */
void Parameter::printself(std::ostream & stream) const {
stream << " ";
if (isInternal())
stream << "iii";
else {
if (isReadable())
stream << "r";
else
stream << "-";
if (isWritable())
stream << "w";
else
stream << "-";
if (isParsable())
stream << "p";
else
stream << "-";
}
stream << " ";
std::stringstream sstr;
sstr << name;
UInt width = std::max(int(10 - sstr.str().length()), 0);
sstr.width(width);
if (description != "") {
sstr << " [" << description << "]";
}
stream << sstr.str();
width = std::max(int(50 - sstr.str().length()), 0);
stream.width(width);
stream << " : ";
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ParameterRegistry::ParameterRegistry() : consisder_sub(true) {
}
/* -------------------------------------------------------------------------- */
ParameterRegistry::~ParameterRegistry() {
std::map<std::string, Parameter *>::iterator it, end;
for (it = params.begin(); it != params.end(); ++it) {
delete it->second;
it->second = NULL;
}
this->params.clear();
}
/* -------------------------------------------------------------------------- */
void ParameterRegistry::printself(std::ostream & stream, int indent) const {
std::string space;
for (Int i = 0; i < indent; i++, space += AKANTU_INDENT)
;
Parameters::const_iterator it;
for (it = params.begin(); it != params.end(); ++it) {
stream << space;
it->second->printself(stream);
}
SubRegisteries::const_iterator sub_it;
for (sub_it = sub_registries.begin(); sub_it != sub_registries.end(); ++sub_it) {
stream << space << "Registry [" << std::endl;
sub_it->second->printself(stream, indent + 1);
stream << space << "]";
}
}
/* -------------------------------------------------------------------------- */
void ParameterRegistry::registerSubRegistry(const ID & id,
ParameterRegistry & registry) {
sub_registries[id] = ®istry;
}
/* -------------------------------------------------------------------------- */
void ParameterRegistry::setParameterAccessType(const std::string & name,
ParameterAccessType ptype) {
Parameters::iterator it = params.find(name);
if (it == params.end())
AKANTU_CUSTOM_EXCEPTION(debug::ParameterUnexistingException(name));
Parameter & param = *(it->second);
param.setAccessType(ptype);
}
} // akantu
Event Timeline
Log In to Comment