Loading...
Searching...
No Matches
Attribute.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef ODIM_ATTRIBUTE
32#define ODIM_ATTRIBUTE
33
34
35#include <drain/Log.h>
36#include <ostream>
37//#include <cmath>
38#include <string>
39
40#include <drain/util/EnumFlagger.h>
41#include <drain/Convert.h>
42
43#include <odim/Group.h>
44
45
46
47namespace odim {
48
49/*
50 *
51 \code
52
53 for (const odim::ODIMvariable variable: {"where:BBOX", "where:EPSG", "where:xsize", "where:ysize"}){
54 mout.pending<LOG_WARNING>(variable, " = ", variable.getGroupId(), '|', variable.getGroupName(), ':', variable.getKey());
55 if (src.properties.hasKey(variable)){
56 //mout.accept<LOG_WARNING>(variable, " = ", src.properties[variable]);
57 mouseGroup->set(std::string("data-")+variable.getKey(), src.properties[variable]);
58 }
59}
60 \endcode
61
62*/
63
65
66public:
67
68 inline
70 group.set(GroupId::HOW);
71 }
72
74
77 template <typename T>
78 inline
79 ODIMvariable(const T & value){
80 assign(value);
81 }
82
84 template <typename T>
85 inline
86 ODIMvariable(const T & group, const std::string & key){
87 assign(group, key);
88 }
89
90
91 inline
92 void assign(GroupId g, const std::string & k){
93 group.set(g);
94 key.assign(k);
95 fullName = drain::StringBuilder<':'>(g, k);
96 }
97
98 inline
99 void assign(std::string &g, const std::string & k){
100 group.set(g);
101 key.assign(k);
102 fullName = drain::StringBuilder<':'>(g, k);
103 }
104
105 inline
106 void assign(const std::string & value){
107 std::string g;
108 drain::StringTools::split2(value, g, key, ':');
109 group.set(g);
110 fullName = drain::StringBuilder<':'>(g, key);
111 // fullName = value; // No double-check?
112 }
113
114
115 inline
116 GroupId getGroupId() const {
117 return group.getValue();
118 }
119
120 inline
121 const std::string & getGroupName() const {
122 return group.str();
123 }
124
125 inline
126 const std::string & getKey() const {
127 return key;
128 }
129
130 inline
131 const std::string & str() const {
132 return fullName;
133 }
134
135 operator const std::string & () const {
136 return fullName;
137 }
138
139protected:
140
141 ODIMgroup group;
142 std::string key;
143 std::string fullName;
144
145};
146
147inline
148std::ostream & operator<<(std::ostream & ostr, const odim::ODIMvariable & variable){
149 ostr << variable.getGroupName() << ':' << variable.getKey();
150 return ostr;
151}
152
153}
154
155
156
157
158#endif
159
160// Rack
virtual const key_t & str() const override
String corresponding the current value. Returns empty, if not found.
Definition Flags.h:155
Definition StringBuilder.h:58
static bool split2(const std::string &s, T1 &first, T2 &second, const C &separators, const std::string &trimChars=" \t\n")
Splits and trims a given std::string to a std Sequence.
Definition Attribute.h:64
ODIMvariable(const T &group, const std::string &key)
Initialise with group and key for example WHAT or "what", and "source" .
Definition Attribute.h:86
ODIMvariable(const T &value)
Initialise with an argument of type group:key, for example what:source .
Definition Attribute.h:79
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631