OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
StringArray.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: StringArray.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class StringArray:
10 // A class used to parse array attributes.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:36 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Attributes/StringArray.h"
20 #include "Attributes/Attributes.h"
22 #include "Expressions/AValue.h"
24 #include "Utilities/ParseError.h"
25 #include <vector>
26 
27 using namespace Expressions;
28 
29 
30 // Class StringArray
31 // ------------------------------------------------------------------------
32 
33 namespace Attributes {
34 
35  StringArray::StringArray(const std::string &name, const std::string &help):
36  AttributeHandler(name, help, 0)
37  {}
38 
39 
41  {}
42 
43 
44  const std::string &StringArray::getType() const {
45  static std::string type = "string array";
46  return type;
47  }
48 
49 
50  void StringArray::parse(Attribute &attr, Statement &stat, bool) const {
52  }
53 
54 
56  (Attribute &attr, Statement &statement, bool, int index) const {
57  std::vector<std::string> array = Attributes::getStringArray(attr);
58 
59  if(AttributeBase *base = &attr.getBase()) {
60  array = dynamic_cast<AValue<std::string>*>(base)->evaluate();
61  }
62 
63  while(int(array.size()) < index) {
64  array.push_back(std::string());
65  }
66 
67  array[index - 1] =
68  Expressions::parseString(statement, "String value expected.");
69  Attributes::setStringArray(attr, array);
70  }
71 
72 };
virtual void parseComponent(Attribute &, Statement &, bool, int) const
Parse a component of the array.
Definition: StringArray.cpp:56
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: StringArray.cpp:50
void setStringArray(Attribute &attr, const std::vector< std::string > &value)
Set string array value.
Definition: Attributes.cpp:423
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
virtual const std::string & getType() const
Return attribute type string ``string array&#39;&#39;.
Definition: StringArray.cpp:44
A representation of an Object attribute.
Definition: Attribute.h:55
Interface for statements.
Definition: Statement.h:38
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:378
Abstract base class for attribute parsers.
Object attribute with a constant array value.
Definition: AValue.h:35
std::vector< std::string > parseStringArray(Statement &)
Parse string array.
const std::string name
std::string parseString(Statement &, const char msg[])
Parse string value.
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition: Attribute.cpp:67