libdap  Updated for version 3.17.2
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 D4Constant;
40 class D4RValue;
41 
43 {
44 private:
45  std::vector<D4RValue *> d_rvalues;
46 
47 public:
48  typedef std::vector<D4RValue *>::iterator iter;
49 
50  D4RValueList() { }
51  D4RValueList(D4RValue *rv) { add_rvalue(rv); }
52 
53  ~D4RValueList();
54 
55  void add_rvalue(D4RValue *rv) {
56  d_rvalues.push_back(rv);
57  }
58 
59  D4RValue *get_rvalue(unsigned int i) {
60  return d_rvalues.at(i);
61  }
62 
63  iter begin() { return d_rvalues.begin(); }
64  iter end() { return d_rvalues.end(); }
65 
66  unsigned int size() const { return d_rvalues.size(); }
67 
68 };
69 
73 class D4RValue
74 {
75 private:
76  BaseType *d_variable; // This is a weak pointer
77 
78  D4Function d_func; // (weak) Pointer to a function returning BaseType *
79  D4RValueList *d_args; // Strong pointer to arguments to the function; delete
80 
81  BaseType *d_constant; // Strong pointer; delete
82 
83  enum value_kind {
84  unknown,
85  basetype,
86  function,
87  constant
88  };
89 
90  value_kind d_value_kind;
91 
92  friend class D4RValueList;
93 
94 public:
95  D4RValue() : d_variable(0), d_func(0), d_args(0), d_constant(0), d_value_kind(unknown) { }
96 
97  D4RValue(BaseType *btp) : d_variable(btp), d_func(0), d_args(0), d_constant(0), d_value_kind(basetype) { }
98  D4RValue(D4Function f, D4RValueList *args) : d_variable(0), d_func(f), d_args(args), d_constant(0), d_value_kind(function) { }
99 
100  D4RValue(unsigned long long ui);
101  D4RValue(long long i);
102  D4RValue(double r);
103  D4RValue(std::string s);
104  D4RValue(std::vector<dods_byte> &byte_args);
105  D4RValue(std::vector<dods_int8> &byte_int8);
106  D4RValue(std::vector<dods_uint16> &byte_uint16);
107  D4RValue(std::vector<dods_int16> &byte_int16);
108  D4RValue(std::vector<dods_uint32> &byte_uint32);
109  D4RValue(std::vector<dods_int32> &byte_int32);
110  D4RValue(std::vector<dods_uint64> &byte_uint64);
111  D4RValue(std::vector<dods_int64> &byte_int64);
112  D4RValue(std::vector<dods_float32> &byte_float32);
113  D4RValue(std::vector<dods_float64> &byte_float64);
114 
115  virtual ~D4RValue();
116 
117  // This is the call that will be used to return the value of a function.
118  // jhrg 3/10/14
119  BaseType *value(DMR &dmr);
120 };
121 
122 } // namespace libdap
123 #endif // _RValue_h
The basic data type for the DODS DAP types.
Definition: BaseType.h:117