OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
AttributeHandler.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: AttributeHandler.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: AttributeHandler
10// An abstract class used to parse and print attributes.
11//
12// ------------------------------------------------------------------------
13//
14// $Date: 2000/03/27 09:33:34 $
15// $Author: Andreas Adelmann $
16//
17// ------------------------------------------------------------------------
18
21
22#include <boost/algorithm/string/join.hpp>
23
24// Class AttributeHandler
25// ------------------------------------------------------------------------
26
27std::multimap<std::string,
29 std::string>
31
33(const std::string &name, const std::string &help, AttributeBase *def):
34 RCObject(), itsName(name), itsHelp(help), itsDefault(std::shared_ptr<AttributeBase>(def)),
35 is_deferred(false), is_readonly(false)
36{}
37
38
41
42
44 throw OpalException("AttributeHandler::clone()",
45 "Internal error: should not call this method.");
46}
47
48
50 if(itsDefault) {
51 return &*itsDefault;
52 } else {
53 throw OpalException("AttributeHandler::getDefault()",
54 "Attribute \"" + itsName + "\" has no default value.");
55 }
56}
57
58
59const std::string &AttributeHandler::getHelp() const {
60 return itsHelp;
61}
62
63
64const std::string &AttributeHandler::getName() const {
65 return itsName;
66}
67
68
70(Attribute &, Statement &, bool, int) const {
71 // Default behaviour.
72 throw OpalException("AttributeHandler::parseComponent()",
73 "You cannot assign to a component of \"" + itsName +
74 "\" which is not a vector value.");
75}
76
77
79 return is_deferred;
80}
81
82
84 is_deferred = flag;
85}
86
87
89 return is_readonly;
90}
91
92
94 is_readonly = flag;
95}
96
97void AttributeHandler::setPredefinedValues(const std::set<std::string>& predefinedValues,
98 const std::string& defaultValue)
99{
100 std::string validValues = " Valid values are " + boost::algorithm::join(predefinedValues, ", ") + ".";
101 if (defaultValue != "_HAS_NO_DEFAULT_") {
102 validValues += " Its default is " + defaultValue + ".";
103 }
104 std::string* help = const_cast<std::string*>(&itsHelp);
105 *help += validValues;
106}
107
108std::multimap<AttributeHandler::OwnerType, std::string> AttributeHandler::getOwner(const std::string &att) {
109 std::multimap<OwnerType, std::string> possibleOwners;
110
112 auto its = attributeOwnerDictionary_s.equal_range(att);
113
114 for (auto it = its.first; it != its.second; ++ it) {
115 auto owner = it->second;
116
117 possibleOwners.insert(std::make_pair(owner.first, owner.second));
118 }
119 }
120
121 return possibleOwners;
122}
123
124void AttributeHandler::addAttributeOwner(const std::string &owner,
125 const AttributeHandler::OwnerType &type,
126 const std::string &name) {
127 attributeOwnerDictionary_s.insert(std::make_pair(name,
128 std::make_pair(type,
129 owner)
130 )
131 );
132}
STL namespace.
A representation of an Object attribute.
Definition Attribute.h:52
Abstract base class for attribute values of different types.
void setDeferred(bool)
Set or reset defer flag.
const std::string itsHelp
Help text.
virtual AttributeBase * getDefault() const
Return default value.
bool isDeferred() const
Return defer flag.
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
bool is_deferred
Defer flag.
void setReadOnly(bool)
Set or reset read-only flag.
static std::multimap< std::string, std::pair< OwnerType, std::string > > attributeOwnerDictionary_s
virtual const std::string & getName() const
Return attribute name.
const std::string itsName
Attribute name.
virtual const std::string & getHelp() const
Return help string.
virtual void parseComponent(Attribute &a, Statement &s, bool eval, int i) const
Parse component value.
AttributeHandler(const std::string &name, const std::string &help, AttributeBase *def)
Constructor.
bool isReadOnly() const
Return read-only flag.
static std::multimap< OwnerType, std::string > getOwner(const std::string &att)
virtual AttributeHandler * clone() const
Make clone.
bool is_readonly
Read-only flag.
void setPredefinedValues(const std::set< std::string > &, const std::string &)
Add predefined strings values to the help.
std::shared_ptr< AttributeBase > itsDefault
Default value.
RCObject()
Default constructor.
Definition RCObject.h:98
Interface for statements.
Definition Statement.h:38
The base class for all OPAL exceptions.