1 #ifndef OPAL_SRefAttr_HH
2 #define OPAL_SRefAttr_HH
55 SRefAttr(
const std::string &oName,
const std::string &aName,
int index);
76 virtual void print(std::ostream &)
const;
80 virtual void set(
const T &)
const;
117 (
const std::string &oName,
const std::string &aName,
int index):
118 obj_name(oName), att_name(aName), itsIndex(index),
119 itsObject(0), itsAttr(0)
125 obj_name(rhs.obj_name), att_name(rhs.att_name), itsIndex(rhs.itsIndex),
126 itsObject(rhs.itsObject), itsAttr(rhs.itsAttr)
132 if(itsObject) itsObject->unregisterReference(
this);
150 std::vector<T> array = value->evaluate();
151 if(itsIndex >
int(array.size())) {
152 throw ParseError(
"SRefAttr::evaluate()",
"Reference \"" +
153 getImage() +
"\" has index out of range.");
155 return array[itsIndex - 1];
158 throw ParseError(
"SRefAttr::evaluate()",
"Reference \"" +
159 getImage() +
"\" is not an array.");
163 return value->evaluate();
165 throw ParseError(
"SRefAttr::evaluate()", getImage() +
166 "\" is of the wrong type.");
178 "Attribute is not of real type.");
191 if(! att_name.empty()) os <<
"->" << att_name;
192 if(itsIndex != 0) os <<
'[' << itsIndex <<
']';
210 return itsAttr->set(
new SValue<T>(value));
212 throw ParseError(
"Real::get()",
"Attribute \"" +
213 itsAttr->getName() +
"\" is of the wrong type.");
224 if(att_name.empty() && itsIndex <= 0) {
226 "\nThe <variable> \"" + obj_name +
"\" is unknown.\n");
229 "Object \"" + obj_name +
"\" is unknown.");
235 itsObject->registerReference(
const_cast<SRefAttr<T>*
>(
this));
237 if(att_name.empty()) {
238 itsAttr = itsObject->findAttribute(
"VALUE");
240 throw ParseError(
"SRefAttr::fill()",
"Object \"" + obj_name +
241 "\" is not a variable, constant or vector.");
244 itsAttr = itsObject->findAttribute(att_name);
246 throw ParseError(
"SRefAttr::fill()",
"Attribute \"" + obj_name +
247 "->" + att_name +
"\" is unknown.");
Representation objects and parsers for attribute expressions.
std::ostream & operator<<(std::ostream &os, const SRefAttr< T > &a)
A representation of an Object attribute.
Abstract base class for attribute values of different types.
An attribute defined as a reference to a scalar.
static const std::string typeName
void operator=(const SRefAttr &)
const std::string att_name
virtual SRefAttr< T > * clone() const
Make clone.
const std::string obj_name
virtual void set(const T &) const
Store new value.
virtual void print(std::ostream &) const
Print the reference.
virtual void invalidate()
Invalidate.
virtual double getReal()
Return real value.
virtual T evaluate() const
Evaluate.
The base class for all OPAL objects.
Object * find(const std::string &name)
Find entry.
static OpalData * getInstance()
Object attribute with a `‘deferred’' array value.
Object attribute with a constant scalar value.