NetCDF-C++
4.3.2
Toggle main menu visibility
Loading...
Searching...
No Matches
ncEnumType.cpp
1
#include "ncEnumType.h"
2
#include "ncGroup.h"
3
#include "ncCheck.h"
4
#include "ncByte.h"
5
#include "ncUbyte.h"
6
#include "ncChar.h"
7
#include "ncShort.h"
8
#include "ncUshort.h"
9
#include "ncInt.h"
10
#include "ncUint.h"
11
#include "ncInt64.h"
12
#include "ncUint64.h"
13
#include "ncFloat.h"
14
#include "ncDouble.h"
15
#include "ncString.h"
16
#include "ncException.h"
17
using namespace
std;
18
using namespace
netCDF
;
19
using namespace
netCDF::exceptions
;
20
21
// Class represents a netCDF variable.
22
23
// assignment operator
24
NcEnumType
&
NcEnumType::operator=
(
const
NcEnumType
& rhs)
25
{
26
NcType::operator=
(rhs);
// assign base class parts
27
return
*
this
;
28
}
29
30
// assignment operator
31
NcEnumType
&
NcEnumType::operator=
(
const
NcType
& rhs)
32
{
33
if
(&rhs !=
this
) {
34
// check the rhs is the base of an Enum type
35
if
(
getTypeClass
() != NC_ENUM)
throw
NcException
(
"The NcType object must be the base of an Enum type."
,__FILE__,__LINE__);
36
// assign base class parts
37
NcType::operator=
(rhs);
38
}
39
return
*
this
;
40
}
41
42
// The copy constructor.
43
NcEnumType::NcEnumType
(
const
NcEnumType
& rhs):
44
NcType
(rhs)
45
{
46
}
47
48
49
// Constructor generates a null object.
50
NcEnumType::NcEnumType
() :
51
NcType
()
// invoke base class constructor
52
{}
53
54
// constructor
55
NcEnumType::NcEnumType
(
const
NcGroup
& grp,
const
string
& name):
56
NcType
(grp,name)
57
{}
58
59
60
// constructor
61
NcEnumType::NcEnumType
(
const
NcType
&
ncType
):
62
NcType
(
ncType
)
63
{
64
// check the nctype object is the base of an Enum type
65
if
(
getTypeClass
() != NC_ENUM)
throw
NcException
(
"The NcType object must be the base of an Enum type."
,__FILE__,__LINE__);
66
}
67
68
// Returns the base type.
69
NcType
NcEnumType::getBaseType
()
const
70
{
71
char
charName[NC_MAX_NAME+1];
72
nc_type base_nc_typep;
73
size_t
*base_sizep=NULL;
74
size_t
*num_membersp=NULL;
75
ncCheck
(nc_inq_enum(
groupId
,
myId
,charName,&base_nc_typep,base_sizep,num_membersp),__FILE__,__LINE__);
76
switch
(base_nc_typep) {
77
case
NC_BYTE :
return
ncByte
;
78
case
NC_UBYTE :
return
ncUbyte
;
79
case
NC_CHAR :
return
ncChar
;
80
case
NC_SHORT :
return
ncShort
;
81
case
NC_USHORT :
return
ncUshort;
82
case
NC_INT :
return
ncInt
;
83
case
NC_UINT :
return
ncUint
;
84
case
NC_INT64 :
return
ncInt64
;
85
case
NC_UINT64 :
return
ncUint64
;
86
case
NC_FLOAT :
return
ncFloat
;
87
case
NC_DOUBLE :
return
ncDouble
;
88
case
NC_STRING :
return
ncString
;
89
default
:
90
// this is a user defined type
91
return
NcType
(
getParentGroup
(),base_nc_typep);
92
}
93
}
94
95
96
// Returns number of members in this NcEnumType object.
97
size_t
NcEnumType::getMemberCount
()
const
{
98
char
charName[NC_MAX_NAME+1];
99
nc_type* base_nc_typep=NULL;
100
size_t
* base_sizep=NULL;
101
size_t
num_membersp;
102
ncCheck
(nc_inq_enum(
groupId
,
myId
,charName,base_nc_typep,base_sizep,&num_membersp),__FILE__,__LINE__);
103
return
num_membersp;
104
};
105
106
// Returns the member name for the given zero-based index.
107
string
NcEnumType::getMemberNameFromIndex
(
int
index)
const
{
108
void
* value=NULL;
109
char
charName[NC_MAX_NAME+1];
110
ncCheck
(nc_inq_enum_member(
groupId
,
myId
,index,charName,value),__FILE__,__LINE__);
111
return
static_cast<
string
>
(charName);
112
};
netCDF::NcEnumType::getBaseType
NcType getBaseType() const
Returns the base type.
Definition
ncEnumType.cpp:69
netCDF::NcEnumType::getMemberCount
size_t getMemberCount() const
Returns number of members in this NcEnumType object.
Definition
ncEnumType.cpp:97
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::operator=
NcEnumType & operator=(const NcEnumType &rhs)
assignment operator
Definition
ncEnumType.cpp:24
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::getTypeClass
ncType getTypeClass() const
The type class returned as enumeration type.
Definition
ncType.cpp:111
netCDF::NcType::getParentGroup
netCDF::NcGroup getParentGroup() const
Gets parent group.
Definition
ncType.cpp:88
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::operator=
NcType & operator=(const NcType &rhs)
assignment operator
Definition
ncType.cpp:26
netCDF::NcType::ncType
ncType
List of netCDF types that can be represented.
Definition
ncType.h:26
netCDF::exceptions::NcException
Base object is thrown if a netCDF exception is encountered.
Definition
ncException.h:24
netCDF::exceptions
Exception classes.
Definition
ncException.h:16
netCDF
C++ API for netCDF4.
Definition
ncAtt.h:10
netCDF::ncShort
NcShort ncShort
A global instance of the NcShort class within the netCDF namespace.
Definition
ncShort.cpp:7
netCDF::ncFloat
NcFloat ncFloat
A global instance of the NcFloat class within the netCDF namespace.
Definition
ncFloat.cpp:7
netCDF::ncInt64
NcInt64 ncInt64
A global instance of the NcInt64 class within the netCDF namespace.
Definition
ncInt64.cpp:7
netCDF::ncUint64
NcUint64 ncUint64
A global instance of the NcUint64 class within the netCDF namespace.
Definition
ncUint64.cpp:7
netCDF::ncUint
NcUint ncUint
A global instance of the NcUint class within the netCDF namespace.
Definition
ncUint.cpp:7
netCDF::ncString
NcString ncString
A global instance of the NcString class within the netCDF namespace.
Definition
ncString.cpp:7
netCDF::ncInt
NcInt ncInt
A global instance of the NcInt class within the netCDF namespace.
Definition
ncInt.cpp:7
netCDF::ncDouble
NcDouble ncDouble
A global instance of the NcDouble class within the netCDF namespace.
Definition
ncDouble.cpp:7
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
netCDF::ncUbyte
NcUbyte ncUbyte
A global instance of the NcUbyte class within the netCDF namespace.
Definition
ncUbyte.cpp:7
netCDF::ncChar
NcChar ncChar
A global instance of the NcChar class within the netCDF namespace.
Definition
ncChar.cpp:7
netCDF::ncByte
NcByte ncByte
A global instance of the NcByte class within the netCDF namespace.
Definition
ncByte.cpp:7
Return to the Main Unidata NetCDF page.
Generated on
for NetCDF-C++. NetCDF is a
Unidata
library.