bes  Updated for version 3.20.6
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  std::string coordRefType;
59  std::string domainType;
60  bool xExists;
61  bool yExists;
62  bool zExists;
63  bool tExists;
64  bool isParam;
65  bool isAxis;
66  bool canConvertToCovJson;
67 
68  struct Axis {
69  std::string name;
70  std::string values;
71  };
72 
73  struct Parameter {
74  std::string id;
75  std::string name;
76  std::string type;
77  std::string dataType;
78  std::string unit;
79  std::string longName;
80  std::string standardName;
81  std::string shape;
82  std::string values;
83  };
84 
85  unsigned int axisCount;
86  std::vector<Axis *> axes;
87  unsigned int parameterCount;
88  std::vector<Parameter *> parameters;
89  std::vector<int> shapeVals;
90 
102  bool canConvert();
103 
125  void getAttributes(std::ostream *strm, libdap::AttrTable &attr_table, std::string name,
126  bool *axisRetrieved, bool *parameterRetrieved);
127 
136  string sanitizeTimeOriginString(std::string timeOrigin);
137 
153  void transform(std::ostream *strm, libdap::DDS *dds, std::string indent, bool sendData, bool testOverride);
154 
167  void transform(std::ostream *strm, libdap::BaseType *bt, std::string indent, bool sendData);
168 
186  void transform(std::ostream *strm, libdap::Constructor *cnstrctr, std::string indent, bool sendData);
187 
198  void transform(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
199 
211  void transformAtomic(libdap::BaseType *bt, std::string indent, bool sendData);
212 
223  void transformNodeWorker(std::ostream *strm, vector<libdap::BaseType *> leaves, vector<libdap::BaseType *> nodes,
224  string indent, bool sendData);
225 
233  void printCoverage(std::ostream *strm, std::string indent);
234 
268  void printDomain(std::ostream *strm, std::string indent);
269 
284  void printAxes(std::ostream *strm, std::string indent);
285 
307  void printReference(std::ostream *strm, std::string indent);
308 
340  void printParameters(std::ostream *strm, std::string indent);
341 
364  void printRanges(std::ostream *strm, std::string indent);
365 
376  void printCoverageJSON(std::ostream *strm, string indent, bool testOverride);
377 
395  template<typename T>
396  void covjsonSimpleTypeArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
397 
418  void covjsonStringArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
419 
432  template<typename T>
433  unsigned int covjsonSimpleTypeArrayWorker(std::ostream *strm, T *values, unsigned int indx,
434  std::vector<unsigned int> *shape, unsigned int currentDim);
435 
444  void addAxis(std::string name, std::string values);
445 
461  void addParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
462  std::string longName, std::string standardName, std::string shape, std::string values);
463 
464  // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
465  void setAxesExistence(bool x, bool y, bool z, bool t) {
466  this->xExists = x;
467  this->yExists = y;
468  this->zExists = z;
469  this->tExists = t;
470  }
471 
472  void setDomainType(int domainType) {
473  this->domainType = domainType;
474  }
475  // ---------------------------------------------------------------------------------------------------------
476 
477 public:
491  virtual void transform(std::ostream &ostrm, bool sendData, bool testOverride);
492 
510  FoDapCovJsonTransform(libdap::DDS *dds);
511 
516  {
517  for (std::vector<Axis *>::const_iterator i = axes.begin(); i != axes.end(); ++i)
518  delete (*i);
519 
520  for (std::vector<Parameter *>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
521  delete (*i);
522  }
523 
534  virtual void dump(std::ostream &strm) const;
535 
536  // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
537  virtual void addTestAxis(std::string name, std::string values) {
538  addAxis(name, values);
539  }
540 
541  virtual void addTestParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
542  std::string longName, std::string standardName, std::string shape, std::string values) {
543  addParameter(id, name, type, dataType, unit, longName, standardName, shape, values);
544  }
545 
546  virtual void setTestAxesExistence(bool x, bool y, bool z, bool t) {
547  setAxesExistence(x, y, z, t);
548  }
549 
550  virtual void setTestDomainType(int domainType) {
551  setDomainType(domainType);
552  }
553 
554  virtual void printCoverage(std::ostream &ostrm, std::string indent) {
555  printCoverage(&ostrm, indent);
556  }
557 
558  virtual void printDomain(std::ostream &ostrm, std::string indent) {
559  printDomain(&ostrm, indent);
560  }
561 
562  virtual void printAxes(std::ostream &ostrm, std::string indent) {
563  printAxes(&ostrm, indent);
564  }
565 
566  virtual void printReference(std::ostream &ostrm, std::string indent) {
567  printReference(&ostrm, indent);
568  }
569 
570  virtual void printParameters(std::ostream &ostrm, std::string indent) {
571  printParameters(&ostrm, indent);
572  }
573 
574  virtual void printRanges(std::ostream &ostrm, std::string indent) {
575  printRanges(&ostrm, indent);
576  }
577  // ---------------------------------------------------------------------------------------------------------
578 };
579 
580 #endif /* FODAPCOVJSONTRANSFORM_H_ */
FoDapCovJsonTransform::FoDapCovJsonTransform
FoDapCovJsonTransform(libdap::DDS *dds)
Get the CovJSON encoding for a DDS.
Definition: FoDapCovJsonTransform.cc:680
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:688
BESObj
top level BES object to house generic methods
Definition: BESObj.h:49
FoDapCovJsonTransform::~FoDapCovJsonTransform
virtual ~FoDapCovJsonTransform()
Destructs the FoDapCovJsonTransform object and frees all memory.
Definition: FoDapCovJsonTransform.h:515
FoDapCovJsonTransform
Definition: FoDapCovJsonTransform.h:51
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56