50 std::string stringifyVariable(
Object* obj) {
54 std::ostringstream valueStream;
58 return valueStream.str();
64 return valueStream.str();
69 bool boolean = value->
getBool();
70 valueStream << std::boolalpha << boolean;
77 "Attributes::stringifyVariable",
78 "The variable '" + obj->
getOpalName() +
"' isn't of type REAL, STRING or BOOL");
110 "Attributes::getBool()",
111 "Attribute \"" + attr.
getName() +
"\" is not logical.");
129 "Attributes::setBool()",
130 "Attribute \"" + attr.
getName() +
"\" is not logical.");
144 return value->evaluate();
147 "Attributes::getBoolArray()",
148 "Attribute \"" + attr.
getName() +
"\" is not a logical array.");
151 return std::vector<bool>();
162 "Attributes::setBoolArray()",
163 "Attribute \"" + attr.
getName() +
"\" is not a logical array");
177 return place->evaluate();
180 "Attributes::getPlace()",
181 "Attribute \"" + attr.
getName() +
"\" is not a place reference.");
193 "Attributes::setPlace()",
194 "Attribute \"" + attr.
getName() +
"\" is not a place reference.");
208 return range->evaluate();
211 "Attributes::getRange()",
212 "Attribute \"" + attr.
getName() +
"\" is not a range reference.");
224 "Attributes::setRange()",
225 "Attribute \"" + attr.
getName() +
"\" is not a range reference.");
252 "Attributes::getReal()",
253 "Attribute \"" + attr.
getName() +
"\" is not real.");
271 "Attributes::setReal()",
"Attribute \"" + attr.
getName() +
"\" is not real.");
289 "Attributes::getRealArray()",
290 "Attribute \"" + attr.
getName() +
"\" is not a real array.");
293 return std::vector<double>();
304 "Attributes::setRealArray()",
305 "Attribute \"" + attr.
getName() +
"\" is not a real array.");
324 const std::string& name,
const std::string& help,
const std::string& initial) {
343 "Attributes::getString()",
344 "Attribute \"" + attr.
getName() +
"\" is not string.");
349 std::regex variableRE(
"\\$\\{(.*?)\\}");
352 std::string exprDeref;
353 std::string::const_iterator start = expr.begin();
354 std::string::const_iterator end = expr.end();
356 while (std::regex_search(
357 start, end, what, variableRE, std::regex_constants::match_default)) {
358 exprDeref += std::string(start, what[0].first);
359 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
361 if (
Object* obj = opal->find(variable)) {
362 exprDeref += ::stringifyVariable(obj);
365 "Attributes::getString",
366 "Can't find variable '" + variable +
"' in string \"" + expr +
"\"");
369 start = what[0].second;
371 exprDeref += std::string(start, end);
375 return std::string();
390 "Attributes::setString()",
391 "Attribute \"" + attr.
getName() +
"\" is not a string.");
399 const std::string& name,
const std::string& help,
400 const std::initializer_list<std::string>& predefinedStrings) {
405 const std::string& name,
const std::string& help,
406 const std::initializer_list<std::string>& predefinedStrings,
407 const std::string& initial) {
422 value.
set(upperCaseVal);
425 "Attributes::setPredefinedString()",
426 "Attribute \"" + attr.
getName() +
"\" is not a supported string.");
438 const std::string& name,
const std::string& help,
const std::string& initial) {
454 "Attributes::setUpperCaseString()",
455 "Attribute \"" + attr.
getName() +
"\" is not an upper case string.");
472 std::regex variableRE(
"\\$\\{(.*?)\\}");
475 std::vector<std::string> value =
477 for (
auto expr : value) {
478 std::string exprDeref;
479 std::string::const_iterator start = expr.begin();
480 std::string::const_iterator end = expr.end();
482 while (std::regex_search(
483 start, end, what, variableRE, std::regex_constants::match_default)) {
484 exprDeref += std::string(start, what[0].first);
485 std::string variable =
488 if (
Object* obj = opal->find(variable)) {
489 std::ostringstream value;
493 exprDeref += value.str();
495 exprDeref += std::string(what[0].first, what[0].second);
498 start = what[0].second;
500 expr = exprDeref + std::string(start, end);
506 "Attributes::getStringArray()",
507 "Attribute \"" + attr.
getName() +
"\" is not a string array.");
510 return std::vector<std::string>();
520 "Attributes::setStringArray()",
521 "Attribute \"" + attr.
getName() +
"\" is not a string array.");
534 std::vector<std::string> uppercase(value.size());
536 value.begin(), value.end(), uppercase.begin(),
537 [](std::string val) -> std::string {
538 return Util::toUpper(val);
543 "Attributes::setUpperCaseStringArray()",
544 "Attribute \"" + attr.
getName() +
"\" is not an upper case string array.");
558 return row->evaluate();
561 "Attributes::getTableRow()",
562 "Attribute \"" + attr.
getName() +
"\" is not a table row reference.");
574 "Attributes::setTableRow()",
575 "Attribute \"" + attr.
getName() +
"\" is not a table row reference.");
593 "Attributes::getTokenList()",
594 "Attribute \"" + attr.
getName() +
"\" is not a token list.");
597 return std::list<Token>();
603 attr.
set(
new SValue<std::list<Token> >(val));
606 "Attributes::setTokenList()",
607 "Attribute \"" + attr.
getName() +
"\" is not a token list.");
625 "Attributes::getTokenListArray()",
626 "Attribute \"" + attr.
getName() +
"\" is not a token list array.");
629 return std::vector<std::list<Token> >();
635 attr.
set(
new AValue<std::list<Token> >(value));
Abstract base class for attribute values of different types.
A representation of an Object attribute.
AttributeBase & getBase() const
Return reference to polymorphic value.
const std::string & getName() const
Return the attribute name.
void set(AttributeBase *newBase)
Define new value.
bool isBaseAllocated() const
AttributeHandler & getHandler() const
Return a reference to the parser.
Parser for an attribute of type logical array.
Parser for attribute of type logical.
Parser for an attribute of type place reference.
Parser for an attribute of type string.
Parser for an attribute of type range definition.
Parser for an attribute of type real array.
Parser for an attribute of type real.
Parser for an attribute of type attribute reference.
Parser for an attribute of type string array.
Parser for an attribute of type string.
Parser for an attribute of type table row reference.
Parser for an attribute of type token list array.
Parser for an attribute of type token list.
Parser for an attribute of type string array.
Parser for an attribute of type string.
Object attribute with a `‘deferred’' array value.
Object attribute with a constant array value.
An attribute defined as a reference to a scalar.
virtual void set(const T &) const
Store new value.
virtual T evaluate() const
Evaluate.
Object attribute with a constant scalar value.
virtual T evaluate()
Evaluate.
The base class for all OPAL objects.
const std::string & getOpalName() const
Return object name.
static OpalData * getInstance()
Representation of a place within a beam line or sequence.
Representation of a range within a beam line or sequence.
virtual void printValue(std::ostream &os) const
Print its value.
Representation of a table row reference.
The base class for all OPAL value definitions.
virtual double getReal() const
Return real value.
virtual bool getBool() const
Return logical value.
virtual std::string getString() const
Return string value.
A collection of routines to construct object Attributes and retrieve.
Attribute makePlace(const std::string &name, const std::string &help)
Create a place attribute.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
void setBoolArray(Attribute &attr, const std::vector< bool > &value)
Set logical array value.
void setUpperCaseStringArray(Attribute &attr, const std::vector< std::string > &value)
Set upper case string array value.
Attribute makeUpperCaseStringArray(const std::string &name, const std::string &help)
Make uppercase string array attribute.
void setRealArray(Attribute &attr, const std::vector< double > &value)
Set array value.
void setBool(Attribute &attr, bool val)
Set logical value.
std::list< Token > getTokenList(const Attribute &attr)
Return token list value.
void setTableRow(Attribute &attr, const TableRowRep &rep)
Set table row value.
Attribute makeUpperCaseString(const std::string &name, const std::string &help)
Make uppercase string attribute.
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
void setUpperCaseString(Attribute &attr, const std::string &val)
Set uppercase string value.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Attribute makeTableRow(const std::string &name, const std::string &help)
Create a table row attribute.
Attribute makeReference(const std::string &name, const std::string &help)
Create a reference attribute.
void setRange(Attribute &attr, const RangeRep &rep)
Set range value.
void setString(Attribute &attr, const std::string &val)
Set string value.
Attribute makeRange(const std::string &name, const std::string &help)
Create a range attribute.
Attribute makeTokenListArray(const std::string &name, const std::string &help)
Make token list attribute.
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
bool getBool(const Attribute &attr)
Return logical value.
TableRowRep getTableRow(const Attribute &attr)
Get table row value.
Attribute makeTokenList(const std::string &name, const std::string &help)
Make token list attribute.
void setTokenListArray(Attribute &attr, const std::vector< std::list< Token > > &value)
Set token list array value.
void setReal(Attribute &attr, double val)
Set real value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
void setStringArray(Attribute &attr, const std::vector< std::string > &value)
Set string array value.
PlaceRep getPlace(const Attribute &attr)
Get place value.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
void setPredefinedString(Attribute &attr, const std::string &val)
Set predefined string value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
std::vector< std::list< Token > > getTokenListArray(const Attribute &attr)
Return token list array value.
void setTokenList(Attribute &attr, const std::list< Token > &val)
Set token list value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
RangeRep getRange(const Attribute &attr)
Get range value.
void setPlace(Attribute &attr, const PlaceRep &rep)
Set place value.
Representation objects and parsers for attribute expressions.
std::string toUpper(const std::string &str)