OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
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 
20 #include "Parser/Statement.h"
22 
23 #include <boost/algorithm/string/join.hpp>
24 
25 // Class AttributeHandler
26 // ------------------------------------------------------------------------
27 
28 std::multimap<std::string,
30  std::string>
32 
34 (const std::string &name, const std::string &help, AttributeBase *def):
35  RCObject(), itsName(name), itsHelp(help), itsDefault(def),
36  is_deferred(false), is_readonly(false)
37 {}
38 
39 
41 {}
42 
43 
45  throw OpalException("AttributeHandler::clone()",
46  "Internal error: should not call this method.");
47 }
48 
49 
51  if(itsDefault.isValid()) {
52  return &*itsDefault;
53  } else {
54  throw OpalException("AttributeHandler::getDefault()",
55  "Attribute \"" + itsName + "\" has no default value.");
56  }
57 }
58 
59 
60 const std::string &AttributeHandler::getHelp() const {
61  return itsHelp;
62 }
63 
64 
65 const std::string &AttributeHandler::getName() const {
66  return itsName;
67 }
68 
69 
71 (Attribute &, Statement &, bool, int) const {
72  // Default behaviour.
73  throw OpalException("AttributeHandler::parseComponent()",
74  "You cannot assign to a component of \"" + itsName +
75  "\" which is not a vector value.");
76 }
77 
78 
80  return is_deferred;
81 }
82 
83 
85  is_deferred = flag;
86 }
87 
88 
90  return is_readonly;
91 }
92 
93 
95  is_readonly = flag;
96 }
97 
98 void AttributeHandler::setPredefinedValues(const std::set<std::string>& predefinedValues,
99  const std::string& defaultValue)
100 {
101  std::string validValues = " Valid values are " + boost::algorithm::join(predefinedValues, ", ") + ".";
102  if (defaultValue != "_HAS_NO_DEFAULT_") {
103  validValues += " Its default is " + defaultValue + ".";
104  }
105  std::string* help = const_cast<std::string*>(&itsHelp);
106  *help += validValues;
107 }
108 
109 std::multimap<AttributeHandler::OwnerType, std::string> AttributeHandler::getOwner(const std::string &att) {
110  std::multimap<OwnerType, std::string> possibleOwners;
111 
113  auto its = attributeOwnerDictionary_s.equal_range(att);
114 
115  for (auto it = its.first; it != its.second; ++ it) {
116  auto owner = it->second;
117 
118  possibleOwners.insert(std::make_pair(owner.first, owner.second));
119  }
120  }
121 
122  return possibleOwners;
123 }
124 
125 void AttributeHandler::addAttributeOwner(const std::string &owner,
127  const std::string &name) {
128  attributeOwnerDictionary_s.insert(std::make_pair(name,
129  std::make_pair(type,
130  owner)
131  )
132  );
133 }
const std::string name
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
A representation of an Object attribute.
Definition: Attribute.h:52
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
Abstract base class for attribute parsers.
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.
Pointer< AttributeBase > itsDefault
Default value.
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.
virtual ~AttributeHandler()
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.
bool isValid() const
Test for validity.
Definition: Pointer.h:172
Abstract base class for reference counted objects.
Definition: RCObject.h:40
Interface for statements.
Definition: Statement.h:38
The base class for all OPAL exceptions.
Definition: OpalException.h:28