NetCDF-C++ 4.3.1
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
10namespace netCDF
11{
12 class NcGroup; // forward declaration.
13
15 class NcEnumType : public NcType
16 {
17 public:
18
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
Class represents a netCDF enum type.
Definition: ncEnumType.h:16
NcType getBaseType() const
Returns the base type.
Definition: ncEnumType.cpp:69
void getMemberValue(int index, T &memberValue) const
Returns the value of a member with the given zero-based index.
Definition: ncEnumType.h:94
size_t getMemberCount() const
Returns number of members in this NcEnumType object.
Definition: ncEnumType.cpp:97
NcEnumType(const NcGroup &grp, const std::string &name)
Constructor.
NcEnumType()
Constructor generates a null object.
Definition: ncEnumType.cpp:50
std::string getMemberNameFromIndex(int index) const
Returns the member name for the given zero-based index.
Definition: ncEnumType.cpp:107
void addMember(const std::string &name, T memberValue)
Adds a new member to this NcEnumType type.
Definition: ncEnumType.h:71
ncEnumType
List of NetCDF-4 Enumeration types.
Definition: ncEnumType.h:20
@ nc_USHORT
unsigned 2-byte int
Definition: ncEnumType.h:25
@ nc_INT
signed 4 byte integer
Definition: ncEnumType.h:23
@ nc_UINT
unsigned 4-byte int
Definition: ncEnumType.h:26
@ nc_SHORT
signed 2 byte integer
Definition: ncEnumType.h:22
@ nc_UBYTE
unsigned 1 byte int
Definition: ncEnumType.h:24
@ nc_BYTE
signed 1 byte integer
Definition: ncEnumType.h:21
@ nc_UINT64
unsigned 8-byte int
Definition: ncEnumType.h:28
@ nc_INT64
signed 8-byte int
Definition: ncEnumType.h:27
NcEnumType & operator=(const NcEnumType &rhs)
assignment operator
Definition: ncEnumType.cpp:24
~NcEnumType()
Destructor.
Definition: ncEnumType.h:63
std::string getMemberNameFromValue(const T memberValue) const
Returns the member name for the given NcEnumType value.
Definition: ncEnumType.h:83
Class represents a netCDF group.
Definition: ncGroup.h:28
Base class inherited by NcOpaque, NcVlen, NcCompound and NcEnum classes.
Definition: ncType.h:15
int groupId
the group Id
Definition: ncType.h:152
nc_type myId
the type Id
Definition: ncType.h:149
ncType
List of netCDF types that can be represented.
Definition: ncType.h:26
C++ API for netCDF4.
Definition: ncAtt.h:10
void ncCheck(int retCode, const char *file, int line)
Function checks error code and if necessary throws an exception.
Definition: ncCheck.cpp:11

Return to the Main Unidata NetCDF page.
Generated on Wed Nov 10 2021 15:25:08 for NetCDF-C++. NetCDF is a Unidata library.