OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
28 : Action(
29 1, "HELP",
30 "The \"HELP\" statement displays the purpose and attribute "
31 "types of an object.") {
32 itsAttr[0] = Attributes::makeString("NAME", "Name of object for which help is wanted");
33
35}
36
37Help::Help(const std::string& name, Help* parent) : Action(name, parent) {
38}
39
42
43Help* Help::clone(const std::string& name) {
44 return new Help(name, this);
45}
46
48 if (itsAttr[0]) {
49 std::string name = Attributes::getString(itsAttr[0]);
50
51 if (Object* object = OpalData::getInstance()->find(name)) {
52 object->printHelp(std::cerr);
53 } else {
54 *ippl::Error << "\n" << *this << "Unknown object \"" << name << "\".\n" << endl;
55 }
56 } else {
57 printHelp(std::cerr);
58 }
59}
60
61void Help::parse(Statement& statement) {
62 parseShortcut(statement);
63}
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Action(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Action.cpp:54
virtual void parseShortcut(Statement &, bool eval=true)
Parser for single-attribute commands.
Definition Object.cpp:127
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition Object.cpp:189
Object(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Object.cpp:354
virtual void printHelp(std::ostream &) const
Print help.
Definition Object.cpp:199
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
static OpalData * getInstance()
Definition OpalData.cpp:195
virtual ~Help()
Definition Help.cpp:40
virtual Help * clone(const std::string &name)
Make clone.
Definition Help.cpp:43
virtual void execute()
Execute the command.
Definition Help.cpp:47
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition Help.cpp:61
Help()
Exemplar constructor.
Definition Help.cpp:27
Interface for statements.
Definition Statement.h:38