NetCDF-C++  4.3.1-developer
ncEnumType.h
1 #include <string>
2 #include "ncType.h"
3 #include "netcdf.h"
4 #include "ncCheck.h"
5 
6 #ifndef NcEnumTypeClass
7 #define NcEnumTypeClass
8 
9 
10 namespace netCDF
11 {
12  class NcGroup; // forward declaration.
13 
15  class NcEnumType : public NcType
16  {
17  public:
18 
20  enum ncEnumType {
21  nc_BYTE = NC_BYTE,
22  nc_SHORT = NC_SHORT,
23  nc_INT = NC_INT,
24  nc_UBYTE = NC_UBYTE,
25  nc_USHORT = NC_USHORT,
26  nc_UINT = NC_UINT,
27  nc_INT64 = NC_INT64,
28  nc_UINT64 = NC_UINT64
29  };
30 
32  NcEnumType();
33 
41  NcEnumType(const NcGroup& grp, const std::string& name);
42 
48  NcEnumType(const NcType& ncType);
49 
51  NcEnumType& operator=(const NcEnumType& rhs);
52 
57  NcEnumType& operator=(const NcType& rhs);
58 
60  NcEnumType(const NcEnumType& rhs);
61 
64 
65 
71  template <class T> void addMember(const std::string& name, T memberValue)
72  {
73  ncCheck(nc_insert_enum(groupId, myId, name.c_str(), (void*) &memberValue),__FILE__,__LINE__);
74  }
75 
77  size_t getMemberCount() const;
78 
80  std::string getMemberNameFromIndex(int index) const;
81 
83  template <class T> std::string getMemberNameFromValue(const T memberValue) const {
84  char charName[NC_MAX_NAME+1];
85  ncCheck(nc_inq_enum_ident(groupId,myId,static_cast<long long>(memberValue),charName),__FILE__,__LINE__);
86  return std::string(charName);
87  }
88 
94  template <class T> void getMemberValue(int index, T& memberValue) const
95  {
96  char* charName=NULL;
97  ncCheck(nc_inq_enum_member(groupId,myId,index,charName,&memberValue),__FILE__,__LINE__);
98  }
99 
101  NcType getBaseType() const;
102 
103  };
104 
105 }
106 
107 #endif
void getMemberValue(int index, T &memberValue) const
Returns the value of a member with the given zero-based index.
Definition: ncEnumType.h:94
Base class inherited by NcOpaque, NcVlen, NcCompound and NcEnum classes.
Definition: ncType.h:14
signed 4 byte integer
Definition: ncEnumType.h:23
int groupId
the group Id
Definition: ncType.h:152
std::string getMemberNameFromIndex(int index) const
Returns the member name for the given zero-based index.
Definition: ncEnumType.cpp:107
C++ API for netCDF4.
Definition: ncAtt.h:9
unsigned 4-byte int
Definition: ncEnumType.h:26
Class represents a netCDF enum type.
Definition: ncEnumType.h:15
Class represents a netCDF group.
Definition: ncGroup.h:27
ncType
List of netCDF types that can be represented.
Definition: ncType.h:25
~NcEnumType()
Destructor.
Definition: ncEnumType.h:63
unsigned 2-byte int
Definition: ncEnumType.h:25
signed 2 byte integer
Definition: ncEnumType.h:22
void addMember(const std::string &name, T memberValue)
Adds a new member to this NcEnumType type.
Definition: ncEnumType.h:71
std::string getMemberNameFromValue(const T memberValue) const
Returns the member name for the given NcEnumType value.
Definition: ncEnumType.h:83
nc_type myId
the type Id
Definition: ncType.h:149
NcEnumType()
Constructor generates a null object.
Definition: ncEnumType.cpp:50
unsigned 1 byte int
Definition: ncEnumType.h:24
void ncCheck(int retCode, const char *file, int line)
Function checks error code and if necessary throws an exception.
Definition: ncCheck.cpp:11
size_t getMemberCount() const
Returns number of members in this NcEnumType object.
Definition: ncEnumType.cpp:97
NcType getBaseType() const
Returns the base type.
Definition: ncEnumType.cpp:69
ncEnumType
List of NetCDF-4 Enumeration types.
Definition: ncEnumType.h:20
signed 8-byte int
Definition: ncEnumType.h:27
NcEnumType & operator=(const NcEnumType &rhs)
assignment operator
Definition: ncEnumType.cpp:24
unsigned 8-byte int
Definition: ncEnumType.h:28
signed 1 byte integer
Definition: ncEnumType.h:21

Return to the Main Unidata NetCDF page.
Generated on Fri Nov 11 2016 15:28:29 for NetCDF-C++. NetCDF is a Unidata library.