libdap Updated for version 3.20.5
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
35namespace libdap
36{
37
38class BaseType;
39class D4RValue;
40
41// Factory class to build RValue objects. User by the parser/ce-evaluator
42D4RValue *D4RValueFactory(std::string cpps);
43
45{
46private:
47 std::vector<D4RValue *> d_rvalues;
48
49 void m_duplicate(const D4RValueList &src);
50
51public:
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 void add_rvalue(D4RValue *rv) {
61 d_rvalues.push_back(rv);
62 }
63
64 D4RValue *get_rvalue(unsigned int i) {
65 return d_rvalues.at(i);
66 }
67
68 iter begin() { return d_rvalues.begin(); }
69 iter end() { return d_rvalues.end(); }
70
71 unsigned int size() const { return d_rvalues.size(); }
72
73};
74
80{
81public:
82 enum value_kind {
83 unknown,
84 basetype,
85 function,
86 constant
87 };
88
89private:
90 BaseType *d_variable; // This is a weak pointer; do not delete
91
92 D4Function d_func; // (weak) pointer to a function returning BaseType *
93 D4RValueList *d_args; // pointer to arguments to the function; delete
94
95 BaseType *d_constant; // pointer; delete.
96
97 value_kind d_value_kind;
98
100 void m_duplicate(const D4RValue &src);
101
102 friend class D4RValueList;
103
104public:
105 D4RValue() : d_variable(0), d_func(0), d_args(0), d_constant(0), d_value_kind(unknown) { }
106 D4RValue(const D4RValue &src) { m_duplicate(src); }
107 D4RValue(BaseType *btp) : d_variable(btp), d_func(0), d_args(0), d_constant(0), d_value_kind(basetype) { }
108 D4RValue(D4Function f, D4RValueList *args) : d_variable(0), d_func(f), d_args(args), d_constant(0), d_value_kind(function) { }
109
110 D4RValue(unsigned long long ui);
111 D4RValue(long long i);
112 D4RValue(double r);
113 D4RValue(std::string s);
114 D4RValue(std::vector<dods_byte> &byte_args);
115 D4RValue(std::vector<dods_int8> &byte_int8);
116 D4RValue(std::vector<dods_uint16> &byte_uint16);
117 D4RValue(std::vector<dods_int16> &byte_int16);
118 D4RValue(std::vector<dods_uint32> &byte_uint32);
119 D4RValue(std::vector<dods_int32> &byte_int32);
120 D4RValue(std::vector<dods_uint64> &byte_uint64);
121 D4RValue(std::vector<dods_int64> &byte_int64);
122 D4RValue(std::vector<dods_float32> &byte_float32);
123 D4RValue(std::vector<dods_float64> &byte_float64);
124
125 virtual ~D4RValue();
126
127 D4RValue &operator=(D4RValue &rhs) {
128 if (this == &rhs)
129 return *this;
130
131 m_duplicate(rhs);
132
133 return *this;
134 }
135
144 value_kind get_kind() const { return d_value_kind; }
145
146 // This is the call that will be used to return the value of a function.
147 // jhrg 3/10/14
148 virtual BaseType *value(DMR &dmr);
149 // And this optimizes value() for filters, where functions are not supported.
150 virtual BaseType *value();
151
152};
153
154} // namespace libdap
155#endif // _RValue_h
The basic data type for the DODS DAP types.
Definition BaseType.h:118
value_kind get_kind() const
What kind of thing holds the value Values in DAP4 constraints are either constants,...
Definition D4RValue.h:144
virtual BaseType * value()
Get the value for a RValue object.
Definition D4RValue.cc:300
top level DAP object to house generic methods
D4RValue * D4RValueFactory(std::string cpps)
Build an appropriate RValue.
Definition D4RValue.cc:218