OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
NetcdfElement.h
Go to the documentation of this file.
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2009 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29 #ifndef __NCML_MODULE__NETCDF_ELEMENT_H__
30 #define __NCML_MODULE__NETCDF_ELEMENT_H__
31 
32 #include "AggMemberDataset.h" // agg_util
33 #include "DDSAccessInterface.h"
34 #include "DDSLoader.h"
35 #include "NCMLElement.h"
36 
37 namespace libdap
38 {
39  class BaseType;
40  class DDS;
41 }
42 
43 class BESDapResponse;
44 
45 namespace ncml_module
46 {
47  class AggregationElement;
48  class DimensionElement;
49  class NCMLParser;
50  class VariableElement;
51 
64  : public NCMLElement // superclass
65  , public virtual agg_util::DDSAccessRCInterface // interface
66  {
67  private:
68  NetcdfElement& operator=(const NetcdfElement& rhs); //disallow
69 
70  public:
71  static const string _sTypeName;
72  static const vector<string> _sValidAttributes;
73 
74  NetcdfElement();
75  NetcdfElement(const NetcdfElement& proto);
76  virtual ~NetcdfElement();
77  virtual const string& getTypeName() const;
78  virtual NetcdfElement* clone() const; // override clone with more specific subclass
79  virtual void setAttributes(const XMLAttributeMap& attrs);
80  virtual void handleBegin();
81  virtual void handleContent(const string& content);
82  virtual void handleEnd();
83  virtual string toString() const;
84 
85  // Accessors for attributes we deal with.
86  // TODO Add these as we support aggregation attributes
87  const string& location() const { return _location; }
88  const string& id() const { return _id; }
89  const string& title() const { return _title; }
90  const string& coordValue() const { return _coordValue; }
91  const string& ncoords() const { return _ncoords; }
92 
93  bool hasNcoords() const { return !_ncoords.empty(); }
94 
100  unsigned int getNcoordsAsUnsignedInt() const;
101 
106  bool isValid() const;
107 
113  virtual const libdap::DDS* getDDS() const;
114 
118  virtual libdap::DDS* getDDS();
119 
121  {
122  return _gotMetadataDirective;
123  }
124 
126  {
127  _gotMetadataDirective = true;
128  }
129 
134  void borrowResponseObject(BESDapResponse* pResponse);
135 
139  void unborrowResponseObject(BESDapResponse* pResponse);
140 
147 
156 
162  const DimensionElement* getDimensionInLocalScope(const string& name) const;
163 
173  const DimensionElement* getDimensionInFullScope(const string& name) const;
174 
179  void addDimension(DimensionElement* dim);
180 
182  string printDimensions() const;
183 
185  void clearDimensions();
186 
188  const std::vector<DimensionElement*>& getDimensionElements() const;
189 
199  void setChildAggregation(AggregationElement* agg, bool throwIfExists=true);
200 
204 
209 
212 
215 
216 
217 #if 0 // not sure we need this yet
218 
227  template <typename T> int getCoordValueVector(vector<T>& values) const;
228 #endif
229 
239  bool getCoordValueAsDouble(double& val) const;
240 
254  void addVariableToValidateOnClose(libdap::BaseType* pNewVar, VariableElement* pVE);
255 
256 
267  void setVariableGotValues(libdap::BaseType* pVarToValidate, bool removeEntry);
268 
275  VariableElement* findVariableElementForLibdapVar(libdap::BaseType* pNewVar);
276 
286  static bool isLocationLexicographicallyLessThan(const NetcdfElement* pLHS, const NetcdfElement* pRHS);
287 
297  static bool isCoordValueLexicographicallyLessThan(const NetcdfElement* pLHS, const NetcdfElement* pRHS);
298 
299  private:
300 
302  void loadLocation();
303 
307  void throwOnUnsupportedAttributes();
308 
314  bool validateAttributeContextOrThrow() const;
315 
316  static vector<string> getValidAttributes();
317 
318  private:
319  string _location;
320  string _id;
321  string _title;
322  string _ncoords;
323  string _enhance;
324  string _addRecords;
325  string _coordValue;
326  string _fmrcDefinition;
327 
328  // Whether we got a metadata direction element { readMetadata | explicit } for this node yet.
329  // Just used to check for more than one.
330  bool _gotMetadataDirective;
331 
332  // Whether we own the memory for _response and need to destroy it in dtor or not.
333  bool _weOwnResponse;
334 
335  // true after loadLocation has been called.
336  bool _loaded;
337 
338  // Our response object
339  // We OWN it if we're not the root element,
340  // but the parser owns it if we are the root.
341  // The parser sets _weOwnResponse correctly for our dtor.
342  BESDapResponse* _response;
343 
344  // If non-null, a pointer to the singleton aggregation element for this dataset.
345  // We use an RCPtr to automatically ref() it when we set it
346  // and to unref() it in our dtor.
347  RCPtr<AggregationElement> _aggregation;
348 
349  // If we are nested within an aggregation element,
350  // this is a back ptr we can use to traverse upwards.
351  // If it null if we're a root dataset.
352  AggregationElement* _parentAgg;
353 
354  // A table of strong references to Dimensions valid for this element's lexical scope.
355  // We use raw DimensionElement*, but ref() them upon adding them to the vector
356  // and unref() them in the dtor.
357  // We won't have that many, so a vector is more efficient than a map for this.
358  std::vector< DimensionElement* > _dimensions;
359 
360  // Lazy evaluated, starts unassigned.
361  // When getAggMemberDataset() is called, it is lazy-constructed
362  // to weak ref the returned strong shared ptr (RCPtr).
364 
365  public: // inner classes can't be private?
397  {
398  public:
400 
407 
417  void addVariableToValidate(libdap::BaseType* pNewVar, VariableElement* pVE);
418 
423  void removeVariableToValidate(libdap::BaseType* pVarToRemove);
424 
430  void setVariableGotValues(libdap::BaseType* pVarToValidate);
431 
437  bool validate();
438 
445  VariableElement* findVariableElementForLibdapVar(libdap::BaseType* pNewVar);
446 
447  private:
448  // disallow implicit copies
451 
452  public:
453 
454  class VVVEntry
455  {
456  public:
457  VVVEntry() : _pNewVar(0), _pVarElt(0) { }
458  VVVEntry(libdap::BaseType* pBT, VariableElement* pVE) : _pNewVar(pBT), _pVarElt(pVE) { }
459  void clear() { _pNewVar=0; _pVarElt=0; }
460  libdap::BaseType* _pNewVar;
462  };
463 
464 
465  /********************* helper functions *******************/
466 
472  private:
473  VariableValueValidator::VVVEntry* findEntryByLibdapVar(libdap::BaseType* pVarToFind);
474 
475 
476  // We don't expect too many entries, so a simple vector is the best way to go,
477  // avoid overhead of maps, etc.
478  vector<VVVEntry> _entries;
479  NetcdfElement* _pParent;
480  }; // class VariableValueValidator
481 
482  private:
483  // The actual instance we will poke from methods in NetcdfElement
484  VariableValueValidator _variableValidator;
485  };
486 
487 }
488 
489 #endif /* __NCML_MODULE__NETCDF_ELEMENT_H__ */
~VariableValueValidator()
Will decrement the ref count of all contained VariableElement's.
virtual const string & getTypeName() const
Return the type of the element, which should be: the same as ConcreteClassName::getTypeName() ...
void addVariableToValidateOnClose(libdap::BaseType *pNewVar, VariableElement *pVE)
Add the pNewvar created by pVE to this dataset's list of variables to validate for having values set ...
ResponseType
For telling the loader what type of BESDapResponse to load and return.
Definition: DDSLoader.h:97
virtual string toString() const
Return a string describing the element.
static bool isCoordValueLexicographicallyLessThan(const NetcdfElement *pLHS, const NetcdfElement *pRHS)
Compare the coordvalue fields of the two arguments and return true if lhs.coordValue() < rhs...
const string & location() const
Definition: NetcdfElement.h:87
void setParentAggregation(AggregationElement *parent)
Set my parent AggregationElement to parent.
void addDimension(DimensionElement *dim)
Add the given element to this scope.
void setChildAggregation(AggregationElement *agg, bool throwIfExists=true)
Set our aggregation to the given agg.
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
const string & coordValue() const
Definition: NetcdfElement.h:90
void clearDimensions()
Clear the dimension table, releasing all strong references.
virtual void handleEnd()
Handle the closing of this element.
virtual void handleContent(const string &content)
Handle the characters content for the element.
Concrete class for NcML element.
Definition: NetcdfElement.h:63
virtual const libdap::DDS * getDDS() const
Return the DDS for this dataset, loading it in if needed.
const DimensionElement * getDimensionInLocalScope(const string &name) const
static const vector< string > _sValidAttributes
Definition: NetcdfElement.h:72
static const string _sTypeName
Definition: NetcdfElement.h:71
virtual NetcdfElement * clone() const
Make and return a copy of this.
void setVariableGotValues(libdap::BaseType *pVarToValidate)
Lookup the VariableElement pVE associated with the given pVarToValidate and call pVE->setGotValues() ...
RCPtr< agg_util::AggMemberDataset > getAggMemberDataset() const
Return a shared reference to the AggMemberDataset that encapsulates this dataset. ...
string printDimensions() const
"Print" out the dimensions to a string
bool validate()
Make sure all the entries has had their values set else throw a parse error explaining which variable...
static bool isLocationLexicographicallyLessThan(const NetcdfElement *pLHS, const NetcdfElement *pRHS)
Compare the location fields of the two arguments and return true if lhs.location() < rhs...
Inner class for keeping track of new variables created within the context of this dataset for which w...
static class NCMLUtil overview
const string & id() const
Definition: NetcdfElement.h:88
AggregationElement * getChildAggregation() const
Return the raw pointer (or NULL) to our contained aggregation.
VVVEntry(libdap::BaseType *pBT, VariableElement *pVE)
virtual void handleBegin()
Handle a begin on this element.
Mixture interface for when we a reference-counted DDS container.
const std::vector< DimensionElement * > & getDimensionElements() const
Get the list of dimension elements local to only this dataset, not its enclosing scope.
const string & ncoords() const
Definition: NetcdfElement.h:91
bool getProcessedMetadataDirective() const
const DimensionElement * getDimensionInFullScope(const string &name) const
void removeVariableToValidate(libdap::BaseType *pVarToRemove)
Remove an entry previously added under the key pVarToRemove with addVariableToValidate.
void createResponseObject(agg_util::DDSLoader::ResponseType type)
Called if this is a member of an aggregation (i.e.
unsigned int getNcoordsAsUnsignedInt() const
Get the ncoords() field as a valid size.
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
Definition: RCObject.h:279
bool getCoordValueAsDouble(double &val) const
Parse the netcdf attribute as a double.
VariableElement * findVariableElementForLibdapVar(libdap::BaseType *pNewVar)
If a VariableElement has been associated with a new var to validate, return it.
void setVariableGotValues(libdap::BaseType *pVarToValidate, bool removeEntry)
Lookup the VariableElement* associated with pVarToValidate via a previous addVariableToValidateOnClos...
void unborrowResponseObject(BESDapResponse *pResponse)
Kind of superfluous, but tells this object to clear its reference to pReponse, which had better match...
Base class for NcML element concrete classes.
Definition: NCMLElement.h:64
Represents an OPeNDAP DAP response object within the BES.
Concrete class for NcML element.
virtual void setAttributes(const XMLAttributeMap &attrs)
Set the attributes of this from the map.
AggregationElement * getParentAggregation() const
void addVariableToValidate(libdap::BaseType *pNewVar, VariableElement *pVE)
Add a validation entry for the given VariableElement and the actual variable that it has created and ...
const string & title() const
Definition: NetcdfElement.h:89
NetcdfElement * getParentDataset() const
Return the next enclosing dataset for this, or NULL if we're the root.
void borrowResponseObject(BESDapResponse *pResponse)
Used by the NCMLParser to let us know to borrow the response object and not own it.
VariableElement * findVariableElementForLibdapVar(libdap::BaseType *pNewVar)
If a VariableElement has been associated with a new var to validate, return it.