charon-core  0.3.1
Parameter.cpp
Go to the documentation of this file.
1 /* This file is part of Charon.
2 
3  Charon is free software: you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Charon is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public License
14  along with Charon. If not, see <http://www.gnu.org/licenses/>.
15  */
25 
26 // ==================== class AbstractParameter =========================
27 
29  _parent(0) {
30 }
31 
33  const std::string& name) {
34  if(_parent)
35  throw std::runtime_error(std::string("Parameter \"") + name + "\" already assigned");
36  if(!parent)
37  throw std::runtime_error("Setting invalid parent object!");
38  if(!name.length())
39  throw std::runtime_error("Invalid name: length 0");
40 
41  _parent = parent;
42  _name = name;
43 }
44 
45 AbstractParameter::~AbstractParameter() {
46 }
47 
49  return *_parent;
50 }
51 
53  return *_parent;
54 }
55 
56 std::string AbstractParameter::getName() const {
57  return _name;
58 }
59 
60 std::ostream & operator<<(
61  std::ostream& os, const AbstractParameter& parameter) {
62  parameter.intoStream(os);
63  return os;
64 }
65 
67  const ParameterFile& pf, const std::string paramName) const {
68  if (pf.isSet(paramName)) {
69  std::string refName = pf.get<std::string>(paramName);
70  if(refName.size() > 0 && refName.substr(0,1) == "@") {
71  refName = refName.erase(0,1);
72  return refName;
73  }
74  }
75  return paramName;
76 }
ParameteredObject * _parent
Parent ParameteredObject.
Definition: Parameter.h:67
void init(ParameteredObject *parent, const std::string &name)
Initialize new parameter.
Definition: Parameter.cpp:32
std::ostream & operator<<(std::ostream &os, const AbstractParameter &parameter)
Parameter stream output operator.
Definition: Parameter.cpp:60
charon_core_LOCAL AbstractParameter(const AbstractParameter &)
Forbid copying.
This class serves to store parameters used within the Charon Project.
Definition: ParameterFile.h:68
Parameter object handling.
Definition: Parameter.h:57
std::string _followLink(const ParameterFile &pf, const std::string paramName) const
Follow reference to targeted parameter.
Definition: Parameter.cpp:66
Base class for serializable objects.
std::string getName() const
Get parameter name.
Definition: Parameter.cpp:56
virtual void intoStream(std::ostream &os) const =0
Inserts the value of the Parameter at the end of a stream.
std::string _name
Parameter name.
Definition: Parameter.h:64
T get(std::string parameter) const
Get the value of a specified parameter.
bool isSet(std::string parameter) const
Check if a givem parameter has already been set.
Implementation of the template class ParameterFile.
ParameteredObject & getParent()
get parent object
Definition: Parameter.cpp:48
Implementation of the abstract class AbstractParameter and template classes Parameter and ParameterLi...