MI - Fimex
CDMAttribute.h
Go to the documentation of this file.
1 /*
2  * Fimex
3  *
4  * (C) Copyright 2008, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  */
23 
24 #ifndef CDMATTRIBUTE_H_
25 #define CDMATTRIBUTE_H_
26 
27 #include <string>
28 #include <vector>
29 #include <ostream>
30 #include <boost/shared_ptr.hpp>
31 #include "fimex/DataDecl.h"
32 #include "fimex/CDMDataType.h"
33 #include "fimex/CDMNamedEntity.h"
34 #include "fimex/CDMException.h"
35 #include "fimex/deprecated.h"
36 
37 namespace MetNoFimex
38 {
39 
44 {
45 
46 public:
47  CDMAttribute();
49  explicit CDMAttribute(std::string name, std::string value);
51  explicit CDMAttribute(std::string name, char value);
53  explicit CDMAttribute(std::string name, int value);
55  explicit CDMAttribute(std::string name, short value);
57  explicit CDMAttribute(std::string name, float value);
59  explicit CDMAttribute(std::string name, double value);
61  explicit CDMAttribute(std::string name, CDMDataType datatype, DataPtr data);
63  explicit CDMAttribute(const std::string& name, const std::string& datatype, const std::string& value) throw(CDMException);
65  explicit CDMAttribute(const std::string& name, CDMDataType datatype, const std::vector<std::string>& values) throw(CDMException);
66  virtual ~CDMAttribute();
68  const std::string& getName() const {return name;}
70  void setName(std::string newName) {name = newName;}
72  const std::string getStringValue() const;
74  const DataPtr getData() const {return data;}
76  void setData(DataPtr data) {this->data = data;}
78  CDMDataType getDataType() const {return datatype;}
79  void toXMLStream(std::ostream& out, const std::string& indent = "") const;
80 private:
81  std::string name;
82  CDMDataType datatype;
83  DataPtr data;
84  /* datatype and name must be set to call this init function */
85  void initDataByArray(const std::vector<std::string>& values);
86  /* init data arrays for all types */
87  template<typename T>
88  void initDataArray(const std::vector<std::string>& values);
89 };
90 
97 MIFI_DEPRECATED(std::vector<CDMAttribute> projStringToAttributes(std::string projStr));
105 MIFI_DEPRECATED(std::string attributesToProjString(const std::vector<CDMAttribute>& attrs));
106 
107 
108 }
109 
110 #endif /*CDMATTRIBUTE_H_*/
Definition: CDMNamedEntity.h:42
basic_string< char > string
boost::shared_ptr< Data > DataPtr
Definition: DataDecl.h:39
const std::string & getName() const
retrieve the name of the attribute
Definition: CDMAttribute.h:68
basic_ostream< char > ostream
MIFI_DEPRECATED(std::vector< CDMAttribute > projStringToAttributes(std::string projStr))
convert a proj4 string to a list of CDMAttributes usable for CF-1.0 projection variable ...
Definition: CDMException.h:36
Definition: C_CDMReader.h:35
Definition: CDMAttribute.h:43
const DataPtr getData() const
retrieve the data-pointer of the attribute
Definition: CDMAttribute.h:74
void setData(DataPtr data)
set the data for this attribute
Definition: CDMAttribute.h:76
CDMDataType getDataType() const
retrieve the datatype of the attribute
Definition: CDMAttribute.h:78
const std::string getStringValue() const
retrieve the stringified value of the attribute
void setName(std::string newName)
set the name of the attribute
Definition: CDMAttribute.h:70
CDMDataType
Definition: CDMDataType.h:35
void toXMLStream(std::ostream &out, const std::string &indent="") const