libdap Updated for version 3.20.10
libdap4 is an implementation of OPeNDAP's DAP protocol.
BaseType.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) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9// Dan Holloway <dan@hollywood.gso.uri.edu>
10// Reza Nekovei <reza@intcomm.net>
11//
12// This library is free software; you can redistribute it and/or
13// modify it under the terms of the GNU Lesser General Public
14// License as published by the Free Software Foundation; either
15// version 2.1 of the License, or (at your option) any later version.
16//
17// This library is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20// Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public
23// License along with this library; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25//
26// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27
28// (c) COPYRIGHT URI/MIT 1994-1999
29// Please read the full copyright statement in the file COPYRIGHT_URI.
30//
31// Authors:
32// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
33// dan Dan Holloway <dan@hollywood.gso.uri.edu>
34// reza Reza Nekovei <reza@intcomm.net>
35
36// Abstract base class for the variables in a dataset. This is used to store
37// the type-invariant information that describes a variable as given in the
38// DODS API.
39//
40// jhrg 9/6/94
41
42#ifndef _basetype_h
43#define _basetype_h 1
44
45#include <vector>
46#include <stack>
47#include <iostream>
48#include <string>
49
50#include "AttrTable.h"
51
52#include "InternalErr.h"
53
54#include "dods-datatypes.h"
55#include "Type.h"
56
57#include "DapObj.h"
58
59using namespace std;
60
61class Crc32;
62
63namespace libdap
64{
65
66class ConstraintEvaluator;
67
68class DDS;
69class Marshaller;
70class UnMarshaller;
71
72class Constructor;
73class XMLWrter;
74
75class DMR;
76class D4Group;
77class XMLWriter;
78class D4StreamMarshaller;
79class D4StreamUnMarshaller;
80
81class D4Attributes;
82
117class BaseType : public DapObj
118{
119private:
120 string d_name; // name of the instance
121 Type d_type; // instance's type
122 string d_dataset; // name of the dataset used to create this BaseType
123
124 bool d_is_read; // true if the value has been read
125 bool d_is_send; // Is the variable in the projection?
126
127 // d_parent points to the Constructor or Vector which holds a particular
128 // variable. It is null for simple variables. The Vector and Constructor
129 // classes must maintain this variable.
130 BaseType *d_parent;
131
132 // Attributes for this variable. Added 05/20/03 jhrg
133 AttrTable d_attr;
134
135 D4Attributes *d_attributes;
136
137 bool d_is_dap4; // True if this is a DAP4 variable, false ... DAP2
138
139 // These are non-empty only for DAP4 variables. Added 9/27/12 jhrg
140
141 // These were/are used for DAP2 CEs, but not for DAP4 ones
142 bool d_in_selection; // Is the variable in the selection?
143 bool d_is_synthesized; // true if the variable is synthesized
144
145protected:
146 void m_duplicate(const BaseType &bt);
147
148public:
149 typedef stack<BaseType *> btp_stack;
150
151 // These ctors assume is_dap4 is false
152 BaseType(const string &n, const Type &t, bool is_dap4 = false);
153 BaseType(const string &n, const string &d, const Type &t, bool is_dap4 = false);
154
155 BaseType(const BaseType &copy_from);
156 ~BaseType() override;
157
158 virtual string toString();
159
160 virtual void transform_to_dap4(D4Group *root, Constructor *container);
161 virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
162
163 void dump(ostream &strm) const override;
164
165 BaseType &operator=(const BaseType &rhs);
166
179 virtual void clear_local_data() { set_read_p(false); }
180
181 virtual bool is_dap4() const { return d_is_dap4; }
182 virtual void set_is_dap4(const bool v) { d_is_dap4 = v;}
183
190 virtual BaseType *ptr_duplicate() = 0;
191
192 virtual string name() const;
193 virtual void set_name(const string &n);
194 virtual std::string FQN() const;
195
196 virtual Type type() const;
197 virtual void set_type(const Type &t);
198 virtual string type_name() const;
199
200 virtual string dataset() const ;
201
207 virtual int length() const { return 1; }
208
214 virtual void set_length(int) { }
215
216 virtual bool is_simple_type() const;
217 virtual bool is_vector_type() const;
218 virtual bool is_constructor_type() const;
219
220 virtual bool synthesized_p();
221 virtual void set_synthesized_p(bool state);
222
223 virtual int element_count(bool leaves = false);
224
225 virtual bool read_p();
226 virtual void set_read_p(bool state);
227
228 virtual bool send_p();
229 virtual void set_send_p(bool state);
230
231 virtual AttrTable &get_attr_table();
232 virtual void set_attr_table(const AttrTable &at);
233
234 // DAP4 attributes
235 virtual D4Attributes *attributes();
236 virtual void set_attributes(D4Attributes *);
237 virtual void set_attributes_nocopy(D4Attributes *);
238
239 virtual bool is_in_selection();
240 virtual void set_in_selection(bool state);
241
242 virtual void set_parent(BaseType *parent);
243 virtual BaseType *get_parent() const;
244
245 virtual void transfer_attributes(AttrTable *at);
246
247 // I put this comment here because the version in BaseType.cc does not
248 // include the exact_match or s variables since they are not used. Doxygen
249 // was gaging on the comment.
250
281 virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = nullptr);
282 virtual BaseType *var(const string &name, btp_stack &s);
283
284 virtual void add_var(BaseType *bt, Part part = nil);
285 virtual void add_var_nocopy(BaseType *bt, Part part = nil);
286
287 virtual bool read();
288
289 virtual bool check_semantics(string &msg, bool all = false);
290
291 virtual bool ops(BaseType *b, int op);
292 virtual bool d4_ops(BaseType *b, int op);
293
294 virtual unsigned int width(bool constrained = false) const;
295
296 virtual void print_decl(FILE *out, string space = " ",
297 bool print_semi = true,
298 bool constraint_info = false,
299 bool constrained = false);
300
301 virtual void print_xml(FILE *out, string space = " ",
302 bool constrained = false);
303
304 virtual void print_decl(ostream &out, string space = " ",
305 bool print_semi = true,
306 bool constraint_info = false,
307 bool constrained = false);
308
309 virtual void print_xml(ostream &out, string space = " ",
310 bool constrained = false);
311
312 virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
313
314 virtual void print_dap4(XMLWriter &xml, bool constrained = false);
315
318#if 0
330 virtual unsigned int width(bool constrained = false) = 0;
331#endif
352 virtual unsigned int buf2val(void **val) = 0;
353
383 virtual unsigned int val2buf(void *val, bool reuse = false) = 0;
384
399 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
400
444 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
445
446#if 0
467 virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) {
468 return serialize(eval, dds, m, ce_eval);
469 }
470#endif
471
478 virtual void compute_checksum(Crc32 &checksum) = 0;
479
480 virtual void intern_data(/*Crc32 &checksum, DMR &dmr, ConstraintEvaluator &eval*/);
481
495 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
496
497#if 0
516 virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false) {
517 serialize(m, dmr, filter);
518 }
519#endif
520
545 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
546
553 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
554
570 virtual void print_val(FILE *out, string space = "",
571 bool print_decl_p = true);
572
587 virtual void print_val(ostream &out, string space = "",
588 bool print_decl_p = true) = 0;
590};
591
592} // namespace libdap
593
594#endif // _basetype_h
Definition crc.h:77
Contains the attributes for a dataset.
Definition AttrTable.h:143
The basic data type for the DODS DAP types.
Definition BaseType.h:118
void m_duplicate(const BaseType &bt)
Perform a deep copy.
Definition BaseType.cc:86
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition BaseType.cc:1130
virtual string type_name() const
Returns the type of the class instance as a string.
Definition BaseType.cc:375
virtual void intern_data()
Read data into this variable.
Definition BaseType.cc:923
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:895
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition BaseType.cc:939
virtual AttrTable & get_attr_table()
Definition BaseType.cc:578
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:316
virtual void set_in_selection(bool state)
Definition BaseType.cc:714
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
Definition BaseType.cc:999
virtual BaseType * get_parent() const
Definition BaseType.cc:747
virtual bool read_p()
Has this variable been read?
Definition BaseType.cc:476
virtual unsigned int width(bool constrained=false) const
How many bytes does this variable use Return the number of bytes of storage this variable uses....
Definition BaseType.cc:1295
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition BaseType.cc:512
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:354
virtual void set_length(int)
Set the number of elements for this variable.
Definition BaseType.h:214
virtual bool d4_ops(BaseType *b, int op)
Evaluator a relop for DAP4.
Definition BaseType.cc:1278
virtual void set_attr_table(const AttrTable &at)
Definition BaseType.cc:586
virtual void set_synthesized_p(bool state)
Definition BaseType.cc:459
virtual void set_parent(BaseType *parent)
Definition BaseType.cc:729
virtual int element_count(bool leaves=false)
Count the members of constructor types.
Definition BaseType.cc:439
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:287
virtual string toString()
Definition BaseType.cc:180
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
Definition BaseType.cc:398
virtual void print_xml(FILE *out, string space=" ", bool constrained=false)
Definition BaseType.cc:1101
virtual void set_name(const string &n)
Sets the name of the class instance.
Definition BaseType.cc:340
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition BaseType.cc:1252
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
Definition BaseType.cc:408
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)=0
Prints the value of the variable.
virtual D4Attributes * attributes()
Definition BaseType.cc:595
virtual std::string FQN() const
Definition BaseType.cc:328
virtual bool send_p()
Should this variable be sent?
Definition BaseType.cc:550
virtual int length() const
How many elements are in this variable.
Definition BaseType.h:207
virtual void clear_local_data()
Definition BaseType.h:179
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
Definition BaseType.cc:389
virtual void set_send_p(bool state)
Definition BaseType.cc:564
virtual BaseType * ptr_duplicate()=0
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
virtual unsigned int buf2val(void **val)=0
Reads the class data.
virtual void compute_checksum(Crc32 &checksum)=0
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
Definition BaseType.cc:212
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net, then remove them from the object.
Definition BaseType.cc:933
virtual void add_var(BaseType *bt, Part part=nil)
Add a variable.
Definition BaseType.cc:811
virtual void transfer_attributes(AttrTable *at)
Definition BaseType.cc:640
virtual bool is_in_selection()
Is this variable part of the current selection?
Definition BaseType.cc:699
virtual bool synthesized_p()
Definition BaseType.cc:448
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition BaseType.cc:1205
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:126
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
Definition BaseType.cc:754
virtual void set_type(const Type &t)
Sets the type of the class instance.
Definition BaseType.cc:368
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:361
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition BaseType.cc:1086
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Definition BaseType.cc:1160
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
DAP4 to DAP2 transform.
Definition BaseType.cc:255
Evaluate a constraint expression.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
libdap base object for common functionality of libdap objects
Definition DapObj.h:51
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
abstract base class used to unmarshall/deserialize dap data objects
top level DAP object to house generic methods
Type
Identifies the data type.
Definition Type.h:94
Part
Names the parts of multi-section constructor data types.
Definition Type.h:48