OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
What.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: What.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: What
10 // The class for the OPAL WHAT command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:37 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "BasicActions/What.h"
21 #include "Attributes/Attributes.h"
22 #include <iostream>
23 
24 
25 // Class What
26 // ------------------------------------------------------------------------
27 
29  Action(1, "WHAT",
30  "The \"WHAT\" statement displays the definition and attribute"
31  " values of an object.") {
33  ("NAME", "Name of object to be displayed");
34 
36 }
37 
38 
39 What::What(const std::string &name, What *parent):
40  Action(name, parent)
41 {}
42 
43 
45 {}
46 
47 
48 What *What::clone(const std::string &name) {
49  return new What(name, this);
50 }
51 
52 
53 void What::execute() {
54  if(itsAttr[0]) {
55  std::string name = Attributes::getString(itsAttr[0]);
56 
57  if(Object *object = OpalData::getInstance()->find(name)) {
58  std::cerr << *object << std::endl;
59  } else {
60  std::cerr << '\n' << *this << "\nUnknown object \"" << name << "\".\n"
61  << std::endl;
62  }
63  } else {
64  printHelp(std::cerr);
65  }
66 }
67 
68 
69 void What::parse(Statement &statement) {
70  parseShortcut(statement);
71 }
virtual void parseShortcut(Statement &)
Parser for single-attribute commands.
Definition: Object.cpp:132
The base class for all OPAL actions.
Definition: Action.h:30
What()
Exemplar constructor.
Definition: What.cpp:28
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
static OpalData * getInstance()
Definition: OpalData.cpp:209
virtual What * clone(const std::string &name)
Make clone.
Definition: What.cpp:48
Interface for statements.
Definition: Statement.h:38
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
virtual void execute()
Execute the command.
Definition: What.cpp:53
virtual void printHelp(std::ostream &) const
Print help.
Definition: Object.cpp:204
virtual ~What()
Definition: What.cpp:44
const T * find(const T table[], const std::string &name)
Look up name.
Definition: TFind.h:34
The base class for all OPAL objects.
Definition: Object.h:48
const std::string name
The WHAT command.
Definition: What.h:28
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition: What.cpp:69