45 #include <boost/regex.hpp>
47 using namespace Expressions;
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 "The variable '" + obj->
getOpalName() +
"' isn't of type REAL, STRING or BOOL");
85 namespace Attributes {
103 if(dynamic_cast<Bool *>(&attr.
getHandler())) {
110 throw OpalException(
"Attributes::getBool()",
"Attribute \"" +
111 attr.
getName() +
"\" is not logical.");
121 if(dynamic_cast<const Bool *>(&attr.
getHandler())) {
128 throw OpalException(
"Attributes::setBool()",
"Attribute \"" +
129 attr.
getName() +
"\" is not logical.");
146 return value->evaluate();
148 throw OpalException(
"Attributes::getBoolArray()",
"Attribute \"" +
149 attr.
getName() +
"\" is not a logical array.");
152 return std::vector<bool>();
158 if(dynamic_cast<const BoolArray *>(&attr.
getHandler())) {
163 throw OpalException(
"Attributes::setBoolArray()",
"Attribute \"" +
164 attr.
getName() +
"\" is not a logical array");
182 return place->evaluate();
184 throw OpalException(
"Attributes::getPlace()",
"Attribute \"" +
185 attr.
getName() +
"\" is not a place reference.");
194 if(dynamic_cast<const Place *>(&attr.
getHandler())) {
197 throw OpalException(
"Attributes::setPlace()",
"Attribute \"" +
198 attr.
getName() +
"\" is not a place reference.");
216 return range->evaluate();
218 throw OpalException(
"Attributes::getRange()",
"Attribute \"" +
219 attr.
getName() +
"\" is not a range reference.");
228 if(dynamic_cast<const Range *>(&attr.
getHandler())) {
231 throw OpalException(
"Attributes::setRange()",
"Attribute \"" +
232 attr.
getName() +
"\" is not a range reference.");
246 makeReal(
const std::string &
name,
const std::string &help,
double initial) {
255 if(dynamic_cast<Real *>(&attr.
getHandler())) {
262 throw OpalException(
"Attributes::getReal()",
"Attribute \"" +
263 attr.
getName() +
"\" is not real.");
273 if(dynamic_cast<const Real *>(&attr.
getHandler())) {
280 throw OpalException(
"Attributes::setReal()",
"Attribute \"" +
281 attr.
getName() +
"\" is not real.");
296 if(dynamic_cast<RealArray *>(&attr.
getHandler())) {
300 throw OpalException(
"Attributes::getRealArray()",
"Attribute \"" +
301 attr.
getName() +
"\" is not a real array.");
304 return std::vector<double>();
310 if(dynamic_cast<const RealArray *>(&attr.
getHandler())) {
315 throw OpalException(
"Attributes::setRealArray()",
"Attribute \"" +
316 attr.
getName() +
"\" is not a real array.");
338 makeString(
const std::string &
name,
const std::string &help,
const std::string &initial) {
348 || dynamic_cast<UpperCaseString *>(&attr.
getHandler())
349 || dynamic_cast<PredefinedString *>(&attr.
getHandler())) {
356 throw OpalException(
"Attributes::getString()",
"Attribute \"" +
357 attr.
getName() +
"\" is not string.");
362 boost::regex variableRE(
"\\$\\{(.*?)\\}");
365 std::string exprDeref;
366 std::string::const_iterator start = expr.begin();
367 std::string::const_iterator
end = expr.end();
369 while (boost::regex_search(start, end, what, variableRE, boost::match_default)) {
370 exprDeref += std::string(start, what[0].first);
371 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
373 if (
Object *obj = opal->find(variable)) {
374 exprDeref += ::stringifyVariable(obj);
377 "Can't find variable '" + variable +
"' in string \"" + expr +
"\"");
380 start = what[0].second;
382 exprDeref += std::string(start, end);
386 return std::string();
393 if(dynamic_cast<const String *>(&attr.
getHandler())) {
400 throw OpalException(
"Attributes::setString()",
"Attribute \"" +
401 attr.
getName() +
"\" is not a string.");
410 const std::string &help,
411 const std::initializer_list<std::string>& predefinedStrings) {
418 const std::string &help,
419 const std::initializer_list<std::string>& predefinedStrings,
420 const std::string &initial) {
429 if(dynamic_cast<const PredefinedString *>(&attr.
getHandler())) {
434 value.
set(upperCaseVal);
436 throw OpalException(
"Attributes::setPredefinedString()",
"Attribute \"" +
437 attr.
getName() +
"\" is not a supported string.");
458 if(dynamic_cast<const UpperCaseString *>(&attr.
getHandler())) {
465 throw OpalException(
"Attributes::setUpperCaseString()",
"Attribute \"" +
466 attr.
getName() +
"\" is not an upper case string.");
481 if(dynamic_cast<StringArray *>(&attr.
getHandler())
482 || dynamic_cast<UpperCaseStringArray *>(&attr.
getHandler())) {
485 boost::regex variableRE(
"\\$\\{(.*?)\\}");
489 for (
auto expr: value) {
490 std::string exprDeref;
491 std::string::const_iterator start = expr.begin();
492 std::string::const_iterator
end = expr.end();
494 while (boost::regex_search(start, end, what, variableRE, boost::match_default)) {
495 exprDeref += std::string(start, what[0].first);
496 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
498 if (
Object *obj = opal->find(variable)) {
499 std::ostringstream value;
503 exprDeref += value.str();
505 exprDeref += std::string(what[0].first, what[0].second);
508 start = what[0].second;
510 expr = exprDeref + std::string(start, end);
515 throw OpalException(
"Attributes::getStringArray()",
"Attribute \"" +
516 attr.
getName() +
"\" is not a string array.");
519 return std::vector<std::string>();
525 if(dynamic_cast<const StringArray *>(&attr.
getHandler())) {
529 throw OpalException(
"Attributes::setStringArray()",
"Attribute \"" +
530 attr.
getName() +
"\" is not a string array.");
541 if(dynamic_cast<const UpperCaseStringArray *>(&attr.
getHandler())) {
543 std::vector<std::string> uppercase(value.size());
544 std::transform(value.begin(), value.end(), uppercase.begin(),
545 [](std::string val) -> std::string {
return Util::toUpper(val); });
548 throw OpalException(
"Attributes::setUpperCaseStringArray()",
"Attribute \"" +
549 attr.
getName() +
"\" is not an upper case string array.");
566 return row->evaluate();
568 throw OpalException(
"Attributes::getTableRow()",
"Attribute \"" +
570 "\" is not a table row reference.");
579 if(dynamic_cast<const TableRow *>(&attr.
getHandler())) {
582 throw OpalException(
"Attributes::setTableRow()",
"Attribute \"" +
584 "\" is not a table row reference.");
600 if(dynamic_cast<TokenList *>(&attr.
getHandler())) {
603 throw OpalException(
"Attributes::getTokenList()",
"Attribute \"" +
604 attr.
getName() +
"\" is not a token list.");
607 return std::list<Token>();
613 if(dynamic_cast<const TokenList *>(&attr.
getHandler())) {
614 attr.
set(
new SValue<std::list<Token> >(val));
617 "\" is not a token list.");
633 if(dynamic_cast<TokenListArray *>(&attr.
getHandler())) {
636 throw OpalException(
"Attributes::getTokenListArray()",
"Attribute \"" +
637 attr.
getName() +
"\" is not a token list array.");
640 return std::vector<std::list<Token> >();
647 const std::vector<std::list<Token> > &value) {
649 attr.
set(
new AValue<std::list<Token> >(value));
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
static OpalData * getInstance()
Attribute makeTokenListArray(const std::string &name, const std::string &help)
Make token list attribute.
void setString(Attribute &attr, const std::string &val)
Set string value.
Parser for an attribute of type table row reference.
Representation of a range within a beam line or sequence.
void setRealArray(Attribute &attr, const std::vector< double > &value)
Set array value.
void setTokenList(Attribute &attr, const std::list< Token > &val)
Set token list value.
The base class for all OPAL objects.
TableRowRep getTableRow(const Attribute &attr)
Get table row value.
Attribute makeReference(const std::string &name, const std::string &help)
Create a reference attribute.
void setReal(Attribute &attr, double val)
Set real value.
GNU GENERAL PUBLIC LICENSE June Free Software Inc Temple Place
Attribute makeTokenList(const std::string &name, const std::string &help)
Make token list attribute.
void setTableRow(Attribute &attr, const TableRowRep &rep)
Set table row value.
std::string getString(const Attribute &attr)
Get string value.
void setBoolArray(Attribute &attr, const std::vector< bool > &value)
Set logical array value.
Parser for an attribute of type string array.
void set(AttributeBase *newBase)
Define new value.
Object attribute with a constant array value.
Parser for an attribute of type real array.
Parser for an attribute of type token list.
AttributeHandler & getHandler() const
Return a reference to the parser.
An attribute defined as a reference to a scalar.
void setStringArray(Attribute &attr, const std::vector< std::string > &value)
Set string array value.
virtual void printValue(std::ostream &os) const
Print its value.
const std::string & getName() const
Return the attribute name.
PlaceRep getPlace(const Attribute &attr)
Get place value.
Parser for an attribute of type string array.
Parser for an attribute of type string.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
virtual void set(const T &) const
Store new value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::string toUpper(const std::string &str)
Parser for an attribute of type attribute reference.
Attribute makeRange(const std::string &name, const std::string &help)
Create a range attribute.
Parser for an attribute of type logical array.
bool getBool(const Attribute &attr)
Return logical value.
virtual std::string getString() const
Return string value.
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
void setUpperCaseString(Attribute &attr, const std::string &val)
Set uppercase string value.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated place
std::list< Token > getTokenList(const Attribute &attr)
Return token list value.
Representation of a place within a beam line or sequence.
The base class for all OPAL exceptions.
Attribute makeUpperCaseStringArray(const std::string &name, const std::string &help)
Make uppercase string array attribute.
Parser for an attribute of type real.
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Attribute makePlace(const std::string &name, const std::string &help)
Create a place attribute.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
void setPlace(Attribute &attr, const PlaceRep &rep)
Set place value.
Object attribute with a constant scalar value.
virtual double getReal() const
Return real value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
void setUpperCaseStringArray(Attribute &attr, const std::vector< std::string > &value)
Set upper case string array value.
Parser for an attribute of type range definition.
void setPredefinedString(Attribute &attr, const std::string &val)
Set predefined string value.
const std::string & getOpalName() const
Return object name.
Abstract base class for attribute values of different types.
void setBool(Attribute &attr, bool val)
Set logical value.
virtual T evaluate()
Evaluate.
Representation of a table row reference.
The base class for all OPAL value definitions.
void setTokenListArray(Attribute &attr, const std::vector< std::list< Token > > &value)
Set token list array value.
virtual bool getBool() const
Return logical value.
double getReal(const Attribute &attr)
Return real value.
Parser for attribute of type logical.
bool isBaseAllocated() const
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
constexpr double e
The value of .
AttributeBase & getBase() const
Return reference to polymorphic value.
Parser for an attribute of type token list array.
Object attribute with a ``deferred'' array value.
Attribute makeUpperCaseString(const std::string &name, const std::string &help)
Make uppercase string attribute.
Parser for an attribute of type string.
std::vector< std::list< Token > > getTokenListArray(const Attribute &attr)
Return token list array value.
RangeRep getRange(const Attribute &attr)
Get range value.
virtual T evaluate() const
Evaluate.
void setRange(Attribute &attr, const RangeRep &rep)
Set range value.
Attribute makeTableRow(const std::string &name, const std::string &help)
Create a table row attribute.
Parser for an attribute of type string.
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
A representation of an Object attribute.