OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
PlaceRep.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: PlaceRep.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: PlaceRep
10 // A class used to represent a place specification.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:34 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
24 
25 
26 // Class PlaceRep
27 // ------------------------------------------------------------------------
28 
30  data(), is_selected(false) {
31  initialize();
32 }
33 
34 
36  data(rhs.data), is_selected(rhs.is_selected) {
37  initialize();
38 }
39 
40 
41 PlaceRep::PlaceRep(const std::string &def):
42  data(), is_selected(def == "SELECTED") {
43  append(def, 1);
44  initialize();
45 }
46 
47 
49 {}
50 
51 
53  data = rhs.data;
54  initialize();
55  return *this;
56 }
57 
58 
59 void PlaceRep::append(const std::string &name, int occur) {
60  data.push_back(std::make_pair(name, occur));
61 }
62 
63 
65  status = false;
66  seen = 0;
67 }
68 
69 
70 void PlaceRep::enter(const FlaggedElmPtr &fep) const {
71  const std::string &name = fep.getElement()->getName();
72  const int occur = fep.getCounter();
73 
74  if(seen < data.size() &&
75  name == data[seen].first &&
76  occur == data[seen].second) {
77  ++seen;
78  }
79 
80  if(seen == data.size()) status = true;
81 }
82 
83 
84 void PlaceRep::leave(const FlaggedElmPtr &fep) const {
85  const std::string &name = fep.getElement()->getName();
86  const int occur = fep.getCounter();
87 
88  if(seen > 0 &&
89  name == data[seen-1].first &&
90  occur == data[seen-1].second) {
91  --seen;
92  }
93 
94  if(seen < data.size()) status = false;
95 }
96 
97 
98 bool PlaceRep::isActive() const {
99  return status;
100 }
101 
102 
103 bool PlaceRep::isSelected() const {
104  return is_selected;
105 }
106 
107 
108 void PlaceRep::print(std::ostream &os) const {
109  if(data.empty()) {
110  os << "#S";
111  } else {
112  os << data[0].first;
113  if(data[0].second > 0) os << '[' << data[0].second << ']';
114 
115  for(Data::size_type i = 1; i < data.size(); ++i) {
116  os << "::" << data[i].first;
117  if(data[i].second) os << '[' << data[i].second << ']';
118  }
119  }
120 
121  return;
122 }
const std::string name
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
~PlaceRep()
Definition: PlaceRep.cpp:48
bool isActive() const
Return status.
Definition: PlaceRep.cpp:98
void print(std::ostream &os) const
Print in input format.
Definition: PlaceRep.cpp:108
bool status
Definition: PlaceRep.h:94
Data data
Definition: PlaceRep.h:88
void initialize()
Initialise data for search.
Definition: PlaceRep.cpp:64
PlaceRep()
Default constructor.
Definition: PlaceRep.cpp:29
bool is_selected
Definition: PlaceRep.h:91
void enter(const FlaggedElmPtr &) const
Enter an element or line.
Definition: PlaceRep.cpp:70
Data::size_type seen
Definition: PlaceRep.h:97
bool isSelected() const
Return select flag.
Definition: PlaceRep.cpp:103
void append(const std::string &, int occur)
Add a name/occurrence pair.
Definition: PlaceRep.cpp:59
const PlaceRep & operator=(const PlaceRep &)
Definition: PlaceRep.cpp:52
void leave(const FlaggedElmPtr &) const
Leave an element or line.
Definition: PlaceRep.cpp:84
virtual const std::string & getName() const
Get element name.
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
A section of a beam line.
Definition: FlaggedElmPtr.h:36
int getCounter() const
Get clone counter.
Definition: FlaggedElmPtr.h:96