OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
AttributeSet.h
Go to the documentation of this file.
1 #ifndef CLASSIC_AttributeSet_HH
2 #define CLASSIC_AttributeSet_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: AttributeSet.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.2 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: AttributeSet
13 // A map of name (std::string) versus value (double) intended to store
14 // user-defined attributes.
15 //
16 // ------------------------------------------------------------------------
17 // Class category: AbsBeamline
18 // ------------------------------------------------------------------------
19 //
20 // $Date: 2000/12/16 16:26:43 $
21 // $Author: mad $
22 //
23 // ------------------------------------------------------------------------
24 
25 //#include "Channels/Channel.h"
26 #include <map>
27 #include <functional>
28 #include <string>
29 
30 class Channel;
31 class ConstChannel;
32 
33 // Class AttributeSet
34 // ------------------------------------------------------------------------
36 // Class AttributeSet implements a map of name (std::string) versus value
37 // (double) for user-defined attributes. This map is intended for
38 // algorithms that require specific, but not predefined data in the
39 // accelerator model for their working.
40 
41 class AttributeSet {
42 
43 public:
44 
46  typedef std::map<std::string, double, std::less<std::string> > NameMap;
47 
49  typedef NameMap::const_iterator const_iterator;
50 
52  // Constructs an empty map.
53  AttributeSet();
54 
55  AttributeSet(const AttributeSet &);
56  virtual ~AttributeSet();
57  const AttributeSet &operator=(const AttributeSet &);
58 
60  const_iterator begin() const;
61 
63  const_iterator end() const;
64 
65 
67  // If the attribute does not exist, return zero.
68  double getAttribute(const std::string &aKey) const;
69 
71  // If the attribute exists, return true, otherwise false.
72  bool hasAttribute(const std::string &aKey) const;
73 
75  // If the key [b]aKey[/b] exists, this method removes it.
76  void removeAttribute(const std::string &aKey);
77 
79  void setAttribute(const std::string &aKey, double val);
80 
81 
83  // This method constructs a Channel permitting read/write access to
84  // the attribute [b]aKey[/b] and returns it.
85  // If the attribute does not exist, it returns NULL.
86  Channel *getChannel(const std::string &aKey, bool create = false);
87 
89  // This method constructs a Channel permitting read-only access to
90  // the attribute [b]aKey[/b] and returns it.
91  // If the attribute does not exist, it returns NULL.
92  const ConstChannel *getConstChannel(const std::string &aKey) const;
93 
94 protected:
95 
97 
99 };
100 
101 
102 // Implementation.
103 // ------------------------------------------------------------------------
104 
106 { return itsMap.begin(); }
107 
109 { return itsMap.end(); }
110 
111 #endif // CLASSIC_AttributeSet_HH
Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
Map of std::string versus double value.
Definition: AttributeSet.h:41
const_iterator end() const
Iterator marking the end of the list.
Definition: AttributeSet.h:108
NameMap::const_iterator const_iterator
An iterator for a map of name versus value.
Definition: AttributeSet.h:49
const_iterator begin() const
Iterator accessing first member.
Definition: AttributeSet.h:105
bool hasAttribute(const std::string &aKey) const
Test for presence of an attribute.
Abstract interface for read-only access to variable.
Definition: ConstChannel.h:29
virtual ~AttributeSet()
void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
NameMap itsMap
The attribute map.
Definition: AttributeSet.h:98
Abstract interface for read/write access to variable.
Definition: Channel.h:32
const AttributeSet & operator=(const AttributeSet &)
AttributeSet()
Default constructor.
void removeAttribute(const std::string &aKey)
Remove an existing attribute.
std::map< std::string, double, std::less< std::string > > NameMap
A map of name versus value.
Definition: AttributeSet.h:46
double getAttribute(const std::string &aKey) const
Get attribute value.
const ConstChannel * getConstChannel(const std::string &aKey) const
Construct a read-only channel.