30 #ifndef __NCML_MODULE_NCML_PARSER_H__
31 #define __NCML_MODULE_NCML_PARSER_H__
40 #include <AttrTable.h>
42 #include "DDSLoader.h"
43 #include "NCMLElement.h"
44 #include "SaxParser.h"
45 #include "ScopeStack.h"
46 #include "XMLHelpers.h"
65 class AggregationElement;
66 class DimensionElement;
139 AttrTable* get()
const;
142 void set(AttrTable* pAT);
151 void loadAndSetAttrTable();
154 mutable AttrTable* _pAttrTable;
155 mutable bool _loaded;
218 bool parsing()
const;
221 int getParseLineNumber()
const;
229 virtual void onStartDocument();
230 virtual void onEndDocument();
231 virtual void onStartElement(
const std::string& name,
const XMLAttributeMap& attrs);
232 virtual void onEndElement(
const std::string& name);
234 virtual void onStartElementWithNamespace(
const std::string& localname,
const std::string& prefix,
237 virtual void onEndElementWithNamespace(
const std::string& localname,
const std::string& prefix,
238 const std::string& uri);
240 virtual void onCharacters(
const std::string& content);
241 virtual void onParseWarning(std::string msg);
242 virtual void onParseError(std::string msg);
243 virtual void setParseLineNumber(
int line);
252 bool isScopeAtomicAttribute()
const;
255 bool isScopeAttributeContainer()
const;
258 bool isScopeSimpleVariable()
const;
261 bool isScopeCompositeVariable()
const;
264 bool isScopeVariable()
const;
267 bool isScopeGlobal()
const;
270 bool isScopeNetcdf()
const;
273 bool isScopeAggregation()
const;
278 bool withinNetcdf()
const;
284 bool withinVariable()
const;
312 DDS* getDDSForCurrentDataset()
const;
330 void addChildDatasetToCurrentDataset(
NetcdfElement* dataset);
343 bool parsingDataRequest()
const;
348 void resetParseState();
357 bool isNameAlreadyUsedAtCurrentScope(
const std::string& name);
366 BaseType* getVariableInCurrentVariableContainer(
const string& name);
375 BaseType* getVariableInContainer(
const string& varName, BaseType* pContainer);
384 BaseType* getVariableInDDS(
const string& varName);
400 void addCopyOfVariableAtCurrentScope(BaseType& varTemplate);
406 void deleteVariableAtCurrentScope(
const string& name);
411 BaseType* getCurrentVariable()
const;
417 void setCurrentVariable(BaseType* pVar);
425 static bool typeCheckDAPVariable(
const BaseType& var,
const string& expectedType);
435 AttrTable* getCurrentAttrTable()
const;
442 void setCurrentAttrTable(AttrTable* pAT);
448 AttrTable* getGlobalAttrTable()
const;
454 bool attributeExistsAtCurrentScope(
const string& name)
const;
461 bool findAttribute(
const string& name, AttrTable::Attr_iter& attr)
const;
466 void clearAllAttrTables(DDS* dds);
469 void clearVariableMetadataRecursively(BaseType* var);
476 int tokenizeAttrValues(vector<string>& tokens,
const string& values,
const string& dapAttrTypeName,
477 const string& separator);
487 int tokenizeValuesForDAPType(vector<string>& tokens,
const string& values, AttrType dapType,
488 const string& separator);
497 void printScope()
const;
500 string getScopeString()
const;
503 string getTypedScopeString()
const;
506 int getScopeDepth()
const;
522 typedef std::vector<NCMLElement*>::const_reverse_iterator ElementStackConstIterator;
523 ElementStackConstIterator getElementStackBegin()
const
525 return _elementStack.rbegin();
527 ElementStackConstIterator getElementStackEnd()
const
529 return _elementStack.rend();
535 void clearElementStack();
538 void processStartNCMLElement(
const std::string& name,
const XMLAttributeMap& attrs);
541 void processEndNCMLElement(
const std::string& name);
546 const DimensionElement* getDimensionAtLexicalScope(
const string& dimName)
const;
552 string printAllDimensionsAtLexicalScope()
const;
568 bool isParsingOtherXML()
const;
590 static string convertNcmlTypeToCanonicalType(
const string& ncmlType);
599 void checkDataIsValidForCanonicalTypeOrThrow(
const string& type,
const vector<string>& tokens)
const;
607 static bool sThrowExceptionOnUnknownElements;
645 std::vector<NCMLElement*> _elementStack;
663 int _currentParseLine;