OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
EditSelect.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: EditSelect.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: EditSelect
10 // The class for the OPAL sequence editor SELECT command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:38 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Editor/EditSelect.h"
23 #include "Attributes/Attributes.h"
24 #include "Editor/Edit.h"
26 #include "Utilities/Options.h"
27 #include <iostream>
28 
29 
30 // Class EditSelect
31 // ------------------------------------------------------------------------
32 
33 // The attributes of class EditSelect.
34 namespace {
35  enum {
36  RANGE, // The range to be considered.
37  CLASS, // The class to be considered.
38  TYPE, // The element TYPE keyword.
39  PATTERN, // The regular expression to be matched.
40  FULL, // Flag for full selection.
41  CLEAR, // Flag for full de-selection.
42  SIZE
43  };
44 }
45 
46 
48  Editor(SIZE, "SELECT",
49  "The \"SELECT\" sub-command marks element(s) in the sequence "
50  "to be affected by subsequent edit sub-commands") {
52  ("RANGE", "Range to be considered for selection");
54  ("CLASS", "Class of elements to be selected within range");
56  ("TYPE", "The element \"TYPE\" attribute.");
58  ("PATTERN", "Regular expression for name matching");
60  ("FULL", "If true, all element are selected");
62  ("CLEAR", "If true, all selections are cleared");
63 
65 }
66 
67 
68 EditSelect::EditSelect(const std::string &name, EditSelect *parent):
69  Editor(name, parent)
70 {}
71 
72 
74 {}
75 
76 
77 EditSelect *EditSelect::clone(const std::string &name) {
78  return new EditSelect(name, this);
79 }
80 
81 
83  if(itsAttr[FULL] && Attributes::getBool(itsAttr[FULL])) {
85 
86  if(Options::info) {
87  std::cerr << "\nAll elements selected.\n";
88  }
89  } else if(itsAttr[CLEAR] && Attributes::getBool(itsAttr[CLEAR])) {
91 
92  if(Options::info) {
93  std::cerr << "\nAll elements de-selected.\n";
94  }
95  } else {
96  // Now set select flags according to range, class and pattern.
97  const RangeRep &range = Attributes::getRange(itsAttr[RANGE]);
98  const std::string &clsName = Attributes::getString(itsAttr[CLASS]);
99  const std::string &typName = Attributes::getString(itsAttr[TYPE]);
100  const std::string &pattern = Attributes::getString(itsAttr[PATTERN]);
101  int count = Edit::block->select(range, clsName, typName, pattern);
102 
103  // inform user about number of selections done
104  if(Options::info) {
105  if(count == 0) {
106  std::cerr << "\nNo elements";
107  } else if(count == 1) {
108  std::cerr << "\n1 element";
109  } else {
110  std::cerr << '\n' << count << " elements";
111  }
112 
113  std::cerr << " selected.\n";
114  }
115  }
116 
117  std::cerr << std::endl;
118 }
RangeRep getRange(const Attribute &attr)
Get range value.
Definition: Attributes.cpp:177
The sequence editor SELECT command.
Definition: EditSelect.h:28
Attribute makeRange(const std::string &name, const std::string &help)
Create a range attribute.
Definition: Attributes.cpp:171
void selectClear()
Clear all selection flags.
Definition: Edit.cpp:323
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
bool info
Info flag.
Definition: Options.cpp:8
void selectFull()
Set all selection flags.
Definition: Edit.cpp:329
The base class for all OPAL sequence editor commands.
Definition: Editor.h:31
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
static Edit * block
Pointer to the edit data.
Definition: Edit.h:134
Representation of a range within a beam line or sequence.
Definition: RangeRep.h:34
virtual void execute()
Execute the command.
Definition: EditSelect.cpp:82
virtual ~EditSelect()
Definition: EditSelect.cpp:73
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
virtual EditSelect * clone(const std::string &name)
Make clone.
Definition: EditSelect.cpp:77
int select(const RangeRep &rng, const std::string &cls, const std::string &typ, const std::string &patt)
Select elements in the edit sequence.
Definition: Edit.cpp:315
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
EditSelect()
Exemplar constructor.
Definition: EditSelect.cpp:47
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307