libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4RValue.h
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2014 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #ifndef _D4RValue_h
27 #define _D4RValue_h
28 
29 #include <vector>
30 #include <string>
31 
32 #include <dods-datatypes.h>
33 #include <D4Function.h>
34 
35 namespace libdap
36 {
37 
38 class BaseType;
39 class D4RValue;
40 
41 // Factory class to build RValue objects. User by the parser/ce-evaluator
42 D4RValue *D4RValueFactory(std::string cpps);
43 
45 {
46 private:
47  std::vector<D4RValue *> d_rvalues;
48 
49  void m_duplicate(const D4RValueList &src);
50 
51 public:
52  typedef std::vector<D4RValue *>::iterator iter;
53 
54  D4RValueList() { }
55  D4RValueList(const D4RValueList &src) { m_duplicate(src); }
56  D4RValueList(D4RValue *rv) { add_rvalue(rv); }
57 
58  virtual ~D4RValueList();
59 
60  D4RValueList &operator=(const D4RValueList &rhs) {
61  if (this == &rhs) return *this;
62  m_duplicate(rhs);
63  return *this;
64  }
65 
66  void add_rvalue(D4RValue *rv) {
67  d_rvalues.push_back(rv);
68  }
69 
70  D4RValue *get_rvalue(unsigned int i) {
71  return d_rvalues.at(i);
72  }
73 
74  iter begin() { return d_rvalues.begin(); }
75  iter end() { return d_rvalues.end(); }
76 
77  unsigned int size() const { return d_rvalues.size(); }
78 
79 };
80 
85 class D4RValue
86 {
87 public:
88  enum value_kind {
89  unknown,
90  basetype,
91  function,
92  constant
93  };
94 
95 private:
96  BaseType *d_variable; // This is a weak pointer; do not delete
97 
98  D4Function d_func; // (weak) pointer to a function returning BaseType *
99  D4RValueList *d_args; // pointer to arguments to the function; delete
100 
101  BaseType *d_constant; // pointer; delete.
102 
103  value_kind d_value_kind;
104 
106  void m_duplicate(const D4RValue &src);
107 
108  friend class D4RValueList;
109 
110 public:
111  D4RValue() : d_variable(0), d_func(0), d_args(0), d_constant(0), d_value_kind(unknown) { }
112  D4RValue(const D4RValue &src) { m_duplicate(src); }
113  D4RValue(BaseType *btp) : d_variable(btp), d_func(0), d_args(0), d_constant(0), d_value_kind(basetype) { }
114  D4RValue(D4Function f, D4RValueList *args) : d_variable(0), d_func(f), d_args(args), d_constant(0), d_value_kind(function) { }
115 
116  D4RValue(unsigned long long ui);
117  D4RValue(long long i);
118  D4RValue(double r);
119  D4RValue(std::string s);
120  D4RValue(std::vector<dods_byte> &byte_args);
121  D4RValue(std::vector<dods_int8> &byte_int8);
122  D4RValue(std::vector<dods_uint16> &byte_uint16);
123  D4RValue(std::vector<dods_int16> &byte_int16);
124  D4RValue(std::vector<dods_uint32> &byte_uint32);
125  D4RValue(std::vector<dods_int32> &byte_int32);
126  D4RValue(std::vector<dods_uint64> &byte_uint64);
127  D4RValue(std::vector<dods_int64> &byte_int64);
128  D4RValue(std::vector<dods_float32> &byte_float32);
129  D4RValue(std::vector<dods_float64> &byte_float64);
130 
131  virtual ~D4RValue();
132 
133  D4RValue &operator=(D4RValue &rhs) {
134  if (this == &rhs)
135  return *this;
136 
137  m_duplicate(rhs);
138 
139  return *this;
140  }
141 
150  value_kind get_kind() const { return d_value_kind; }
151 
152  // This is the call that will be used to return the value of a function.
153  // jhrg 3/10/14
154  virtual BaseType *value(DMR &dmr);
155  // And this optimizes value() for filters, where functions are not supported.
156  virtual BaseType *value();
157 
158 };
159 
160 } // namespace libdap
161 #endif // _RValue_h
top level DAP object to house generic methods
Definition: AISConnect.cc:30
D4RValue * D4RValueFactory(std::string cpps)
Build an appropriate RValue.
Definition: D4RValue.cc:218
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
value_kind get_kind() const
What kind of thing holds the value Values in DAP4 constraints are either constants, dataset variables or function results. It might be nice to know the source of a given value in order to optimize the evaluation of certain kinds of expressions.
Definition: D4RValue.h:150