OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 <sstream>
23
24// Class AttributeHandler
25// ------------------------------------------------------------------------
26
27std::multimap<std::string, std::pair<AttributeHandler::OwnerType, std::string> >
29
31 const std::string& name, const std::string& help, AttributeBase* def)
32 : itsName(name),
33 itsHelp(help),
34 itsDefault(std::shared_ptr<AttributeBase>(def)),
35 is_deferred(false),
36 is_readonly(false) {}
37
39
41 if (itsDefault) {
42 return &*itsDefault;
43 } else {
44 throw OpalException(
45 "AttributeHandler::getDefault()",
46 "Attribute \"" + itsName + "\" has no default value.");
47 }
48}
49
50const std::string& AttributeHandler::getHelp() const { return itsHelp; }
51
52const std::string& AttributeHandler::getName() const { return itsName; }
53
55 // Default behaviour.
56 throw OpalException(
57 "AttributeHandler::parseComponent()",
58 "You cannot assign to a component of \"" + itsName + "\" which is not a vector value.");
59}
60
62
63void AttributeHandler::setDeferred(bool flag) { is_deferred = flag; }
64
66
67void AttributeHandler::setReadOnly(bool flag) { is_readonly = flag; }
68
70 const std::set<std::string>& predefinedValues, const std::string& defaultValue) {
71 std::ostringstream oss;
72 for (auto it = predefinedValues.begin(); it != predefinedValues.end(); ++it) {
73 if (it != predefinedValues.begin()) oss << ", ";
74 oss << *it;
75 }
76 std::string validValues = " Valid values are " + oss.str() + ".";
77 if (defaultValue != "_HAS_NO_DEFAULT_") {
78 validValues += " Its default is " + defaultValue + ".";
79 }
80 std::string* help = const_cast<std::string*>(&itsHelp);
81 *help += validValues;
82}
83
84std::multimap<AttributeHandler::OwnerType, std::string> AttributeHandler::getOwner(
85 const std::string& att) {
86 std::multimap<OwnerType, std::string> possibleOwners;
87
89 auto its = attributeOwnerDictionary_s.equal_range(att);
90
91 for (auto it = its.first; it != its.second; ++it) {
92 auto owner = it->second;
93
94 possibleOwners.insert(std::make_pair(owner.first, owner.second));
95 }
96 }
97
98 return possibleOwners;
99}
100
102 const std::string& owner, const AttributeHandler::OwnerType& type,
103 const std::string& name) {
104 attributeOwnerDictionary_s.insert(std::make_pair(name, std::make_pair(type, owner)));
105}
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.
bool isReadOnly() const
Return read-only flag.
static std::multimap< OwnerType, std::string > getOwner(const std::string &att)
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.
A representation of an Object attribute.
Definition Attribute.h:52
Interface for statements.
Definition Statement.h:37
STL namespace.