OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
System.cpp
Go to the documentation of this file.
1//
2// Class System
3// The class for OPAL SYSTEM command on a single core.
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/System.h"
19#include "Ippl.h"
20
22#include "Utility/IpplInfo.h"
23
24#include <cstdlib>
25
27 : Action(
28 1, "SYSTEM",
29 "The \"SYSTEM\" statement sends a command string to the "
30 "operating system.") {
31 itsAttr[0] = Attributes::makeString("CMD", "A system command to be executed");
32
34}
35
36System::System(const std::string& name, System* parent) : Action(name, parent) {
37}
38
41
42System* System::clone(const std::string& name) {
43 return new System(name, this);
44}
45
47 if (ippl::Comm->rank() == 0) {
48 std::string command = Attributes::getString(itsAttr[0]);
49
50 int res = system(command.c_str());
51 if (res != 0)
52 *ippl::Error << "SYSTEM call failed" << endl;
53 }
54}
55
56void System::parse(Statement& statement) {
57 parseShortcut(statement);
58}
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
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
virtual ~System()
Definition System.cpp:39
virtual System * clone(const std::string &name)
Make clone.
Definition System.cpp:42
virtual void execute()
Execute the command.
Definition System.cpp:46
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition System.cpp:56
System()
Exemplar constructor.
Definition System.cpp:26
Interface for statements.
Definition Statement.h:38