OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Help.cpp
Go to the documentation of this file.
1//
2// Class Help
3// The class for OPAL HELP command.
4//
5// Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#include "BasicActions/Help.h"
19
23#include "Utility/IpplInfo.h"
24
25#include <iostream>
26
27
29 Action(1, "HELP",
30 "The \"HELP\" statement displays the purpose and attribute "
31 "types of an object.") {
33 ("NAME", "Name of object for which help is wanted");
34
36}
37
38
39Help::Help(const std::string& name, Help* parent):
40 Action(name, parent)
41{}
42
43
45{}
46
47
48Help* Help::clone(const std::string& name) {
49 return new Help(name, this);
50}
51
52
54 if (itsAttr[0]) {
55 std::string name = Attributes::getString(itsAttr[0]);
56
57 if (Object *object = OpalData::getInstance()->find(name)) {
58 object->printHelp(std::cerr);
59 } else {
60 ERRORMSG("\n" << *this << "Unknown object \"" << name << "\".\n"
61 << endl) ;
62 }
63 } else {
64 printHelp(std::cerr);
65 }
66}
67
68
69void Help::parse(Statement& statement) {
70 parseShortcut(statement);
71}
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
const std::string name
const T * find(const T table[], const std::string &name)
Look up name.
Definition: TFind.h:34
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
The base class for all OPAL actions.
Definition: Action.h:30
The base class for all OPAL objects.
Definition: Object.h:48
virtual void parseShortcut(Statement &, bool eval=true)
Parser for single-attribute commands.
Definition: Object.cpp:129
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
virtual void printHelp(std::ostream &) const
Print help.
Definition: Object.cpp:201
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
static OpalData * getInstance()
Definition: OpalData.cpp:196
Definition: Help.h:24
virtual ~Help()
Definition: Help.cpp:44
virtual Help * clone(const std::string &name)
Make clone.
Definition: Help.cpp:48
virtual void execute()
Execute the command.
Definition: Help.cpp:53
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition: Help.cpp:69
Help()
Exemplar constructor.
Definition: Help.cpp:28
Interface for statements.
Definition: Statement.h:38