MI - Fimex
CDMVariable.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 CDMVARIABLE_H_
25 #define CDMVARIABLE_H_
26 
27 #include <string>
28 #include <vector>
29 #include <ostream>
30 #include "fimex/CDMAttribute.h"
31 #include "fimex/CDMDataType.h"
32 #include "fimex/CDMNamedEntity.h"
33 
34 namespace MetNoFimex
35 {
36 
42 {
43 public:
44  explicit CDMVariable(std::string name, CDMDataType datatype, std::vector<std::string> shape);
45  virtual ~CDMVariable();
46  const std::string& getName() const {return name;}
47  void setName(std::string newName) {name = newName;}
48  CDMDataType getDataType() const {return datatype;}
49  void setDataType(CDMDataType type) {datatype = type;}
50  const std::vector<std::string>& getShape() const {return shape;}
51  void setShape(std::vector<std::string> newShape) {shape = newShape;}
58  void setAsSpatialVector(const std::string& counterpart, const std::string& direction);
62  bool isSpatialVector() const {return "" != spatialVectorCounterpart;}
64  const std::string& getSpatialVectorCounterpart() const {return spatialVectorCounterpart;}
66  const std::string& getSpatialVectorDirection() const {return spatialVectorDirection;}
72  bool checkDimension(const std::string& dimension) const;
74  void toXMLStream(std::ostream& out) const;
76  void toXMLStream(std::ostream& out, const std::vector<CDMAttribute>& attrs) const;
78  void setData(DataPtr data) {this->data = data;}
86  const DataPtr getData() const {return data;}
88  int hasData() const {return (data.get() != 0);}
89 private:
90  std::string name;
91  CDMDataType datatype;
93  void shapeToXMLStream(std::ostream& out) const;
94  DataPtr data;
95  std::string spatialVectorCounterpart;
96  std::string spatialVectorDirection;
97 };
98 
99 }
100 
101 #endif /*CDMVARIABLE_H_*/
Definition: CDMNamedEntity.h:42
void setDataType(CDMDataType type)
Definition: CDMVariable.h:49
basic_string< char > string
bool isSpatialVector() const
Definition: CDMVariable.h:62
boost::shared_ptr< Data > DataPtr
Definition: DataDecl.h:39
void setAsSpatialVector(const std::string &counterpart, const std::string &direction)
const std::vector< std::string > & getShape() const
Definition: CDMVariable.h:50
const std::string & getSpatialVectorDirection() const
get the possible directions of this spatial vector (comma-separated string)
Definition: CDMVariable.h:66
void setShape(std::vector< std::string > newShape)
Definition: CDMVariable.h:51
CDMDataType getDataType() const
Definition: CDMVariable.h:48
basic_ostream< char > ostream
Definition: C_CDMReader.h:35
void toXMLStream(std::ostream &out) const
print a xml representation to the stream without attributes
const std::string & getName() const
Definition: CDMVariable.h:46
int hasData() const
check if real data has been set with setData() (null-pointer reference returns false) ...
Definition: CDMVariable.h:88
const DataPtr getData() const
retrieve volatile data from this variable
Definition: CDMVariable.h:86
void setData(DataPtr data)
add data to the variable
Definition: CDMVariable.h:78
void setName(std::string newName)
Definition: CDMVariable.h:47
Definition: CDMVariable.h:41
CDMDataType
Definition: CDMDataType.h:35
bool checkDimension(const std::string &dimension) const
CDMVariable(std::string name, CDMDataType datatype, std::vector< std::string > shape)
const std::string & getSpatialVectorCounterpart() const
get the spatial counterpart of this vector
Definition: CDMVariable.h:64