bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
NetcdfElement.h
1
2// 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
37namespace libdap {
38class BaseType;
39class DDS;
40}
41
42class BESDapResponse;
43
44namespace ncml_module {
45
48class NCMLParser;
49class VariableElement;
50
62class NetcdfElement: public NCMLElement, // superclass
63 public virtual agg_util::DDSAccessRCInterface // interface
64{
65private:
66 NetcdfElement& operator=(const NetcdfElement& rhs); //disallow
67
68public:
69 static const std::string _sTypeName;
70 static const std::vector<std::string> _sValidAttributes;
71
72 NetcdfElement();
73 NetcdfElement(const NetcdfElement& proto);
74 virtual ~NetcdfElement();
75 virtual const std::string& getTypeName() const;
76 virtual NetcdfElement* clone() const; // override clone with more specific subclass
77 virtual void setAttributes(const XMLAttributeMap& attrs);
78 virtual void handleBegin();
79 virtual void handleContent(const std::string& content);
80 virtual void handleEnd();
81 virtual std::string toString() const;
82
83 // Accessors for attributes we deal with.
84 // TODO Add these as we support aggregation attributes
85 const std::string& location() const
86 {
87 return _location;
88 }
89 const std::string& id() const
90 {
91 return _id;
92 }
93 const std::string& title() const
94 {
95 return _title;
96 }
97 const std::string& coordValue() const
98 {
99 return _coordValue;
100 }
101 const std::string& ncoords() const
102 {
103 return _ncoords;
104 }
105
106 bool hasNcoords() const
107 {
108 return !_ncoords.empty();
109 }
110
116 unsigned int getNcoordsAsUnsignedInt() const;
117
122 bool isValid() const;
123
129 virtual const libdap::DDS* getDDS() const;
130
134 virtual libdap::DDS* getDDS();
135
136 bool getProcessedMetadataDirective() const
137 {
138 return _gotMetadataDirective;
139 }
140
141 void setProcessedMetadataDirective()
142 {
143 _gotMetadataDirective = true;
144 }
145
151
156
163
172
178 const DimensionElement* getDimensionInLocalScope(const std::string& name) const;
179
189 const DimensionElement* getDimensionInFullScope(const std::string& name) const;
190
196
198 std::string printDimensions() const;
199
202
204 const std::vector<DimensionElement*>& getDimensionElements() const;
205
215 void setChildAggregation(AggregationElement* agg, bool throwIfExists = true);
216
220
224 NetcdfElement* getParentDataset() const;
225
228
231
232#if 0 // not sure we need this yet
242 template <typename T> int getCoordValueVector(std::vector<T>& values) const;
243#endif
244
254 bool getCoordValueAsDouble(double& val) const;
255
269 void addVariableToValidateOnClose(libdap::BaseType* pNewVar, VariableElement* pVE);
270
281 void setVariableGotValues(libdap::BaseType* pVarToValidate, bool removeEntry);
282
290
300 static bool isLocationLexicographicallyLessThan(const NetcdfElement* pLHS, const NetcdfElement* pRHS);
301
311 static bool isCoordValueLexicographicallyLessThan(const NetcdfElement* pLHS, const NetcdfElement* pRHS);
312
313private:
314
316 void loadLocation();
317
321 void throwOnUnsupportedAttributes();
322
328 bool validateAttributeContextOrThrow() const;
329
330 static std::vector<std::string> getValidAttributes();
331
332private:
333 std::string _location;
334 std::string _id;
335 std::string _title;
336 std::string _ncoords;
337 std::string _enhance;
338 std::string _addRecords;
339 std::string _coordValue;
340 std::string _fmrcDefinition;
341
342 // Whether we got a metadata direction element { readMetadata | explicit } for this node yet.
343 // Just used to check for more than one.
344 bool _gotMetadataDirective;
345
346 // Whether we own the memory for _response and need to destroy it in dtor or not.
347 bool _weOwnResponse;
348
349 // true after loadLocation has been called.
350 bool _loaded;
351
352 // Our response object
353 // We OWN it if we're not the root element,
354 // but the parser owns it if we are the root.
355 // The parser sets _weOwnResponse correctly for our dtor.
356 BESDapResponse* _response;
357
358 // If non-null, a pointer to the singleton aggregation element for this dataset.
359 // We use an RCPtr to automatically ref() it when we set it
360 // and to unref() it in our dtor.
361 RCPtr<AggregationElement> _aggregation;
362
363 // If we are nested within an aggregation element,
364 // this is a back ptr we can use to traverse upwards.
365 // If it null if we're a root dataset.
366 AggregationElement* _parentAgg;
367
368 // A table of strong references to Dimensions valid for this element's lexical scope.
369 // We use raw DimensionElement*, but ref() them upon adding them to the vector
370 // and unref() them in the dtor.
371 // We won't have that many, so a vector is more efficient than a map for this.
372 std::vector<DimensionElement*> _dimensions;
373
374 // Lazy evaluated, starts unassigned.
375 // When getAggMemberDataset() is called, it is lazy-constructed
376 // to weak ref the returned strong shared ptr (RCPtr).
378
379public:
380 // inner classes can't be private?
411 class VariableValueValidator {
412 public:
413 VariableValueValidator(NetcdfElement* pParent);
414
421
431 void addVariableToValidate(libdap::BaseType* pNewVar, VariableElement* pVE);
432
437 void removeVariableToValidate(libdap::BaseType* pVarToRemove);
438
444 void setVariableGotValues(libdap::BaseType* pVarToValidate);
445
451 bool validate();
452
460
461 private:
462 // disallow implicit copies
463 VariableValueValidator(const VariableValueValidator&);
464 VariableValueValidator& operator=(const VariableValueValidator&);
465
466 public:
467
468 class VVVEntry {
469 public:
470 VVVEntry() :
471 _pNewVar(0), _pVarElt(0)
472 {
473 }
474 VVVEntry(libdap::BaseType* pBT, VariableElement* pVE) :
475 _pNewVar(pBT), _pVarElt(pVE)
476 {
477 }
478 void clear()
479 {
480 _pNewVar = 0;
481 _pVarElt = 0;
482 }
483 libdap::BaseType* _pNewVar;
484 VariableElement* _pVarElt;
485 };
486
487 /********************* helper functions *******************/
488
494 private:
495 VariableValueValidator::VVVEntry* findEntryByLibdapVar(libdap::BaseType* pVarToFind);
496
497 // We don't expect too many entries, so a simple vector is the best way to go,
498 // avoid overhead of maps, etc.
499 std::vector<VVVEntry> _entries;
500 NetcdfElement* _pParent;
501 }; // class VariableValueValidator
502
503private:
504 // The actual instance we will poke from methods in NetcdfElement
505 VariableValueValidator _variableValidator;
506};
507
508}
509
510#endif /* __NCML_MODULE__NETCDF_ELEMENT_H__ */
Represents an OPeNDAP DAP response object within the BES.
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
Definition RCObject.h:284
void removeVariableToValidate(libdap::BaseType *pVarToRemove)
void setVariableGotValues(libdap::BaseType *pVarToValidate)
void addVariableToValidate(libdap::BaseType *pNewVar, VariableElement *pVE)
VariableElement * findVariableElementForLibdapVar(libdap::BaseType *pNewVar)
RCPtr< agg_util::AggMemberDataset > getAggMemberDataset() const
virtual const std::string & getTypeName() const
virtual void handleContent(const std::string &content)
virtual libdap::DDS * getDDS()
virtual void handleBegin()
virtual std::string toString() const
virtual NetcdfElement * clone() const
bool getCoordValueAsDouble(double &val) const
void createResponseObject(agg_util::DDSLoader::ResponseType type)
void unborrowResponseObject(BESDapResponse *pResponse)
void addDimension(DimensionElement *dim)
const DimensionElement * getDimensionInFullScope(const std::string &name) const
virtual void setAttributes(const XMLAttributeMap &attrs)
static bool isLocationLexicographicallyLessThan(const NetcdfElement *pLHS, const NetcdfElement *pRHS)
void setChildAggregation(AggregationElement *agg, bool throwIfExists=true)
AggregationElement * getParentAggregation() const
const DimensionElement * getDimensionInLocalScope(const std::string &name) const
unsigned int getNcoordsAsUnsignedInt() const
void setVariableGotValues(libdap::BaseType *pVarToValidate, bool removeEntry)
void setParentAggregation(AggregationElement *parent)
VariableElement * findVariableElementForLibdapVar(libdap::BaseType *pNewVar)
void addVariableToValidateOnClose(libdap::BaseType *pNewVar, VariableElement *pVE)
const std::vector< DimensionElement * > & getDimensionElements() const
std::string printDimensions() const
void borrowResponseObject(BESDapResponse *pResponse)
virtual const libdap::DDS * getDDS() const
AggregationElement * getChildAggregation() const
static bool isCoordValueLexicographicallyLessThan(const NetcdfElement *pLHS, const NetcdfElement *pRHS)
NetcdfElement * getParentDataset() const
Concrete class for NcML <variable> element.
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...