39 itsSequence(seq), okFlag(true), itsLine()
48 if (stat.
keyword(
"ENDSEQUENCE")) {
95 if (i->fromPosition != 0 &&
98 j != i->itsList.end(); ++j) {
99 (*j)->itsPosition += i->fromPosition->itsPosition;
112 "Circular \"FROM\" clauses.");
123 i->fromPosition = &(*pos);
126 "Not all FROM clauses resolved.");
137 if (
ref ==
"ENTRY") {
139 }
else if (
ref ==
"CENTRE" ||
ref.empty()) {
141 }
else if (
ref ==
"EXIT") {
144 throw OpalException(
"SequenceParser::findNeighbourPositions()",
145 "Unknown reference flag \"" +
ref +
146 "\" in <sequence> \"" +
158 std::string
name = i->getElement()->getName();
163 i->itsPosition += length / 2.0;
165 i->itsPosition += length;
173 std::string
name = j->getElement()->getName();
178 i->itsPosition += length;
180 i->itsPosition += length / 2.0;
186 ref.fromPosition = &(*j);
198 ref.fromPosition = &(*j);
210 ref.fromPosition = &(*j);
265 throw ParseError(
"SequenceParser::parseMember()",
266 "You cannot redefine \"" + objName +
267 "\" within the sequence of the same name.");
269 throw ParseError(
"SequenceParser::parseMember()",
270 "You cannot refer to \"" + objName +
271 "\" within the sequence of the same name.");
273 throw ParseError(
"SequenceParser::parseMember()",
274 "You cannot redefine \"" + objName +
275 "\" within a sequence.");
281 copy = line->copy(objName);
283 copy = obj->
clone(objName);
309 throw ParseError(
"SequenceParser::parseMember()",
"Object \"" +
310 objName +
"\" is not an element.");
313 throw ParseError(
"SequenceParser::parseMember()",
314 "Element class name \"" + clsName +
"\" is unknown.");
322 double position = 0.0;
323 std::string fromName;
333 flag |= (flag & 0x0001) ? 0x0008 : 0x0001;
334 }
else if (
name ==
"DRIFT") {
337 flag |= (flag & 0x0002) ? 0x0008 : 0x0002;
338 }
else if (
name ==
"FROM") {
343 }
else if (stat.
keyword(
"E")) {
346 throw ParseError(
"SequenceParser::parsePosition()",
347 "Expected 'S' or 'E'.");
351 (stat,
"Expected <name>, \"#S\", or \"#E\".");
353 flag |= (flag & 0x0004) ? 0x0008 : 0x0004;
354 }
else if (defined) {
358 attr->parse(stat,
true);
360 attr->parse(stat,
false);
362 throw ParseError(
"SequenceParser::parsePosition()",
363 "Delimiter \"=\" or \":=\" expected.");
366 throw ParseError(
"SequenceParser::parsePosition()",
368 "\" has no attribute \"" +
name +
"\".");
371 throw ParseError(
"SequenceParser::parsePosition()",
372 "Overriding attributes not permitted here.");
402 if (fromName ==
"PREVIOUS") {
405 }
else if (fromName ==
"NEXT") {
408 }
else if (fromName ==
"#S") {
411 }
else if (fromName ==
"#E") {
421 if (i->fromName == fromName) {
423 i->itsList.push_back(&member);
430 ref.fromName = fromName;
431 ref.itsList.push_back(&member);
438 throw ParseError(
"SequenceParser:parsePosition()",
439 "Conflicting keywords.");
std::string parseString(Statement &, const char msg[])
Parse string value.
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
double parseRealConst(Statement &)
Parse real constant.
double getReal(const Attribute &attr)
Return real value.
std::string getString(const Attribute &attr)
Get string value.
std::string::iterator iterator
boost::function< boost::tuple< double, bool >(arguments_t)> type
A representation of an Object attribute.
The base class for all OPAL beam lines and sequences.
virtual double getLength() const =0
Return element length.
static Element * find(const std::string &name)
Find named Element.
ReferenceType
Reference for element positioning.
The base class for all OPAL objects.
virtual Object * clone(const std::string &name)=0
Return a clone.
virtual Object * makeInstance(const std::string &name, Statement &, const Parser *)
Macro handler function.
const std::string & getOpalName() const
Return object name.
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
void makeDirty(Object *object)
Invalidate expressions.
static OpalData * getInstance()
void define(Object *newObject)
Define a new object.
virtual ElementBase * copyStructure()
Make a structural copy.
void setElement(ElementBase *)
Set the element pointer.
void setReflectionFlag(bool flag) const
Set reflection flag.
Reference-counted pointer.
Interface for statements.
bool keyword(const char *s)
Test for keyword.
bool delimiter(char c)
Test for delimiter.
void start()
Return to start.
void insertDrifts(TLine &line)
TLine::iterator findNamedPosition(TLine &, const std::string &) const
void storeLine(TLine &line)
Store sequence line.
void addEndMarkers(TLine &line) const
MemberType itsType
Type word.
Pointer< Element > OpalElement
double itsPosition
The position attribute ("AT" or "DRIFT").
PositionType itsFlag
Flag word.
void findFromPositions() const
void fillPositions() const
void parseMember(Statement &) const
virtual ~SequenceParser()
void findNeighbourPositions() const
virtual void parse(Statement &) const
Parse sequence member.
void parsePosition(Statement &, Object &, bool defined) const
virtual void parseEnd(Statement &) const
Check for end of statement.
virtual Object * find(const std::string &) const
Find object by name in the main directory.
void stop() const
Set stop flag.
The base class for all OPAL exceptions.