bes  Updated for version 3.20.5
FoDapCovJsonTransform.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 //
3 // FoDapCovJsonTransform.h
4 //
5 // This file is part of BES CovJSON File Out Module
6 //
7 // Copyright (c) 2018 OPeNDAP, Inc.
8 // Author: Corey Hemphill <hemphilc@oregonstate.edu>
9 // Author: River Hendriksen <hendriri@oregonstate.edu>
10 // Author: Riley Rimer <rrimer@oregonstate.edu>
11 //
12 // Adapted from the File Out JSON module implemented by Nathan Potter
13 //
14 // This library is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU Lesser General Public
16 // License as published by the Free Software Foundation; either
17 // version 2.1 of the License, or (at your option) any later version.
18 //
19 // This library is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 // Lesser General Public License for more details.
23 //
24 // You should have received a copy of the GNU Lesser General Public
25 // License along with this library; if not, write to the Free Software
26 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 //
28 
29 #ifndef FODAPNJSONTRANSFORM_H_
30 #define FODAPNJSONTRANSFORM_H_
31 
32 #include <string>
33 #include <vector>
34 #include <map>
35 
36 #include <BESObj.h>
37 
38 namespace libdap {
39 class BaseType;
40 class DDS;
41 class Array;
42 }
43 
45 
52 private:
53  libdap::DDS *_dds;
54  std::string _returnAs;
55  std::string _indent_increment;
56  std::string atomicVals;
57  std::string currDataType;
58  int domainType;
59  bool xExists;
60  bool yExists;
61  bool zExists;
62  bool tExists;
63  bool isParam;
64  bool isAxis;
65  bool canConvertToCovJson;
66 
67  struct Axis {
68  std::string name;
69  std::string values;
70  };
71 
72  struct Parameter {
73  std::string id;
74  std::string name;
75  std::string type;
76  std::string dataType;
77  std::string unit;
78  std::string longName;
79  std::string standardName;
80  std::string shape;
81  std::string values;
82  };
83 
84  unsigned int axisCount;
85  std::vector<Axis *> axes;
86  unsigned int parameterCount;
87  std::vector<Parameter *> parameters;
88 #if 0
89  // not used
90  unsigned int shapeValsCount;
91 #endif
92 
93  std::vector<int> shapeVals;
94 
95  enum domains { Grid = 0, VerticalProfile = 1, PointSeries = 2, Point = 3, CoverageCollection = 4 };
96 
97  bool canConvert();
98 
99  void getAttributes(std::ostream *strm, libdap::AttrTable &attr_table, std::string name,
100  bool *axisRetrieved, bool *parameterRetrieved);
101 
102  void transform(std::ostream *strm, libdap::DDS *dds, std::string indent, bool sendData, bool testOverride);
103  void transform(std::ostream *strm, libdap::BaseType *bt, std::string indent, bool sendData);
104  void transform(std::ostream *strm, libdap::Constructor *cnstrctr, std::string indent, bool sendData);
105  void transform(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
106 
107  void transformAtomic(libdap::BaseType *bt, std::string indent, bool sendData);
108  void transformNodeWorker(std::ostream *strm, vector<libdap::BaseType *> leaves, vector<libdap::BaseType *> nodes,
109  string indent, bool sendData);
110 
111  void printCoverageHeaderWorker(std::ostream *strm, std::string indent, bool isCoverageCollection);
112  void printAxesWorker(std::ostream *strm, std::string indent);
113  void printReferenceWorker(std::ostream *strm, std::string indent);
114  void printParametersWorker(std::ostream *strm, std::string indent);
115  void printRangesWorker(std::ostream *strm, std::string indent);
116  void printCoverageFooterWorker(std::ostream *strm, std::string indent);
117  void printCoverageJSON(std::ostream *strm, string indent, bool testOverride);
118 
119  template<typename T>
120  void covjsonSimpleTypeArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
121  void covjsonStringArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
122 
123  template<typename T>
124  unsigned int covjsonSimpleTypeArrayWorker(std::ostream *strm, T *values, unsigned int indx,
125  std::vector<unsigned int> *shape, unsigned int currentDim);
126 
127  // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
128  void addAxis(std::string name, std::string values) {
129  struct Axis *newAxis = new Axis;
130 
131  newAxis->name = name;
132  newAxis->values = values;
133 
134  this->axes.push_back(newAxis);
135  this->axisCount++;
136  }
137 
138  void addParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
139  std::string longName, std::string standardName, std::string shape, std::string values) {
140  struct Parameter *newParameter = new Parameter;
141 
142  newParameter->id = id;
143  newParameter->name = name;
144  newParameter->type = type;
145  newParameter->dataType = dataType;
146  newParameter->unit = unit;
147  newParameter->longName = longName;
148  newParameter->standardName = standardName;
149  newParameter->shape = shape;
150  newParameter->values = values;
151 
152  this->parameters.push_back(newParameter);
153  this->parameterCount++;
154  }
155 
156  void setAxesExistence(bool x, bool y, bool z, bool t) {
157  this->xExists = x;
158  this->yExists = y;
159  this->zExists = z;
160  this->tExists = t;
161  }
162 
163  void setDomainType(int domainType) {
164  this->domainType = domainType;
165  }
166  // ---------------------------------------------------------------------------------------------------------
167 
168 public:
169  // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
170  FoDapCovJsonTransform(libdap::DDS *dds);
171 
172  virtual ~FoDapCovJsonTransform()
173  {
174  for (std::vector<Axis*>::const_iterator i = axes.begin(); i != axes.end(); ++i)
175  delete (*i);
176 
177  for (std::vector<Parameter *>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
178  delete (*i);
179  }
180 
181  virtual void transform(std::ostream &ostrm, bool sendData, bool testOverride);
182 
183  virtual void dump(std::ostream &strm) const;
184 
185  virtual void addTestAxis(std::string name, std::string values) {
186  addAxis(name, values);
187  }
188 
189  virtual void addTestParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
190  std::string longName, std::string standardName, std::string shape, std::string values) {
191  addParameter(id, name, type, dataType, unit, longName, standardName, shape, values);
192  }
193 
194  virtual void setTestAxesExistence(bool x, bool y, bool z, bool t) {
195  setAxesExistence(x, y, z, t);
196  }
197 
198  virtual void setTestDomainType(int domainType) {
199  setDomainType(domainType);
200  }
201 
202  virtual void printCoverageHeaderWorker(std::ostream &ostrm, std::string indent, bool isCoverageCollection) {
203  printCoverageHeaderWorker(&ostrm, indent, isCoverageCollection);
204  }
205 
206  virtual void printAxesWorker(std::ostream &ostrm, std::string indent) {
207  printAxesWorker(&ostrm, indent);
208  }
209 
210  virtual void printReferenceWorker(std::ostream &ostrm, std::string indent) {
211  printReferenceWorker(&ostrm, indent);
212  }
213 
214  virtual void printParametersWorker(std::ostream &ostrm, std::string indent) {
215  printParametersWorker(&ostrm, indent);
216  }
217 
218  virtual void printRangesWorker(std::ostream &ostrm, std::string indent) {
219  printRangesWorker(&ostrm, indent);
220  }
221 
222  virtual void printCoverageFooterWorker(std::ostream &ostrm, std::string indent) {
223  printCoverageFooterWorker(&ostrm, indent);
224  }
225  // ---------------------------------------------------------------------------------------------------------
226 };
227 
228 #endif /* FODAPCOVJSONTRANSFORM_H_ */
FoDapCovJsonTransform::FoDapCovJsonTransform
FoDapCovJsonTransform(libdap::DDS *dds)
Get the CovJSON encoding for a DDS.
Definition: FoDapCovJsonTransform.cc:766
libdap
Definition: BESDapFunctionResponseCache.h:35
FoDapCovJsonTransform::dump
virtual void dump(std::ostream &strm) const
Dumps information about this transformation object for debugging purposes.
Definition: FoDapCovJsonTransform.cc:785
BESObj
Base object for bes objects.
Definition: BESObj.h:51
FoDapCovJsonTransform
Definition: FoDapCovJsonTransform.h:51
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:60