NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcEnumType.h
Go to the documentation of this file.
1 
16 #ifndef INC_netcdf_NcEnumType_h
17 #define INC_netcdf_NcEnumType_h
18 
19 #include "NcTypeUserDef.h"
20 #include "NcCheck.h"
21 #include "NcLimits.h"
22 
23 namespace netcdf {
24 
25  class NcGroup;
26 
27  class NcEnumType : public NcTypeUserDef
28  {
29  public:
30 
33  {
34  nc_BYTE = NC_BYTE,
35  nc_SHORT = NC_SHORT,
36  nc_INT = NC_INT,
37  nc_UBYTE = NC_UBYTE,
38  nc_USHORT = NC_USHORT,
39  nc_UINT = NC_UINT,
40  nc_INT64 = NC_INT64,
41  nc_UINT64 = NC_UINT64
42  };
43 
45  NcEnumType();
46 
54  NcEnumType(
55  int const useFileID,
56  NcGroup const & grp,
57  std::string const name,
58  int const typeID);
59 
60  NcEnumType(NcEnumType const & rhs)
61  : NcTypeUserDef (rhs)
62  {
63  }
64 
65  virtual std::string const getTypeClassName () const { return myTypeName; }
66 
72  template <class T> void addMember (
73  std::string const name,
74  T memberValue)
75  {
76  NcCHECK( nc_insert_enum( GetGroupID(), GetTypeID(), name.c_str(), (void*) &memberValue) );
77  }
78 
80  size_t GetCount () const;
81 
83  std::string GetNameFromIndex (int const index) const;
84 
86  template
87  <
88  class T
89  >
90  std::string GetNameFromValue (const T memberValue) const
91  {
92  char charName[ NcLimits::maxNameLength + 1 ];
93  NcCHECK( nc_inq_enum_ident (
94  GetGroupID(), GetTypeID(),
95  static_cast<long long>(memberValue),
96  charName ) );
97  return std::string(charName);
98  }
99 
105  template
106  <
107  class T
108  >
109  void GetValue (
110  int const index,
111  T & memberValue) const
112  {
113  char* charName=NULL;
114  NcCHECK( nc_inq_enum_member( GetGroupID(), GetTypeID(), index, charName, &memberValue) );
115  }
116 
118  NcType GetBaseType() const;
119 
120  private:
121  static char const * const myTypeName;
122 
123  };
124 
125 } // namespace netcdf
126 
127 #endif
ncEnumType
Definition: NcEnumType.h:32
NcEnumType()
Definition: NcEnumType.cpp:40
Defines a non-atomic, user-defined NetCDF4 type.
Definition: NcTypeUserDef.h:24
signed 1 byte integer
Definition: NcEnumType.h:34
virtual std::string const getTypeClassName() const
Definition: NcEnumType.h:65
std::string GetNameFromIndex(int const index) const
Definition: NcEnumType.cpp:102
NcType GetBaseType() const
Definition: NcEnumType.cpp:55
Represents a netCDF enum type.
Definition: NcEnumType.h:27
NcEnumType(NcEnumType const &rhs)
Definition: NcEnumType.h:60
int GetGroupID() const
group ID
Definition: NcTypeUserDef.h:55
int GetTypeID() const
type ID from nc_def*
Definition: NcTypeUserDef.h:56
static int const maxNameLength
max length of an NetCDF name
Definition: NcLimits.h:26
signed 4 byte integer
Definition: NcEnumType.h:36
void addMember(std::string const name, T memberValue)
Definition: NcEnumType.h:72
size_t GetCount() const
Definition: NcEnumType.cpp:91
unsigned 8-byte int
Definition: NcEnumType.h:41
#define NcCHECK(a_)
Definition: NcCheck.h:45
unsigned 2-byte int
Definition: NcEnumType.h:38
void GetValue(int const index, T &memberValue) const
Definition: NcEnumType.h:109
unsigned 4-byte int
Definition: NcEnumType.h:39
signed 8-byte int
Definition: NcEnumType.h:40
Checks the netCDF function error code and if necessary throws an exception.
Base class for all netCDF data types.
Definition: NcType.h:47
signed 2 byte integer
Definition: NcEnumType.h:35
Represents a netCDF group.
Definition: NcGroup.h:36
unsigned 1 byte int
Definition: NcEnumType.h:37
std::string GetNameFromValue(const T memberValue) const
Definition: NcEnumType.h:90