OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
EditRemove.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: EditRemove.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: EditRemove
10 // The class for the OPAL sequence editor REMOVE command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:38 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Editor/EditRemove.h"
21 #include "Attributes/Attributes.h"
22 #include "Editor/Edit.h"
24 #include "Utilities/Options.h"
25 #include <iostream>
26 
27 
28 // Class EditRemove
29 // ------------------------------------------------------------------------
30 
31 // The attributes of class EditRemove.
32 namespace {
33  enum {
34  SELECTED, // If true, remove selected elements.
35  CLASS, // The class to be removed.
36  SIZE
37  };
38 }
39 
40 
42  Editor(SIZE, "REMOVE",
43  "The \"REMOVE\" sub-command removes element(s) from the sequence "
44  "being edited.") {
45  itsAttr[SELECTED] = Attributes::makeBool
46  ("SELECTED", "If true, all selected elements are removed");
48  ("CLASS", "Name of element class to be removed");
49 
51 }
52 
53 
54 EditRemove::EditRemove(const std::string &name, EditRemove *parent):
55  Editor(name, parent)
56 {}
57 
58 
60 {}
61 
62 
63 EditRemove *EditRemove::clone(const std::string &name) {
64  return new EditRemove(name, this);
65 }
66 
67 
69  int count = 0;
70 
71  if(Attributes::getBool(itsAttr[SELECTED])) {
72  count = Edit::block->removeMultiple();
73  } else if(itsAttr[CLASS]) {
74  const PlaceRep pos = Attributes::getPlace(itsAttr[CLASS]);
75  count = Edit::block->removeSingle(pos);
76  } else {
77  throw OpalException("EditRemove::execute()",
78  "\"class=selected\" or \"class=<name>\" "
79  "is required for \"REMOVE\".");
80  }
81 
82  if(Options::info) {
83  if(count == 0) {
84  std::cerr << "\nNo elements";
85  } else if(count == 1) {
86  std::cerr << "\n1 element";
87  } else {
88  std::cerr << '\n' << count << " elements";
89  }
90 
91  std::cerr << " removed.\n" << std::endl;
92  }
93 }
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual void execute()
Execute the command.
Definition: EditRemove.cpp:68
The sequence editor REMOVE command.
Definition: EditRemove.h:28
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
bool info
Info flag.
Definition: Options.cpp:8
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
PlaceRep getPlace(const Attribute &attr)
Get place value.
Definition: Attributes.cpp:143
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
EditRemove()
Exemplar constructor.
Definition: EditRemove.cpp:41
virtual ~EditRemove()
Definition: EditRemove.cpp:59
virtual EditRemove * clone(const std::string &name)
Make clone.
Definition: EditRemove.cpp:63
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
static Edit * block
Pointer to the edit data.
Definition: Edit.h:134
Attribute makePlace(const std::string &name, const std::string &help)
Create a place attribute.
Definition: Attributes.cpp:137
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
int removeSingle(const PlaceRep &)
Remove single element.
Definition: Edit.cpp:298
int removeMultiple()
Remove multiple elements.
Definition: Edit.cpp:293
Inform & endl(Inform &inf)
Definition: Inform.cpp:42