OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
VariableAggElement.cc
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 #include "VariableAggElement.h"
30 #include "AggregationElement.h"
31 #include "NCMLDebug.h"
32 #include "NCMLParser.h"
33 #include "NCMLUtil.h"
34 
35 namespace ncml_module
36 {
37  const string VariableAggElement::_sTypeName = "variableAgg";
38  const vector<string> VariableAggElement::_sValidAttributes = getValidAttributes();
39 
41  : RCObjectInterface()
42  , NCMLElement(0)
43  , _name("")
44  {
45  }
46 
48  : RCObjectInterface()
49  , NCMLElement(proto)
50  , _name(proto._name)
51  {
52  }
53 
55  {
56  _name.clear();
57  }
58 
59  const string&
61  {
62  return _sTypeName;
63  }
64 
67  {
68  return new VariableAggElement(*this);
69  }
70 
71  void
73  {
75  _name = attrs.getValueForLocalNameOrDefault("name", "");
76  }
77 
78  void
80  {
82 
83  // Make sure the name is not empty or this is uselss.
84  if (_name.empty())
85  {
87  "Cannot have variableAgg@name empty! Scope=" + _parser->getScopeString());
88  }
89 
90  // Also make sure we are the direct child of an aggregation or it's an error as well!
91  if (!_parser->isScopeAggregation())
92  {
95  "Got a variableAgg element not as a direct child of an aggregation! elt=" + toString() +
96  " at scope=" + _parser->getScopeString() );
97  }
98 
100  parentAgg.addAggregationVariable(_name);
101  parentAgg.setVariableAggElement(); // let the agg know we're adding to it.
102  }
103 
104  void
106  {
107  }
108 
109  string
111  {
112  return (string("<") + _sTypeName +
113  printAttributeIfNotEmpty("name", _name) +
114  "/>");
115  }
116 
119  {
120  AggregationElement* pAgg = dynamic_cast<AggregationElement*>(_parser->getCurrentElement());
121  NCML_ASSERT_MSG(pAgg,
122  "VariableAggElement::getParentAggregation(): "
123  "Expected current top of stack was AggregationElement*, but it wasn't! Logic error!");
124  return *pAgg;
125  }
126 
128 
129  vector<string>
130  VariableAggElement::getValidAttributes()
131  {
132  vector<string> validAttrs;
133  validAttrs.reserve(1);
134  validAttrs.push_back("name");
135  return validAttrs;
136  }
137 }
virtual void setAttributes(const XMLAttributeMap &attrs)
Set the attributes of this from the map.
virtual bool validateAttributes(const XMLAttributeMap &attrs, const vector< string > &validAttrs, vector< string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
Check that the given attributes are all in the valid set, otherwise fill in *pInvalidAttrs with the p...
Definition: NCMLElement.cc:191
virtual const string & getTypeName() const
Return the type of the element, which should be: the same as ConcreteClassName::getTypeName() ...
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
void setVariableAggElement()
Should only be used by the VariableAggElement class to let us know it added the vars.
virtual void handleBegin()
Handle a begin on this element.
const string getValueForLocalNameOrDefault(const string &localname, const string &defVal="") const
If there is an attribute with localname, return its value, else return default.
Definition: XMLHelpers.cc:209
static const vector< string > _sValidAttributes
#define NCML_ASSERT_MSG(cond, msg)
Definition: NCMLDebug.h:83
virtual void handleEnd()
Handle the closing of this element.
int getParseLineNumber() const
Get the line of the NCML file the parser is currently parsing.
Definition: NCMLParser.cc:222
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
Helper for subclasses implementing toString().
Definition: NCMLElement.cc:240
#define THROW_NCML_PARSE_ERROR(parseLine, msg)
Definition: NCMLDebug.h:69
Base class for NcML element concrete classes.
Definition: NCMLElement.h:64
virtual VariableAggElement * clone() const
Make and return a copy of this.
AggregationElement & getParentAggregation() const
Get our parent aggregation off the parser stack.
#define VALID_PTR(ptr)
Definition: NCMLDebug.h:88
void addAggregationVariable(const string &name)
Set the variable with name as an aggregation variable for this aggregation.
Element for the element child of an .
virtual string toString() const
Return a string describing the element.