NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcGroup.h
Go to the documentation of this file.
1 
16 #ifndef INC_netcdf_NcGroup_h
17 #define INC_netcdf_NcGroup_h
18 
19 #include "NcItem.h"
20 #include "NcType.h"
21 #include "NcEnumType.h"
22 #include "NcGroupAtt.h"
23 #include <vector>
24 #include <set>
25 #include <map>
26 
27 namespace netcdf {
28 
29  class NcVar;
30  class NcDim;
31  class NcVlenType;
32  class NcCompoundType;
33  class NcOpaqueType;
34 
35 
36 class NcGroup : public NcItem
37 {
38 
39  public:
40 
42  {
49  };
50 
51  enum Location
52  {
58  All
59  };
60 
61  typedef std::map<std::string, NcGroup> NcGroupMapUnique;
62  typedef std::multimap<std::string, NcGroup> NcGroupMap;
63  typedef std::pair<std::string, NcGroup> NcGroupPair;
64  typedef std::set<NcGroup> NcGroupSet;
65  typedef std::multimap<std::string, NcType> NcTypeMap;
66  typedef std::pair<std::string, NcType> NcTypePair;
67  typedef std::set<NcType> NcTypeSet;
68  typedef std::multimap<std::string, NcTypeUserDef> NcUserTypeMap;
69  typedef std::multimap<std::string, NcVar> NcVarMap;
70  typedef std::pair<std::string, NcVar> NcVarPair;
71  typedef std::set<NcVar> NcVarSet;
72  typedef std::multimap<std::string, NcDim> NcDimMap;
73  typedef std::pair<std::string, NcDim> NcDimPair;
74  typedef std::set<NcDim> NcDimSet;
75  typedef std::multimap<std::string, NcGroupAtt> NcGroupAttMap;
76  typedef std::pair<std::string, NcGroupAtt> NcGroupAttPair;
77  typedef std::set<NcGroupAtt> NcGroupAttSet;
78 
79 
80  NcGroup();
81 
82  NcGroup(
83  int const useFileID,
84  int const groupId,
85  std::string const groupName);
86 
87  NcGroup(NcGroup const & rhs);
88 
89  virtual ~NcGroup();
90 
91  // NcGroup & operator= (NcGroup const & rhs); // not implemented
92  bool operator< ( NcGroup const & rhs) const;
93 
100  std::string GetName(bool fullName=false) const;
101 
107  NcGroup GetParentGroup() const;
108 
115  int GetGroupCount(
116  NcGroup::GroupLocation location=ChildrenGrps) const;
117 
125  NcGroup::GroupLocation location = ChildrenGrps ) const;
126 
135  std::string const name,
136  NcGroup::GroupLocation location=ChildrenGrps) const;
137 
147  NcGroup GetGroup (
148  std::string const name,
149  NcGroup::GroupLocation location=ChildrenGrps) const;
150 
157  NcGroup AddGroup (std::string const name) const;
158 
160  bool IsRootGroup () const;
161 
162  //-----------------------------------------------------------------------
163  // variables
164  //-----------------------------------------------------------------------
165 
171  int GetVarCount (NcGroup::Location location=Current) const;
172 
179  bool HaveVariable (
180  std::string const name,
181  NcGroup::Location const location = Current) const;
182 
188  NcVarMap GetVars (NcGroup::Location location=Current) const;
189 
196  NcVarSet GetVars (
197  std::string const name,
198  NcGroup::Location location=Current) const;
199 
208  NcVar GetVar (
209  std::string const name,
210  NcGroup::Location location=Current) const;
211 
213  NcVar AddVar(std::string const name, std::string const typeName) const;
214 
216  NcVar AddVar(std::string const name, NcType const & ncType) const;
217 
228  NcVar AddVar (
229  std::string const name,
230  std::string const typeName,
231  std::string const dimName) const;
232 
243  NcVar AddVar (
244  std::string const name,
245  NcType const & ncType,
246  const NcDim& ncDim) const;
247 
258  NcVar AddVar (
259  std::string const name,
260  std::string const typeName,
261  const std::vector<std::string>& dimNames) const;
262 
273  NcVar AddVar (
274  std::string const name,
275  NcType const & ncType,
276  const std::vector<NcDim>& ncDimVector) const;
277 
283  NcVar AddVar (NcVar const & var);
284 
285  //-----------------------------------------------------------------------
286  // attributes
287  //-----------------------------------------------------------------------
288 
294  int GetAttCount (NcGroup::Location const location = Current) const;
295 
302  bool HaveAttribute (
303  std::string const name,
304  NcGroup::Location const location = Current) const;
305 
306  private:
307 
308  bool HaveAttribute ( // helper function for public HaveAttribute
309  std::string const & name, // name to search for
310  int const ncid, // group ID to search in
311  size_t & attLength) const; // attribute length
312 
313  public:
314 
321 
329  std::string const name,
330  NcGroup::Location location=Current) const;
331 
341  std::string const name,
342  NcGroup::Location location=Current) const;
343 
344  // NcUbyte
345  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const unsigned char* dataValues ) const;
346 
347  // NcByte
348  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const signed char* dataValues ) const;
349 
350  // NcChar
351  NcGroupAtt PutAtt ( std::string const name, char const aChar ) const;
352 
353  // NcShort
354  NcGroupAtt PutAtt ( std::string const name, NcType const & type, short datumValue ) const;
355  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const short* dataValues ) const;
356 
357  // NcUshort
358  NcGroupAtt PutAtt ( std::string const name, NcType const & type, unsigned short datumValue ) const;
359  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const unsigned short* dataValues ) const;
360 
361  // NcInt as int
362  NcGroupAtt PutAtt ( std::string const name, NcType const & type, int datumValue ) const;
363  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const int* dataValues ) const;
364 
365  // NcInt as long
366  NcGroupAtt PutAtt ( std::string const name, NcType const & type, long datumValue ) const;
367  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const long* dataValues ) const;
368 
369  // NcUint as int
370  NcGroupAtt PutAtt ( std::string const name, NcType const & type, unsigned int datumValue ) const;
371  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const unsigned int* dataValues ) const;
372 
373  // NcUint as long
374 
375  // NcFloat
376  NcGroupAtt PutAtt ( std::string const name, NcType const & type, float datumValue ) const;
377  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const float* dataValues ) const;
378 
379  // NcDouble
380  NcGroupAtt PutAtt ( std::string const name, NcType const & type, double datumValue ) const;
381  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const double* dataValues ) const;
382 
383  // NcInt64
384  NcGroupAtt PutAtt ( std::string const name, NcType const & type, long long datumValue ) const;
385  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const long long* dataValues ) const;
386 
387  // NcUint64
388  NcGroupAtt PutAtt ( std::string const name, NcType const & type, unsigned long long datumValue ) const;
389  NcGroupAtt PutAtt ( std::string const name, NcType const & type, size_t len, const unsigned long long* dataValues ) const;
390 
391  // NcString
392  NcGroupAtt PutAtt ( std::string const name, size_t len, const char** dataValues ) const;
393  NcGroupAtt PutAtt ( std::string const name, std::string const & dataValues ) const;
394  NcGroupAtt PutAtt (std::string const name, std::vector< std::string > const & strVec );
395 
411  NcGroupAtt PutAtt (std::string const name, NcType const & type, size_t len, const void* dataValues) const;
412 
414 
420  /*
421  template< class TAttValue >
422  NcGroupAtt PutAtt ( std::string const name, std::vector<TAttValue> data )
423  {
424  return PutAtt( name, )
425  }
426  */
427 
433  NcGroupAtt PutAtt ( NcGroupAtt const & att );
434 
435  //-----------------------------------------------------------------------
436  // dimensions
437  //-----------------------------------------------------------------------
438 
444  int GetDimCount (NcGroup::Location const location=Current) const;
445 
451  NcDimMap GetDims (NcGroup::Location const location=Current) const;
452 
459  NcDimSet GetDims (std::string const name, NcGroup::Location const location=Current) const;
460 
468  NcDim GetDim (std::string const name, NcGroup::Location const location=Current) const;
469 
477  NcDim AddDim (std::string const name, size_t const dimSize) const;
478 
484  NcDim AddDim (std::string const name) const;
485 
491  NcDim AddDim (NcDim const & dim) const;
492 
493  //-----------------------------------------------------------------------
494  // types
495  //-----------------------------------------------------------------------
496 
502  int GetTypeCount (NcGroup::Location location=Current) const;
503 
510  int GetTypeCount(
511  NcType::ncType enumType,
512  NcGroup::Location location=Current) const;
513 
521  NcGroup::Location location=Current) const;
522 
531  std::string const & name,
532  NcGroup::Location location=Current) const;
533 
541  NcType::ncType enumType,
542  NcGroup::Location location=Current) const;
543 
553  std::string const & name,
554  NcType::ncType enumType,
555  NcGroup::Location location=Current) const;
556 
566  NcType GetType (
567  std::string const & name,
568  NcGroup::Location location=Current) const;
569 
578  std::string const name,
579  NcEnumType::ncEnumType basetype) const;
580 
588  std::string const name,
589  NcType& basetype) const;
590 
591 
599  std::string const name,
600  size_t size) const;
601 
609  std::string const name,
610  size_t size) const;
611 
624 
634  void GetCoordVar (std::string& coordVarName, NcDim& ncDim, NcVar& ncVar, NcGroup::Location location=Current) const;
635 
636 
637  protected:
638 
639  virtual void Rename (std::string const &) {} // no-op
640 
641 
642 }; // class NcGroup
643 
644 
645 inline NcGroup::~NcGroup() {}
646 
647 
648 
649 } // namespace netcdf
650 
651 #endif
NcVlenType AddVlenType(std::string const name, NcType &basetype) const
Definition: NcGroup.cpp:1514
NcGroup GetParentGroup() const
Definition: NcGroup.cpp:104
ncType
Definition: NcType.h:56
std::set< NcGroupAtt > NcGroupAttSet
Definition: NcGroup.h:77
bool IsRootGroup() const
Definition: NcGroup.cpp:99
ncEnumType
Definition: NcEnumType.h:32
void GetCoordVar(std::string &coordVarName, NcDim &ncDim, NcVar &ncVar, NcGroup::Location location=Current) const
Definition: NcGroup.cpp:1587
Select from set of parent groups(includes the current group).
Definition: NcGroup.h:48
Select from contents of parents groups.
Definition: NcGroup.h:55
Select from contents of current and parents groups.
Definition: NcGroup.h:57
std::set< NcVar > NcVarSet
Definition: NcGroup.h:71
std::pair< std::string, NcDim > NcDimPair
Definition: NcGroup.h:73
NcDim GetDim(std::string const name, NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:1204
Represents a netCDF dimension.
Definition: NcDim.h:26
NcType GetType(std::string const &name, NcGroup::Location location=Current) const
Definition: NcGroup.cpp:1474
std::set< NcDim > NcDimSet
Definition: NcGroup.h:74
std::map< std::string, NcGroup > NcGroupMapUnique
Definition: NcGroup.h:61
NcVarMap GetVars(NcGroup::Location location=Current) const
Definition: NcGroup.cpp:337
bool operator<(NcGroup const &rhs) const
Definition: NcGroup.cpp:49
Represents a netCDF enum type.
Definition: NcEnumType.h:27
std::string const & GetName() const
Definition: NcItem.h:63
std::multimap< std::string, NcVar > NcVarMap
Definition: NcGroup.h:69
Represents a netCDF VLEN type.
Definition: NcVlenType.h:25
Select from contents of current and child groups.
Definition: NcGroup.h:58
int GetDimCount(NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:1122
Represents a netCDF opaque type.
Definition: NcOpaqueType.h:25
int GetAttCount(NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:618
virtual void Rename(std::string const &)
Definition: NcGroup.h:639
Location
options for selecting groups.
Definition: NcGroup.h:51
NcGroup AddGroup(std::string const name) const
Definition: NcGroup.cpp:259
Definition: NcGroup.h:53
NcVar GetVar(std::string const name, NcGroup::Location location=Current) const
Definition: NcGroup.cpp:412
Select from set of parent groups (excludes the current group).
Definition: NcGroup.h:45
NcGroupMap GetGroups(NcGroup::GroupLocation location=ChildrenGrps) const
Definition: NcGroup.cpp:165
NcGroupMapUnique GetCoordVars(Location location=Current) const
Definition: NcGroup.cpp:1544
NcGroupAtt PutAtt(std::string const name, NcType const &type, size_t len, const unsigned char *dataValues) const
Definition: NcGroup.cpp:802
NcVar AddVar(std::string const name, std::string const typeName) const
Add a scalar variable of a specified type name.
Definition: NcGroup.cpp:479
NcDimMap GetDims(NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:1157
bool HaveVariable(std::string const name, NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:319
std::set< NcType > NcTypeSet
Definition: NcGroup.h:67
NcOpaqueType AddOpaqueType(std::string const name, size_t size) const
Definition: NcGroup.cpp:1524
Represents a netCDF variable.
Definition: NcVar.h:43
std::multimap< std::string, NcTypeUserDef > NcUserTypeMap
Definition: NcGroup.h:68
std::multimap< std::string, NcDim > NcDimMap
Definition: NcGroup.h:72
std::pair< std::string, NcGroup > NcGroupPair
Definition: NcGroup.h:63
Represents a netCDF compound type.
Definition: NcCompoundType.h:28
virtual ~NcGroup()
Definition: NcGroup.h:645
std::multimap< std::string, NcType > NcTypeMap
Definition: NcGroup.h:65
bool HaveAttribute(std::string const name, NcGroup::Location const location=Current) const
Definition: NcGroup.cpp:670
Select from set of all children of the current group and beneath.
Definition: NcGroup.h:47
Select from contents of children groups.
Definition: NcGroup.h:56
std::pair< std::string, NcType > NcTypePair
Definition: NcGroup.h:66
Select from the set of children in the current group.
Definition: NcGroup.h:44
Represents a netCDF group attribute.
Definition: NcGroupAtt.h:26
Select from set of all children of children in the current group.
Definition: NcGroup.h:46
Select from contents of current group.
Definition: NcGroup.h:54
NcCompoundType AddCompoundType(std::string const name, size_t size) const
Definition: NcGroup.cpp:1534
std::pair< std::string, NcVar > NcVarPair
Definition: NcGroup.h:70
std::set< NcGroup > NcGroupSet
Definition: NcGroup.h:64
NcEnumType AddEnumType(std::string const name, NcEnumType::ncEnumType basetype) const
Definition: NcGroup.cpp:1504
Definition: NcGroup.h:43
int GetGroupCount(NcGroup::GroupLocation location=ChildrenGrps) const
Definition: NcGroup.cpp:120
int GetVarCount(NcGroup::Location location=Current) const
Definition: NcGroup.cpp:277
NcDim AddDim(std::string const name, size_t const dimSize) const
Definition: NcGroup.cpp:1233
NcGroupAttMap GetAttributes(NcGroup::Location location=Current) const
Definition: NcGroup.cpp:711
NcGroup GetGroup(std::string const name, NcGroup::GroupLocation location=ChildrenGrps) const
Definition: NcGroup.cpp:230
NcGroup()
null group
Definition: NcGroup.cpp:56
Base class for NcAtt, NcVar, NcDim, NcGroup.
Definition: NcItem.h:22
Base class for all netCDF data types.
Definition: NcType.h:47
std::multimap< std::string, NcGroup > NcGroupMap
Definition: NcGroup.h:62
std::pair< std::string, NcGroupAtt > NcGroupAttPair
Definition: NcGroup.h:76
int GetTypeCount(NcGroup::Location location=Current) const
Definition: NcGroup.cpp:1267
GroupLocation
options for selecting groups (used for returned set of NcGroup objects)
Definition: NcGroup.h:41
NcTypeMap GetTypes(NcGroup::Location location=Current) const
Definition: NcGroup.cpp:1356
Represents a netCDF group.
Definition: NcGroup.h:36
std::multimap< std::string, NcGroupAtt > NcGroupAttMap
Definition: NcGroup.h:75
NcGroupAtt GetAtt(std::string const name, NcGroup::Location location=Current) const
Definition: NcGroup.cpp:768