bes  Updated for version 3.20.6
ValuesElement.h
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__VALUESELEMENT_H__
30 #define __NCML_MODULE__VALUESELEMENT_H__
31 
32 #include "NCMLElement.h"
33 #include "NCMLDebug.h"
34 #include <sstream>
35 #include <string>
36 #include <vector>
37 
38 namespace libdap {
39 class Array;
40 class BaseType;
41 }
42 
43 namespace ncml_module {
44 class NCMLParser;
45 class VariableElement;
46 
47 class ValuesElement: public NCMLElement {
48 private:
49  ValuesElement& operator=(const ValuesElement& rhs); // disallow
50 
51 public:
52  static const std::string _sTypeName;
53  static const std::vector<std::string> _sValidAttributes;
54 
55  ValuesElement();
56  ValuesElement(const ValuesElement& proto);
57  virtual ~ValuesElement();
58  virtual const std::string& getTypeName() const;
59  virtual ValuesElement* clone() const; // override clone with more specific subclass
60  virtual void setAttributes(const XMLAttributeMap& attrs);
61  virtual void handleBegin();
62  virtual void handleContent(const std::string& content);
63  virtual void handleEnd();
64  virtual std::string toString() const;
65 
66 private:
67  // Methods
68 
73  bool shouldAutoGenerateValues() const
74  {
75  return ((!_start.empty()) && (!_increment.empty()));
76  }
77 
83  void validateStartAndIncrementForVariableTypeOrThrow(libdap::BaseType& var) const;
84 
95  void setVariableValuesFromTokens(NCMLParser& p, libdap::BaseType& var);
96 
104  void setScalarVariableValuesFromTokens(NCMLParser& p, libdap::BaseType& var);
105 
119  void setVectorVariableValuesFromTokens(NCMLParser& p, libdap::BaseType& var);
120 
130  template<typename DAPType> void generateAndSetVectorValues(NCMLParser& p, libdap::Array* pArray);
131 
137  void autogenerateAndSetVariableValues(NCMLParser& p, libdap::BaseType& var);
138 
148  template<class DAPType, typename ValueType> void setScalarValue(libdap::BaseType& var, const std::string& valueAsToken);
149 
160  template<typename DAPType> void setVectorValues(libdap::Array* pArray, const std::vector<std::string>& valueTokens);
161 
163  void parseAndSetCharValue(libdap::BaseType& var, const std::string& valueAsToken);
164 
169  void parseAndSetCharValueArray(NCMLParser& p, libdap::Array* pVecVar, const std::vector<std::string>& tokens);
170 
175  std::string getNCMLTypeForVariable(NCMLParser& p) const;
176 
178  const VariableElement* getContainingVariableElement(NCMLParser& p) const;
179 
181  void setGotValuesOnOurVariableElement(NCMLParser& p);
182 
186  void dealWithEmptyStringValues();
187 
188  static std::vector<std::string> getValidAttributes();
189 
190 private:
191  // Data Rep
192  std::string _start;
193  std::string _increment;
194  std::string _separator; // defaults to whitespace
195 
196  // If we got handleContent successfully!
197  bool _gotContent;
198 
199  //TODO add comment
200  std::string _accumulated_content;
201  // Temp to tokenize the content on handleContent()
202  std::vector<std::string> _tokens;
203 };
204 
205 }
206 
207 #endif /* __NCML_MODULE__VALUESELEMENT_H__ */
ncml_module::ValuesElement::clone
virtual ValuesElement * clone() const
Definition: ValuesElement.cc:87
ncml_module::ValuesElement::handleContent
virtual void handleContent(const std::string &content)
Definition: ValuesElement.cc:148
ncml_module::NCMLParser
Definition: NCMLParser.h:158
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:93
ncml_module::ValuesElement::toString
virtual std::string toString() const
Definition: ValuesElement.cc:277
ncml_module::ValuesElement
Definition: ValuesElement.h:47
libdap
Definition: BESDapFunctionResponseCache.h:35
ncml_module::VariableElement
Concrete class for NcML <variable> element.
Definition: VariableElement.h:58
ncml_module::ValuesElement::setAttributes
virtual void setAttributes(const XMLAttributeMap &attrs)
Definition: ValuesElement.cc:92
ncml_module::ValuesElement::getTypeName
virtual const std::string & getTypeName() const
Definition: ValuesElement.cc:81
ncml_module::NCMLElement
Base class for NcML element concrete classes.
Definition: NCMLElement.h:61
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
ncml_module::ValuesElement::handleBegin
virtual void handleBegin()
Definition: ValuesElement.cc:111
ncml_module::ValuesElement::handleEnd
virtual void handleEnd()
Definition: ValuesElement.cc:216