NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcVarMetaCF.h
Go to the documentation of this file.
1 
15 #ifndef INC_netcdf_NcVarMetaCF_h
16 #define INC_netcdf_NcVarMetaCF_h
17 
18 #include "NcVar.h"
19 
20 namespace netcdf {
21 
22 
24 {
25  public:
26 
27  enum MetaItem // items match elements of array attNames
28  {
36  Meta_Unknown // last item always
37  };
38 
39  NcVarMetaCF ( netcdf::NcVar & useNcVar )
40  : var (useNcVar)
41  {
42  }
43 
44  template< class data_type > void Set (
45  MetaItem const which,
46  data_type const & data)
47  {
48  if ( which == Meta_validMin ||
49  which == Meta_validMax ||
50  which == Meta_FillValue )
51  {
52  var.PutAtt ( std::string(attNames[which]), var.GetType(), data );
53  }
54  }
55 
56  void Set (
57  MetaItem const which,
58  std::string const & data)
59  {
60  if ( which != Meta_Unknown )
61  var.PutAtt( std::string(attNames[which]), data );
62  }
63 
64  void Set (
65  MetaItem const which,
66  char const * const data)
67  {
68  if ( which != Meta_Unknown )
69  var.PutAtt( std::string(attNames[which]), std::string(data) );
70  }
71 
72  template< class data_type > void Get (
73  MetaItem const which,
74  data_type & data)
75  {
76  if ( which != Meta_Unknown && Exists(which) )
77  {
78  netcdf::NcVarAtt const att = var.GetAtt( attNames[which] );
79  att.Get(data);
80  }
81  }
82 
83  static char const * const GetAttName (MetaItem const which)
84  { return attNames[which]; /* no checks */ }
85 
86  bool Exists (MetaItem const which) const;
87 
88  private:
89 
90  static char const * const attNames[];
91  netcdf::NcVar var;
92 
93  // not used
94  NcVarMetaCF (NcVarMetaCF const & rhs);
95  NcVarMetaCF & operator= (NcVarMetaCF const & rhs);
96 };
97 
98 
99 inline bool NcVarMetaCF::Exists (MetaItem const which) const
100 {
101  return var.HaveAttribute( GetAttName(which) );
102 }
103 
104 
105 
106 } // namespace netcdf
107 
108 #endif // INC_netcdf_NcVarMetaCF_h
static char const *const GetAttName(MetaItem const which)
Definition: NcVarMetaCF.h:83
NcType GetType() const
Definition: NcVar.cpp:112
bool HaveAttribute(std::string const name) const
Definition: NcVar.cpp:362
MetaItem
Definition: NcVarMetaCF.h:27
long_name : string
Definition: NcVarMetaCF.h:29
NcVarAtt GetAtt(std::string const name) const
Definition: NcVar.cpp:387
Represents a netCDF variable.
Definition: NcVar.h:43
Definition: NcVarMetaCF.h:36
_FillValue : matching type
Definition: NcVarMetaCF.h:34
units : string
Definition: NcVarMetaCF.h:31
bool Exists(MetaItem const which) const
Definition: NcVarMetaCF.h:99
void Set(MetaItem const which, char const *const data)
Definition: NcVarMetaCF.h:64
void Get(MetaItem const which, data_type &data)
Definition: NcVarMetaCF.h:72
NcVarAtt PutAtt(std::string const name, NcType const &type, size_t len, const unsigned char *dataValues) const
Definition: NcVar.cpp:403
NcVarMetaCF(netcdf::NcVar &useNcVar)
Definition: NcVarMetaCF.h:39
void Set(MetaItem const which, std::string const &data)
Definition: NcVarMetaCF.h:56
standard_name : string
Definition: NcVarMetaCF.h:30
void Set(MetaItem const which, data_type const &data)
Definition: NcVarMetaCF.h:44
_Encoding : string
Definition: NcVarMetaCF.h:35
void Get(TVecUbyte &data) const
get NcUbyte vector
Definition: NcAtt.cpp:155
valid_min : numeric type
Definition: NcVarMetaCF.h:32
valid_max : numeric type
Definition: NcVarMetaCF.h:33
Represents a netCDF variable attribute.
Definition: NcVarAtt.h:27
Class for read/write CF-convention metadata for a netCDF variable. A typical set of attributes are kn...
Definition: NcVarMetaCF.h:23