OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
22#include "Expressions/AValue.h"
25#include <vector>
26
27using namespace Expressions;
28
29
30// Class StringArray
31// ------------------------------------------------------------------------
32
33namespace 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::parseStringValue(statement, "String value expected.");
69 Attributes::setStringArray(attr, array);
70 }
71
72};
const std::string name
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
std::string parseStringValue(Statement &, const char msg[])
std::vector< std::string > parseStringArray(Statement &)
Parse string array.
A collection of routines to construct object Attributes and retrieve.
Definition: Attributes.cpp:85
void setStringArray(Attribute &attr, const std::vector< std::string > &value)
Set string array value.
Definition: Attributes.cpp:524
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:478
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
A representation of an Object attribute.
Definition: Attribute.h:52
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition: Attribute.cpp:69
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
Abstract base class for attribute parsers.
virtual const std::string & getType() const
Return attribute type string `‘string array’'.
Definition: StringArray.cpp:44
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
Interface for statements.
Definition: Statement.h:38
Object attribute with a constant array value.
Definition: AValue.h:35