OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
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//
22#include "Expressions/AValue.h"
25#include "Utilities/Util.h"
26#include <vector>
27
28using namespace Expressions;
29
30
31namespace Attributes {
32
33 UpperCaseStringArray::UpperCaseStringArray(const std::string &name, const std::string &help):
34 AttributeHandler(name, help, 0)
35 {}
36
37
39 {}
40
41
42 const std::string &UpperCaseStringArray::getType() const {
43 static std::string type = "string array";
44 return type;
45 }
46
47
48 void UpperCaseStringArray::parse(Attribute &attr, Statement &stat, bool) const {
49 std::vector<std::string> array = Expressions::parseStringArray(stat);
51 }
52
53
55 (Attribute &attr, Statement &statement, bool, int index) const {
56 std::vector<std::string> array = Attributes::getStringArray(attr);
57
58 if(AttributeBase *base = &attr.getBase()) {
59 array = dynamic_cast<AValue<std::string>*>(base)->evaluate();
60 }
61
62 while(int(array.size()) < index) {
63 array.push_back(std::string());
64 }
65
66 array[index - 1] =
67 Expressions::parseStringValue(statement, "String value expected.");
69 }
70
71};
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 setUpperCaseStringArray(Attribute &attr, const std::vector< std::string > &value)
Set upper case string array value.
Definition: Attributes.cpp:540
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’'.
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
virtual void parseComponent(Attribute &, Statement &, bool, int) const
Parse a component of the array.
Interface for statements.
Definition: Statement.h:38
Object attribute with a constant array value.
Definition: AValue.h:35