NetCDF-C++  4.3.1-developer
ncVlenType.cpp
1 #include "ncVlenType.h"
2 #include "ncGroup.h"
3 #include "ncCheck.h"
4 #include "ncException.h"
5 #include "ncByte.h"
6 #include "ncUbyte.h"
7 #include "ncChar.h"
8 #include "ncShort.h"
9 #include "ncUshort.h"
10 #include "ncInt.h"
11 #include "ncUint.h"
12 #include "ncInt64.h"
13 #include "ncUint64.h"
14 #include "ncFloat.h"
15 #include "ncDouble.h"
16 #include "ncString.h"
17 #include <netcdf.h>
18 using namespace std;
19 using namespace netCDF;
20 using namespace netCDF::exceptions;
21 
22 // Class represents a netCDF variable.
23 using namespace netCDF;
24 
25 // assignment operator
26 NcVlenType& NcVlenType::operator=(const NcVlenType& rhs)
27 {
28  NcType::operator=(rhs); // assign base class parts
29  return *this;
30 }
31 
32 // assignment operator
33 NcVlenType& NcVlenType::operator=(const NcType& rhs)
34 {
35  if (&rhs != this) {
36  // check the rhs is the base of an Opaque type
37  if(getTypeClass() != NC_VLEN) throw NcException("The NcType object must be the base of an Vlen type.",__FILE__,__LINE__);
38  // assign base class parts
39  NcType::operator=(rhs);
40  }
41  return *this;
42 }
43 
44 // The copy constructor.
45 NcVlenType::NcVlenType(const NcVlenType& rhs):
46  NcType(rhs)
47 {
48 }
49 
50 
51 // Constructor generates a null object.
53  NcType() // invoke base class constructor
54 {}
55 
56 // constructor
57 NcVlenType::NcVlenType(const NcGroup& grp, const string& name) :
58  NcType(grp,name)
59 {}
60 
61 // constructor
63  NcType(ncType)
64 {
65  // check the nctype object is the base of a Vlen type
66  if(getTypeClass() != NC_VLEN) throw NcException("The NcType object must be the base of a Vlen type.",__FILE__,__LINE__);
67 }
68 
69 // Returns the base type.
71 {
72  char charName[NC_MAX_NAME+1];
73  nc_type base_nc_typep;
74  size_t datum_sizep;
75  ncCheck(nc_inq_vlen(groupId,myId,charName,&datum_sizep,&base_nc_typep),__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 }
Base class inherited by NcOpaque, NcVlen, NcCompound and NcEnum classes.
Definition: ncType.h:14
NcUint64 ncUint64
A global instance of the NcUint64 class within the netCDF namespace.
Definition: ncUint64.cpp:7
int groupId
the group Id
Definition: ncType.h:152
C++ API for netCDF4.
Definition: ncAtt.h:9
NcByte ncByte
A global instance of the NcByte class within the netCDF namespace.
Definition: ncByte.cpp:7
NcType getBaseType() const
Returns the base type.
Definition: ncVlenType.cpp:70
Class represents a netCDF VLEN type.
Definition: ncVlenType.h:14
NcFloat ncFloat
A global instance of the NcFloat class within the netCDF namespace.
Definition: ncFloat.cpp:7
Class represents a netCDF group.
Definition: ncGroup.h:27
ncType
List of netCDF types that can be represented.
Definition: ncType.h:25
Exception classes.
Definition: ncException.h:15
NcUint ncUint
A global instance of the NcUint class within the netCDF namespace.
Definition: ncUint.cpp:7
NcChar ncChar
A global instance of the NcChar class within the netCDF namespace.
Definition: ncChar.cpp:7
nc_type myId
the type Id
Definition: ncType.h:149
NcVlenType()
Constructor generates a null object.
Definition: ncVlenType.cpp:52
NcDouble ncDouble
A global instance of the NcDouble class within the netCDF namespace.
Definition: ncDouble.cpp:7
Base object is thrown if a netCDF exception is encountered.
Definition: ncException.h:24
NcType()
Constructor generates a null object.
Definition: ncType.cpp:44
void ncCheck(int retCode, const char *file, int line)
Function checks error code and if necessary throws an exception.
Definition: ncCheck.cpp:11
NcShort ncShort
A global instance of the NcShort class within the netCDF namespace.
Definition: ncShort.cpp:7
NcString ncString
A global instance of the NcString class within the netCDF namespace.
Definition: ncString.cpp:7
netCDF::NcGroup getParentGroup() const
Gets parent group.
Definition: ncType.cpp:89
NcInt ncInt
A global instance of the NcInt class within the netCDF namespace.
Definition: ncInt.cpp:7
ncType getTypeClass() const
The type class returned as enumeration type.
Definition: ncType.cpp:116
NcUbyte ncUbyte
A global instance of the NcUbyte class within the netCDF namespace.
Definition: ncUbyte.cpp:7
NcInt64 ncInt64
A global instance of the NcInt64 class within the netCDF namespace.
Definition: ncInt64.cpp:7

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