OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
StringConstant.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: StringConstant.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: StringConstant
10 // Implements a OPAL STRING_CONSTANT definition.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2001/08/13 15:26:42 $
15 // $Author: jowett $
16 //
17 // ------------------------------------------------------------------------
18 
21 #include "Attributes/Attributes.h"
22 #include "Utilities/Util.h"
23 #include <iostream>
24 
25 
26 // Class StringConstant
27 // ------------------------------------------------------------------------
28 
30  ValueDefinition(1, "STRING_CONSTANT",
31  "The \"STRING CONSTANT\" statement defines a global "
32  "string constant:\n"
33  "\tSTRING CONSTANT <name> = <String-expression>;\n") {
34  itsAttr[0] = Attributes::makeString("VALUE", "The constant value");
35 
37 
39  opal->create(new StringConstant("GITREVISION", this, Util::getGitRevision()));
40 }
41 
42 
43 StringConstant::StringConstant(const std::string &name, StringConstant *parent):
44  ValueDefinition(name, parent)
45 {}
46 
47 
48 StringConstant::StringConstant(const std::string &name, StringConstant *parent, const std::string &value):
49  ValueDefinition(name, parent)
50 {
51  Attributes::setString(itsAttr[0], value);
52  itsAttr[0].setReadOnly(true);
53  builtin = true;
54 }
55 
56 
58 {}
59 
60 
62  return false;
63 }
64 
65 
67  return new StringConstant(name, this);
68 }
69 
70 
71 
72 std::string StringConstant::getString() const {
73  return Attributes::getString(itsAttr[0]);
74 }
75 
76 
77 
78 void StringConstant::print(std::ostream &os) const {
79  os << "STRING " << getOpalName() << '=' << itsAttr[0] << ';';
80  os << std::endl;
81 }
82 
83 void StringConstant::printValue(std::ostream &os) const {
84  os << itsAttr[0];
85 }
The global OPAL structure.
Definition: OpalData.h:54
virtual bool canReplaceBy(Object *object)
Test if object can be replaced.
virtual void printValue(std::ostream &os) const
Print its value.
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:524
void setString(Attribute &attr, const std::string &val)
Set string value.
Definition: Attributes.cpp:356
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual void print(std::ostream &) const
Print the constant.
StringConstant()
Exemplar constructor.
static OpalData * getInstance()
Definition: OpalData.cpp:209
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
The STRING CONSTANT definition.
virtual ~StringConstant()
virtual StringConstant * clone(const std::string &name)
Make clone.
The base class for all OPAL objects.
Definition: Object.h:48
The base class for all OPAL value definitions.
const std::string name
std::string getGitRevision()
Definition: Util.cpp:15
bool builtin
Built-in flag.
Definition: Object.h:231
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
virtual std::string getString() const
Return value.
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307