OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
24 // Class AttributeHandler
25 // ------------------------------------------------------------------------
26 
27 std::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(def),
35  is_deferred(false), is_readonly(false)
36 {}
37 
38 
40 {}
41 
42 
44  throw OpalException("AttributeHandler::clone()",
45  "Internal error: should not call this method.");
46 }
47 
48 
50  if(itsDefault.isValid()) {
51  return &*itsDefault;
52  } else {
53  throw OpalException("AttributeHandler::getDefault()",
54  "Attribute \"" + itsName + "\" has no default value.");
55  }
56 }
57 
58 
59 const std::string &AttributeHandler::getHelp() const {
60  return itsHelp;
61 }
62 
63 
64 const 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 
97 std::multimap<AttributeHandler::OwnerType, std::string> AttributeHandler::getOwner(const std::string &att) {
98  std::multimap<OwnerType, std::string> possibleOwners;
99 
101  auto its = attributeOwnerDictionary_s.equal_range(att);
102 
103  for (auto it = its.first; it != its.second; ++ it) {
104  auto owner = it->second;
105 
106  possibleOwners.insert(std::make_pair(owner.first, owner.second));
107  }
108  }
109 
110  return possibleOwners;
111 }
112 
113 void AttributeHandler::addAttributeOwner(const std::string &owner,
115  const std::string &name) {
116  attributeOwnerDictionary_s.insert(std::make_pair(name,
117  std::make_pair(type,
118  owner)
119  )
120  );
121 }
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
virtual void parseComponent(Attribute &a, Statement &s, bool eval, int i) const
Parse component value.
Pointer< AttributeBase > itsDefault
Default value.
bool is_deferred
Defer flag.
The base class for all OPAL exceptions.
Definition: OpalException.h:28
const std::string itsName
Attribute name.
const std::string itsHelp
Help text.
void setReadOnly(bool)
Set or reset read-only flag.
void setDeferred(bool)
Set or reset defer flag.
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
virtual ~AttributeHandler()
virtual AttributeBase * getDefault() const
Return default value.
virtual const std::string & getHelp() const
Return help string.
A representation of an Object attribute.
Definition: Attribute.h:55
virtual const std::string & getName() const
Return attribute name.
Interface for statements.
Definition: Statement.h:38
virtual AttributeHandler * clone() const
Make clone.
Abstract base class for attribute parsers.
bool isValid() const
Test for validity.
Definition: Pointer.h:170
bool isDeferred() const
Return defer flag.
Abstract base class for reference counted objects.
Definition: RCObject.h:42
static std::multimap< OwnerType, std::string > getOwner(const std::string &att)
const std::string name
static std::multimap< std::string, std::pair< OwnerType, std::string > > attributeOwnerDictionary_s
bool is_readonly
Read-only flag.
bool isReadOnly() const
Return read-only flag.