OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Call.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Call.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Call
10 // The class for OPAL "CALL" commands.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:37 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "BasicActions/Call.h"
21 #include "Attributes/Attributes.h"
22 #include "OpalParser/OpalParser.h"
23 #include "Parser/FileStream.h"
25 #include "Utilities/Options.h"
26 #include "Utility/IpplInfo.h"
27 #include <iostream>
28 
29 using std::cerr;
30 using std::endl;
31 
32 
33 // Class Call
34 // ------------------------------------------------------------------------
35 
37  Action(1, "CALL",
38  "The \"CALL\" statement switches input temporarily to the "
39  "named file.") {
40  itsAttr[0] =
41  Attributes::makeString("FILE", "Name of file to be read", "CALL");
42 
44 }
45 
46 
47 Call::Call(const std::string &name, Call *parent):
48  Action(name, parent)
49 {}
50 
51 
53 {}
54 
55 
56 Call *Call::clone(const std::string &name) {
57  return new Call(name, this);
58 }
59 
60 
61 void Call::execute() {
62  std::string file = Attributes::getString(itsAttr[0]);
63 
64  if(Options::info && Ippl::myNode() == 0) {
65  cerr << "Start reading input stream \"" << file << "\"." << endl;
66  }
67 
68  OpalParser().run(new FileStream(file));
69 
70  if(Options::info && Ippl::myNode() == 0) {
71  cerr << "End reading input stream \"" << file << "\"." << endl;
72  }
73 }
74 
75 
76 void Call::parse(Statement &statement) {
77  parseShortcut(statement);
78 }
virtual void parseShortcut(Statement &)
Parser for single-attribute commands.
Definition: Object.cpp:132
The base class for all OPAL actions.
Definition: Action.h:30
static int myNode()
Definition: IpplInfo.cpp:794
virtual ~Call()
Definition: Call.cpp:52
The default parser for OPAL-9.
Definition: OpalParser.h:44
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
bool info
Info flag.
Definition: Options.cpp:8
virtual void execute()
Execute the command.
Definition: Call.cpp:61
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition: Call.cpp:76
virtual Call * clone(const std::string &name)
Make clone.
Definition: Call.cpp:56
Interface for statements.
Definition: Statement.h:38
Call()
Exemplar constructor.
Definition: Call.cpp:36
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:601
A stream of input tokens.
Definition: FileStream.h:32
const std::string name
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
The CALL command.
Definition: Call.h:28
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307