OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 }
bool isValid() const
Test for validity.
Definition: Pointer.h:172
const std::string itsHelp
Help text.
virtual const std::string & getHelp() const
Return help string.
Abstract base class for reference counted objects.
Definition: RCObject.h:40
Abstract base class for attribute parsers.
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition: LICENSE:43
Pointer< AttributeBase > itsDefault
Default value.
virtual AttributeBase * getDefault() const
Return default value.
void setReadOnly(bool)
Set or reset read-only flag.
bool isReadOnly() const
Return read-only flag.
bool isDeferred() const
Return defer flag.
bool is_deferred
Defer flag.
void setDeferred(bool)
Set or reset defer flag.
void setPredefinedValues(const std::set< std::string > &, const std::string &)
Add predefined strings values to the help.
virtual ~AttributeHandler()
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual const std::string & getName() const
Return attribute name.
Interface for statements.
Definition: Statement.h:38
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
static std::multimap< std::string, std::pair< OwnerType, std::string > > attributeOwnerDictionary_s
const std::string name
static std::multimap< OwnerType, std::string > getOwner(const std::string &att)
virtual AttributeHandler * clone() const
Make clone.
const std::string itsName
Attribute name.
SDDS1 &description type
Definition: test.stat:4
virtual void parseComponent(Attribute &a, Statement &s, bool eval, int i) const
Parse component value.
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
bool is_readonly
Read-only flag.
A representation of an Object attribute.
Definition: Attribute.h:52