NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcItem.h
Go to the documentation of this file.
1 
13 #ifndef INC_netcdf_NcItem_h
14 #define INC_netcdf_NcItem_h
15 
16 #include <string>
17 #include "NcConfig.h"
18 
19 namespace netcdf {
20 
21 
22 class NcItem
23 {
24  public:
25 
26  enum { idGlobal = NC_GLOBAL };
27  static int const nullID = -999;
28 
29  virtual ~NcItem () = 0;
30 
31  protected:
32 
34  bool const isNullObject = true)
35  : nullObject (isNullObject),
36  myID (nullID),
37  groupID (nullID),
38  fileID (nullID)
39  {
40  }
41 
43  int const useFileID,
44  int const useID,
45  int const useGroupID = NcItem::idGlobal,
46  std::string const useName = std::string() )
47  : nullObject ( false ),
48  myID ( useID ),
49  groupID ( useGroupID == nullID ? NcItem::idGlobal : useGroupID ),
50  fileID ( useFileID ),
51  myName ( useName )
52  {
53  }
54 
55  NcItem ( NcItem const & rhs )
56  {
57  Copy (rhs);
58  }
59 
60  public:
61 
62  bool IsNull() const { return nullObject; }
63  std::string const & GetName() const { return myName; }
64  int GetID() const { return myID; }
65  int GetGroupID() const { return groupID; }
66  int GetFileID() const { return fileID; }
67 
68  virtual void Rename ( std::string const & newName ) = 0;
69 
70  NcItem & operator= ( NcItem const & rhs )
71  {
72  Copy (rhs);
73  return *this;
74  }
75 
76  bool operator== ( NcItem const & rhs ) const
77  {
78  return myID == rhs.myID &&
79  groupID == rhs.groupID &&
80  fileID == rhs.fileID;
81  }
82  bool operator!= (NcItem const & rhs) const { return !operator==(rhs); }
83  bool operator< (NcItem const & rhs) const
84  {
85  if ( groupID == rhs.groupID )
86  return myID < rhs.myID;
87  else
88  return myID < rhs.myID && groupID < rhs.groupID;
89  }
90 
91  protected:
92 
93  bool nullObject;
94  int myID;
95  int groupID;
96  int fileID;
97  std::string myName;
98 
99  void Copy ( NcItem const & rhs )
100  {
101  nullObject = rhs.nullObject;
102  myID = rhs.myID;
103  groupID = rhs.groupID;
104  fileID = rhs.fileID;
105  myName = rhs.myName;
106  }
107 
108 };
109 
110 inline NcItem::~NcItem () {}
111 
112 
113 } // namespace netcdf
114 
115 
116 #endif // INC_netcdf_NcItem_h
int fileID
netCDF file ID number
Definition: NcItem.h:96
NcItem & operator=(NcItem const &rhs)
Definition: NcItem.h:70
void Copy(NcItem const &rhs)
Definition: NcItem.h:99
bool operator==(NcItem const &rhs) const
Definition: NcItem.h:76
NcItem(NcItem const &rhs)
Definition: NcItem.h:55
bool operator!=(NcItem const &rhs) const
Definition: NcItem.h:82
bool operator<(NcItem const &rhs) const
Definition: NcItem.h:83
int GetGroupID() const
Definition: NcItem.h:65
std::string const & GetName() const
Definition: NcItem.h:63
Definition: NcItem.h:26
virtual void Rename(std::string const &newName)=0
int GetFileID() const
Definition: NcItem.h:66
int groupID
group ID number (can be unused)
Definition: NcItem.h:95
std::string myName
optional name of object
Definition: NcItem.h:97
int myID
object ID number
Definition: NcItem.h:94
static int const nullID
Definition: NcItem.h:27
virtual ~NcItem()=0
Definition: NcItem.h:110
NcItem(bool const isNullObject=true)
Definition: NcItem.h:33
bool IsNull() const
Definition: NcItem.h:62
int GetID() const
Definition: NcItem.h:64
bool nullObject
Definition: NcItem.h:93
Base class for NcAtt, NcVar, NcDim, NcGroup.
Definition: NcItem.h:22
NcItem(int const useFileID, int const useID, int const useGroupID=NcItem::idGlobal, std::string const useName=std::string())
Definition: NcItem.h:42