OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
AttributeSet.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: AttributeSet.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.2 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: AttributeSet
10// A map of name (std::string) versus value (double) intended to store
11// user-defined attributes.
12//
13// ------------------------------------------------------------------------
14// Class category: AbsBeamline
15// ------------------------------------------------------------------------
16//
17// $Date: 2000/12/16 16:26:43 $
18// $Author: mad $
19//
20// ------------------------------------------------------------------------
21
23#include "Channels/Channel.h"
25
26// Class AttributeSet
27// ------------------------------------------------------------------------
28
30
31AttributeSet::AttributeSet(const AttributeSet& rhs) : itsMap(rhs.itsMap) {}
32
34
36 itsMap = rhs.itsMap;
37 return *this;
38}
39
40double AttributeSet::getAttribute(const std::string& aKey) const {
41 const_iterator index = itsMap.find(aKey);
42
43 if (index == itsMap.end()) {
44 return 0.0;
45 } else {
46 return index->second;
47 }
48}
49
50bool AttributeSet::hasAttribute(const std::string& aKey) const {
51 return (itsMap.find(aKey) != itsMap.end());
52}
53
54void AttributeSet::removeAttribute(const std::string& aKey) { itsMap.erase(aKey); }
55
56void AttributeSet::setAttribute(const std::string& aKey, double value) { itsMap[aKey] = value; }
57
58// This method is inlined so its const version can wrap it.
59// ada 3-7-2000 remove inline because KCC does not like it.
60
61Channel* AttributeSet::getChannel(const std::string& aKey, bool create) {
62 NameMap::iterator index = itsMap.find(aKey);
63
64 if (index == itsMap.end()) {
65 if (create) {
66 itsMap[aKey] = 0.0;
67 return new DirectChannel(itsMap[aKey]);
68 }
69 // for (NameMap::iterator index = itsMap.begin(); index != itsMap.end(); index++)
70 return nullptr;
71 } else {
72 return new DirectChannel((*index).second);
73 }
74}
75
76const ConstChannel* AttributeSet::getConstChannel(const std::string& aKey) const {
77 // Use const_cast to allow calling the non-const GetChannel().
78 // The const return value will nevertheless inhibit set().
79 return const_cast<AttributeSet*>(this)->getChannel(aKey);
80}
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.
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.
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.
Abstract interface for read/write access to variable.
Definition Channel.h:30
Abstract interface for read-only access to variable.
Direct access to a [b]double[/b] variable.