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