OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
AttributeSet.h
Go to the documentation of this file.
1#ifndef OPALX_AttributeSet_HH
2#define OPALX_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 <functional>
27#include <map>
28#include <string>
29
30class Channel;
31class 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
42public:
44 typedef std::map<std::string, double, std::less<std::string> > NameMap;
45
47 typedef NameMap::const_iterator const_iterator;
48
50 // Constructs an empty map.
52
54 virtual ~AttributeSet();
55 const AttributeSet& operator=(const AttributeSet&);
56
58 const_iterator begin() const;
59
61 const_iterator end() const;
62
64 // If the attribute does not exist, return zero.
65 double getAttribute(const std::string& aKey) const;
66
68 // If the attribute exists, return true, otherwise false.
69 bool hasAttribute(const std::string& aKey) const;
70
72 // If the key [b]aKey[/b] exists, this method removes it.
73 void removeAttribute(const std::string& aKey);
74
76 void setAttribute(const std::string& aKey, double val);
77
79 // This method constructs a Channel permitting read/write access to
80 // the attribute [b]aKey[/b] and returns it.
81 // If the attribute does not exist, it returns nullptr.
82 Channel* getChannel(const std::string& aKey, bool create = false);
83
85 // This method constructs a Channel permitting read-only access to
86 // the attribute [b]aKey[/b] and returns it.
87 // If the attribute does not exist, it returns nullptr.
88 const ConstChannel* getConstChannel(const std::string& aKey) const;
89
90protected:
92
94};
95
96// Implementation.
97// ------------------------------------------------------------------------
98
100
102
103#endif // OPALX_AttributeSet_HH
Map of std::string versus double value.
virtual ~AttributeSet()
bool hasAttribute(const std::string &aKey) const
Test for presence of an attribute.
AttributeSet()
Default constructor.
const AttributeSet & operator=(const AttributeSet &)
void removeAttribute(const std::string &aKey)
Remove an existing attribute.
const_iterator begin() const
Iterator accessing first member.
NameMap::const_iterator const_iterator
An iterator for a map of name versus value.
Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
std::map< std::string, double, std::less< std::string > > NameMap
A map of name versus value.
void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
double getAttribute(const std::string &aKey) const
Get attribute value.
const ConstChannel * getConstChannel(const std::string &aKey) const
Construct a read-only channel.
NameMap itsMap
The attribute map.
const_iterator end() const
Iterator marking the end of the list.
Abstract interface for read/write access to variable.
Definition Channel.h:30
Abstract interface for read-only access to variable.