52 std::string stringifyVariable(
Object *obj) {
56 std::ostringstream valueStream;
60 return valueStream.str();
66 return valueStream.str();
71 bool boolean = value->
getBool();
72 valueStream << std::boolalpha << boolean;
79 "The variable '" + obj->
getOpalName() +
"' isn't of type REAL, STRING or BOOL");
112 throw OpalException(
"Attributes::getBool()",
"Attribute \"" +
113 attr.
getName() +
"\" is not logical.");
130 throw OpalException(
"Attributes::setBool()",
"Attribute \"" +
131 attr.
getName() +
"\" is not logical.");
148 return value->evaluate();
150 throw OpalException(
"Attributes::getBoolArray()",
"Attribute \"" +
151 attr.
getName() +
"\" is not a logical array.");
154 return std::vector<bool>();
165 throw OpalException(
"Attributes::setBoolArray()",
"Attribute \"" +
166 attr.
getName() +
"\" is not a logical array");
184 return place->evaluate();
186 throw OpalException(
"Attributes::getPlace()",
"Attribute \"" +
187 attr.
getName() +
"\" is not a place reference.");
199 throw OpalException(
"Attributes::setPlace()",
"Attribute \"" +
200 attr.
getName() +
"\" is not a place reference.");
218 return range->evaluate();
220 throw OpalException(
"Attributes::getRange()",
"Attribute \"" +
221 attr.
getName() +
"\" is not a range reference.");
233 throw OpalException(
"Attributes::setRange()",
"Attribute \"" +
234 attr.
getName() +
"\" is not a range reference.");
248 makeReal(
const std::string &
name,
const std::string &help,
double initial) {
264 throw OpalException(
"Attributes::getReal()",
"Attribute \"" +
265 attr.
getName() +
"\" is not real.");
282 throw OpalException(
"Attributes::setReal()",
"Attribute \"" +
283 attr.
getName() +
"\" is not real.");
302 throw OpalException(
"Attributes::getRealArray()",
"Attribute \"" +
303 attr.
getName() +
"\" is not a real array.");
306 return std::vector<double>();
317 throw OpalException(
"Attributes::setRealArray()",
"Attribute \"" +
318 attr.
getName() +
"\" is not a real array.");
340 makeString(
const std::string &
name,
const std::string &help,
const std::string &initial) {
358 throw OpalException(
"Attributes::getString()",
"Attribute \"" +
359 attr.
getName() +
"\" is not string.");
364 std::regex variableRE(
"\\$\\{(.*?)\\}");
367 std::string exprDeref;
368 std::string::const_iterator start = expr.begin();
369 std::string::const_iterator
end = expr.end();
371 while (std::regex_search(start,
end, what, variableRE, std::regex_constants::match_default)) {
372 exprDeref += std::string(start, what[0].first);
373 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
375 if (
Object *obj = opal->find(variable)) {
376 exprDeref += ::stringifyVariable(obj);
379 "Can't find variable '" + variable +
"' in string \"" + expr +
"\"");
382 start = what[0].second;
384 exprDeref += std::string(start,
end);
388 return std::string();
402 throw OpalException(
"Attributes::setString()",
"Attribute \"" +
403 attr.
getName() +
"\" is not a string.");
412 const std::string &help,
413 const std::initializer_list<std::string>& predefinedStrings) {
420 const std::string &help,
421 const std::initializer_list<std::string>& predefinedStrings,
422 const std::string &initial) {
436 value.
set(upperCaseVal);
438 throw OpalException(
"Attributes::setPredefinedString()",
"Attribute \"" +
439 attr.
getName() +
"\" is not a supported string.");
467 throw OpalException(
"Attributes::setUpperCaseString()",
"Attribute \"" +
468 attr.
getName() +
"\" is not an upper case string.");
487 std::regex variableRE(
"\\$\\{(.*?)\\}");
491 for (
auto expr: value) {
492 std::string exprDeref;
493 std::string::const_iterator start = expr.begin();
494 std::string::const_iterator
end = expr.end();
496 while (std::regex_search(start,
end, what, variableRE, std::regex_constants::match_default)) {
497 exprDeref += std::string(start, what[0].first);
498 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
500 if (
Object *obj = opal->find(variable)) {
501 std::ostringstream value;
505 exprDeref += value.str();
507 exprDeref += std::string(what[0].first, what[0].second);
510 start = what[0].second;
512 expr = exprDeref + std::string(start,
end);
517 throw OpalException(
"Attributes::getStringArray()",
"Attribute \"" +
518 attr.
getName() +
"\" is not a string array.");
521 return std::vector<std::string>();
531 throw OpalException(
"Attributes::setStringArray()",
"Attribute \"" +
532 attr.
getName() +
"\" is not a string array.");
545 std::vector<std::string> uppercase(value.size());
546 std::transform(value.begin(), value.end(), uppercase.begin(),
547 [](std::string val) -> std::string { return Util::toUpper(val); });
550 throw OpalException(
"Attributes::setUpperCaseStringArray()",
"Attribute \"" +
551 attr.
getName() +
"\" is not an upper case string array.");
568 return row->evaluate();
570 throw OpalException(
"Attributes::getTableRow()",
"Attribute \"" +
572 "\" is not a table row reference.");
584 throw OpalException(
"Attributes::setTableRow()",
"Attribute \"" +
586 "\" is not a table row reference.");
605 throw OpalException(
"Attributes::getTokenList()",
"Attribute \"" +
606 attr.
getName() +
"\" is not a token list.");
609 return std::list<Token>();
616 attr.
set(
new SValue<std::list<Token> >(val));
619 "\" is not a token list.");
638 throw OpalException(
"Attributes::getTokenListArray()",
"Attribute \"" +
639 attr.
getName() +
"\" is not a token list array.");
642 return std::vector<std::list<Token> >();
649 const std::vector<std::list<Token> > &value) {
651 attr.
set(
new AValue<std::list<Token> >(value));
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
Representation objects and parsers for attribute expressions.
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.
std::string toUpper(const std::string &str)
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.
Abstract base class for attribute values of different types.
An attribute defined as a reference to a scalar.
virtual void set(const T &) const
Store new value.
virtual T evaluate() const
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.
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.
Parser for attribute of type logical.
Parser for an attribute of type logical array.
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.
Parser for an attribute of type real array.
Parser for an attribute of type attribute reference.
Parser for an attribute of type string.
Parser for an attribute of type string array.
Parser for an attribute of type table row reference.
Parser for an attribute of type token list.
Parser for an attribute of type token list array.
Parser for an attribute of type string.
Parser for an attribute of type string array.
Object attribute with a `‘deferred’' array value.
Object attribute with a constant array value.
Object attribute with a constant scalar value.
The base class for all OPAL exceptions.
virtual void printValue(std::ostream &os) const
Print its value.