NetCDF-C++
4.3.2
Toggle main menu visibility
Loading...
Searching...
No Matches
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
63
~NcEnumType
(){}
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
netCDF::NcEnumType::getBaseType
NcType getBaseType() const
Returns the base type.
Definition
ncEnumType.cpp:69
netCDF::NcEnumType::getMemberValue
void getMemberValue(int index, T &memberValue) const
Returns the value of a member with the given zero-based index.
Definition
ncEnumType.h:94
netCDF::NcEnumType::getMemberCount
size_t getMemberCount() const
Returns number of members in this NcEnumType object.
Definition
ncEnumType.cpp:97
netCDF::NcEnumType::NcEnumType
NcEnumType(const NcGroup &grp, const std::string &name)
Constructor.
netCDF::NcEnumType::NcEnumType
NcEnumType()
Constructor generates a null object.
Definition
ncEnumType.cpp:50
netCDF::NcEnumType::getMemberNameFromIndex
std::string getMemberNameFromIndex(int index) const
Returns the member name for the given zero-based index.
Definition
ncEnumType.cpp:107
netCDF::NcEnumType::addMember
void addMember(const std::string &name, T memberValue)
Adds a new member to this NcEnumType type.
Definition
ncEnumType.h:71
netCDF::NcEnumType::ncEnumType
ncEnumType
List of NetCDF-4 Enumeration types.
Definition
ncEnumType.h:20
netCDF::NcEnumType::nc_USHORT
@ nc_USHORT
unsigned 2-byte int
Definition
ncEnumType.h:25
netCDF::NcEnumType::nc_INT
@ nc_INT
signed 4 byte integer
Definition
ncEnumType.h:23
netCDF::NcEnumType::nc_UINT
@ nc_UINT
unsigned 4-byte int
Definition
ncEnumType.h:26
netCDF::NcEnumType::nc_SHORT
@ nc_SHORT
signed 2 byte integer
Definition
ncEnumType.h:22
netCDF::NcEnumType::nc_UBYTE
@ nc_UBYTE
unsigned 1 byte int
Definition
ncEnumType.h:24
netCDF::NcEnumType::nc_BYTE
@ nc_BYTE
signed 1 byte integer
Definition
ncEnumType.h:21
netCDF::NcEnumType::nc_UINT64
@ nc_UINT64
unsigned 8-byte int
Definition
ncEnumType.h:28
netCDF::NcEnumType::nc_INT64
@ nc_INT64
signed 8-byte int
Definition
ncEnumType.h:27
netCDF::NcEnumType::operator=
NcEnumType & operator=(const NcEnumType &rhs)
assignment operator
Definition
ncEnumType.cpp:24
netCDF::NcEnumType::~NcEnumType
~NcEnumType()
Destructor.
Definition
ncEnumType.h:63
netCDF::NcEnumType::getMemberNameFromValue
std::string getMemberNameFromValue(const T memberValue) const
Returns the member name for the given NcEnumType value.
Definition
ncEnumType.h:83
netCDF::NcGroup
Class represents a netCDF group.
Definition
ncGroup.h:26
netCDF::NcType
Base class inherited by NcOpaque, NcVlen, NcCompound and NcEnum classes.
Definition
ncType.h:15
netCDF::NcType::groupId
int groupId
the group Id
Definition
ncType.h:155
netCDF::NcType::NcType
NcType()
Constructor generates a null object.
Definition
ncType.cpp:43
netCDF::NcType::myId
nc_type myId
the type Id
Definition
ncType.h:152
netCDF::NcType::ncType
ncType
List of netCDF types that can be represented.
Definition
ncType.h:26
netCDF
C++ API for netCDF4.
Definition
ncAtt.h:10
netCDF::ncCheck
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
for NetCDF-C++. NetCDF is a
Unidata
library.