OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
UpperCaseStringArray.cpp
Go to the documentation of this file.
1//
2// Class UpperCaseStringArray
3// This class is used to parse attributes of type array of strings that should
4// be all upper case, i.e. it returns an array of upper case strings.
5//
6// Copyright (c) 2020, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
20#include <vector>
23#include "Expressions/AValue.h"
26#include "Utilities/Util.h"
27
28using namespace Expressions;
29
30namespace Attributes {
31
32 UpperCaseStringArray::UpperCaseStringArray(const std::string& name, const std::string& help)
33 : AttributeHandler(name, help, 0) {}
34
36
37 const std::string& UpperCaseStringArray::getType() const {
38 static std::string type = "string array";
39 return type;
40 }
41
42 void UpperCaseStringArray::parse(Attribute& attr, Statement& stat, bool) const {
43 std::vector<std::string> array = Expressions::parseStringArray(stat);
45 }
46
48 Attribute& attr, Statement& statement, bool, int index) const {
49 std::vector<std::string> array = Attributes::getStringArray(attr);
50
51 if (AttributeBase* base = &attr.getBase()) {
52 array = dynamic_cast<AValue<std::string>*>(base)->evaluate();
53 }
54
55 while (int(array.size()) < index) {
56 array.push_back(std::string());
57 }
58
59 array[index - 1] = Expressions::parseStringValue(statement, "String value expected.");
61 }
62
63}; // namespace Attributes
Abstract base class for attribute values of different types.
Abstract base class for attribute parsers.
A representation of an Object attribute.
Definition Attribute.h:52
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition Attribute.cpp:52
virtual const std::string & getType() const
Return attribute type string `‘string array’'.
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
virtual void parseComponent(Attribute &, Statement &, bool, int) const
Parse a component of the array.
Object attribute with a constant array value.
Definition AValue.h:35
Interface for statements.
Definition Statement.h:37
A collection of routines to construct object Attributes and retrieve.
void setUpperCaseStringArray(Attribute &attr, const std::vector< std::string > &value)
Set upper case string array value.
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Representation objects and parsers for attribute expressions.
std::string parseStringValue(Statement &, const char msg[])
std::vector< std::string > parseStringArray(Statement &)
Parse string array.