42 #include <boost/regex.hpp>
45 using namespace Expressions;
51 namespace Attributes {
77 attr.
getName() +
"\" is not logical.");
86 if(dynamic_cast<const Bool *>(&attr.
getHandler())) {
94 attr.
getName() +
"\" is not logical.");
111 return value->evaluate();
113 throw OpalException(
"Attributes::getBoolArray()",
"Attribute \"" +
114 attr.
getName() +
"\" is not a logical array.");
117 return std::vector<bool>();
123 if(dynamic_cast<const BoolArray *>(&attr.
getHandler())) {
128 throw OpalException(
"Attributes::setBoolArray()",
"Attribute \"" +
129 attr.
getName() +
"\" is not a logical array");
147 return place->evaluate();
149 throw OpalException(
"Attributes::getPlace()",
"Attribute \"" +
150 attr.
getName() +
"\" is not a place reference.");
159 if(dynamic_cast<const Place *>(&attr.
getHandler())) {
162 throw OpalException(
"Attributes::getPlace()",
"Attribute \"" +
163 attr.
getName() +
"\" is not a place reference.");
181 return range->evaluate();
184 attr.
getName() +
"\" is not a range reference.");
193 if(dynamic_cast<const Range *>(&attr.
getHandler())) {
197 attr.
getName() +
"\" is not a range reference.");
211 makeReal(
const std::string &
name,
const std::string &help,
double initial) {
220 if(dynamic_cast<Real *>(&attr.
getHandler())) {
227 throw OpalException(
"Attributes::getReal()",
"Attribute \"" +
228 attr.
getName() +
"\" is not real.");
237 if(dynamic_cast<const Real *>(&attr.
getHandler())) {
244 throw OpalException(
"Attributes::setReal()",
"Attribute \"" +
245 attr.
getName() +
"\" is not real.");
260 if(dynamic_cast<RealArray *>(&attr.
getHandler())) {
264 throw OpalException(
"Attributes::getRealArray()",
"Attribute \"" +
265 attr.
getName() +
"\" is not a real array.");
268 return std::vector<double>();
274 if(dynamic_cast<const RealArray *>(&attr.
getHandler())) {
279 throw OpalException(
"Attributes::setRealArray()",
"Attribute \"" +
280 attr.
getName() +
"\" is not a real array.");
302 makeString(
const std::string &
name,
const std::string &help,
const std::string &initial) {
311 if(dynamic_cast<String *>(&attr.
getHandler())) {
318 throw OpalException(
"Attributes::getString()",
"Attribute \"" +
319 attr.
getName() +
"\" is not string.");
324 boost::regex variableRE(
"\\$\\{(.*?)\\}");
327 std::string exprDeref;
328 std::string::const_iterator start = expr.begin();
329 std::string::const_iterator end = expr.end();
331 while (boost::regex_search(start, end, what, variableRE, boost::match_default)) {
332 exprDeref += std::string(start, what[0].first);
333 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
335 if (
Object *obj = opal->find(variable)) {
336 std::ostringstream value;
340 exprDeref += value.str();
342 exprDeref += std::string(what[0].first, what[0].second);
345 start = what[0].second;
347 exprDeref += std::string(start, end);
351 return std::string();
357 if(dynamic_cast<const String *>(&attr.
getHandler())) {
364 throw OpalException(
"Attributes::setString()",
"Attribute \"" +
365 attr.
getName() +
"\" is not a string.");
381 if(dynamic_cast<StringArray *>(&attr.
getHandler())) {
384 boost::regex variableRE(
"\\$\\{(.*?)\\}");
388 for (
auto expr: value) {
389 std::string exprDeref;
390 std::string::const_iterator start = expr.begin();
391 std::string::const_iterator end = expr.end();
393 while (boost::regex_search(start, end, what, variableRE, boost::match_default)) {
394 exprDeref += std::string(start, what[0].first);
395 std::string variable =
Util::toUpper(std::string(what[1].first, what[1].second));
397 if (
Object *obj = opal->find(variable)) {
398 std::ostringstream value;
402 exprDeref += value.str();
404 exprDeref += std::string(what[0].first, what[0].second);
407 start = what[0].second;
409 expr = exprDeref + std::string(start, end);
414 throw OpalException(
"Attributes::getStringArray()",
"Attribute \"" +
415 attr.
getName() +
"\" is not a string array.");
418 return std::vector<std::string>();
424 if(dynamic_cast<const StringArray *>(&attr.
getHandler())) {
428 throw OpalException(
"Attributes::setStringArray()",
"Attribute \"" +
429 attr.
getName() +
"\" is not a string array.");
446 return row->evaluate();
450 "\" is not a table row reference.");
459 if(dynamic_cast<const TableRow *>(&attr.
getHandler())) {
464 "\" is not a table row reference.");
480 if(dynamic_cast<TokenList *>(&attr.
getHandler())) {
483 throw OpalException(
"Attributes::getTokenList()",
"Attribute \"" +
484 attr.
getName() +
"\" is not a token list.");
487 return std::list<Token>();
493 if(dynamic_cast<const TokenList *>(&attr.
getHandler())) {
494 attr.
set(
new SValue<std::list<Token> >(val));
497 "\" is not a token list.");
513 if(dynamic_cast<TokenListArray *>(&attr.
getHandler())) {
516 throw OpalException(
"Attributes::getTokenListArray()",
"Attribute \"" +
517 attr.
getName() +
"\" is not a token list array.");
520 return std::vector<std::list<Token> >();
527 const std::vector<std::list<Token> > &value) {
529 attr.
set(
new AValue<std::list<Token> >(value));
void setReal(Attribute &attr, double val)
Set real value.
bool isBaseAllocated() const
void setStringArray(Attribute &attr, const std::vector< std::string > &value)
Set string array value.
virtual void printValue(std::ostream &os) const
Print its value.
void set(AttributeBase *newBase)
Define new value.
Abstract base class for attribute values of different types.
RangeRep getRange(const Attribute &attr)
Get range value.
void setRange(Attribute &attr, const RangeRep &rep)
Set range value.
The base class for all OPAL exceptions.
Parser for an attribute of type token list.
void setTokenList(Attribute &attr, const std::list< Token > &val)
Set token list value.
std::list< Token > getTokenList(const Attribute &attr)
Return token list value.
Parser for an attribute of type attribute reference.
The REAL VARIABLE definition.
std::string toUpper(const std::string &str)
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
Attribute makeRange(const std::string &name, const std::string &help)
Create a range attribute.
void setString(Attribute &attr, const std::string &val)
Set string value.
Representation of a table row reference.
TableRowRep getTableRow(const Attribute &attr)
Get table row value.
Parser for attribute of type logical.
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
An attribute defined as a reference to a scalar.
bool getBool(const Attribute &attr)
Return logical value.
PlaceRep getPlace(const Attribute &attr)
Get place value.
Representation of a place within a beam line or sequence.
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
static OpalData * getInstance()
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
A representation of an Object attribute.
Parser for an attribute of type string.
void setTableRow(Attribute &attr, const TableRowRep &rep)
Set table row value.
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
virtual void set(const T &) const
Store new value.
Parser for an attribute of type table row reference.
void setBoolArray(Attribute &attr, const std::vector< bool > &value)
Set logical array value.
Object attribute with a constant array value.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Object attribute with a ``deferred'' array value.
void setRealArray(Attribute &attr, const std::vector< double > &value)
Set array value.
Parser for an attribute of type real.
Representation of a range within a beam line or sequence.
void setPlace(Attribute &attr, const PlaceRep &rep)
Set place value.
Attribute makeTableRow(const std::string &name, const std::string &help)
Create a table row attribute.
std::vector< std::list< Token > > getTokenListArray(const Attribute &attr)
Return token list array value.
Attribute makePlace(const std::string &name, const std::string &help)
Create a place attribute.
Attribute makeTokenListArray(const std::string &name, const std::string &help)
Make token list attribute.
Parser for an attribute of type place reference.
Object attribute with a constant scalar value.
The base class for all OPAL objects.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
void setBool(Attribute &attr, bool val)
Set logical value.
Parser for an attribute of type real array.
virtual T evaluate() const
Evaluate.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
AttributeHandler & getHandler() const
Return a reference to the parser.
double getReal(const Attribute &attr)
Return real value.
Parser for an attribute of type string array.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Attribute makeReference(const std::string &name, const std::string &help)
Create a reference attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
void setTokenListArray(Attribute &attr, const std::vector< std::list< Token > > &value)
Set token list array value.
Attribute makeTokenList(const std::string &name, const std::string &help)
Make token list attribute.
const std::string & getName() const
Return the attribute name.
Parser for an attribute of type token list array.
AttributeBase & getBase() const
Return reference to polymorphic value.
std::string getString(const Attribute &attr)
Get string value.
Parser for an attribute of type range definition.
Parser for an attribute of type logical array.