libdap Updated for version 3.21.0
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#include "D4AttributeType.h"
52#include "D4Attributes.h"
53
54#include "InternalErr.h"
55
56#include "dods-datatypes.h"
57#include "Type.h"
58
59#include "DapObj.h"
60
61using namespace std;
62
63class Crc32;
64
65namespace libdap
66{
67
68class ConstraintEvaluator;
69
70class DDS;
71class Marshaller;
72class UnMarshaller;
73
74class Constructor;
75class XMLWrter;
76
77class DMR;
78class D4Group;
79class XMLWriter;
80class D4StreamMarshaller;
81class D4StreamUnMarshaller;
82
83class D4Attributes;
84
119class BaseType : public DapObj
120{
121private:
122 string d_name; // name of the instance
123 Type d_type; // instance's type
124 string d_dataset; // name of the dataset used to create this BaseType
125
126 bool d_is_read; // true if the value has been read
127 bool d_is_send; // Is the variable in the projection?
128
129 // d_parent points to the Constructor or Vector which holds a particular
130 // variable. It is null for simple variables. The Vector and Constructor
131 // classes must maintain this variable.
132 BaseType *d_parent;
133
134 // Attributes for this variable. Added 05/20/03 jhrg
135 AttrTable d_attr;
136
137 D4Attributes *d_attributes;
138
139 bool d_is_dap4; // True if this is a DAP4 variable, false ... DAP2
140
141 // These are non-empty only for DAP4 variables. Added 9/27/12 jhrg
142
143 // These were/are used for DAP2 CEs, but not for DAP4 ones
144 bool d_in_selection; // Is the variable in the selection?
145 bool d_is_synthesized; // true if the variable is synthesized
146
147protected:
148 void m_duplicate(const BaseType &bt);
149
150public:
151 typedef stack<BaseType *> btp_stack;
152
153 // These ctors assume is_dap4 is false
154 BaseType(const string &n, const Type &t, bool is_dap4 = false);
155 BaseType(const string &n, const string &d, const Type &t, bool is_dap4 = false);
156
157 BaseType(const BaseType &copy_from);
158 ~BaseType() override;
159
160 virtual string toString();
161
162 virtual void transform_to_dap4(D4Group *root, Constructor *container);
163 virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
164
165 void dump(ostream &strm) const override;
166
167 BaseType &operator=(const BaseType &rhs);
168
181 virtual void clear_local_data() { set_read_p(false); }
182
183 virtual bool is_dap4() const { return d_is_dap4; }
184 virtual void set_is_dap4(const bool v) { d_is_dap4 = v;}
185
192 virtual BaseType *ptr_duplicate() = 0;
193
194 virtual string name() const;
195 virtual void set_name(const string &n);
196 virtual std::string FQN() const;
197
198 virtual Type type() const;
199 virtual void set_type(const Type &t);
200 virtual string type_name() const;
201
202 virtual string dataset() const ;
203
209 virtual int length() const { return 1; }
210
218 virtual int64_t length_ll() const { return 1; }
219
226 virtual void set_length(int64_t) { /* empty since the length of a BaseType is always one element. jhrg 8/12/22 */ }
227
234 virtual void set_length_ll(int64_t) { /* empty since the length of a BaseType is always one element. jhrg 8/12/22 */ }
235
236 virtual bool is_simple_type() const;
237 virtual bool is_vector_type() const;
238 virtual bool is_constructor_type() const;
239
240 virtual bool synthesized_p();
241 virtual void set_synthesized_p(bool state);
242
243 virtual int element_count(bool leaves = false);
244
245 virtual bool read_p();
246 virtual void set_read_p(bool state);
247
248 virtual bool send_p();
249 virtual void set_send_p(bool state);
250
251 virtual AttrTable &get_attr_table();
252 virtual void set_attr_table(const AttrTable &at);
253
254 // DAP4 attributes
255 virtual D4Attributes *attributes();
256 virtual void set_attributes(D4Attributes *);
257 virtual void set_attributes_nocopy(D4Attributes *);
258
259 virtual bool is_in_selection();
260 virtual void set_in_selection(bool state);
261
262 virtual void set_parent(BaseType *parent);
263 virtual BaseType *get_parent() const;
264
265 virtual BaseType *get_ancestor();
266
267 virtual void transfer_attributes(AttrTable *at);
268
269 // I put this comment here because the version in BaseType.cc does not
270 // include the exact_match or s variables since they are not used. Doxygen
271 // was gaging on the comment.
272
303 virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = nullptr);
304 virtual BaseType *var(const string &name, btp_stack &s);
305
306 virtual void add_var(BaseType *bt, Part part = nil);
307 virtual void add_var_nocopy(BaseType *bt, Part part = nil);
308
309 virtual bool read();
310
311 virtual bool check_semantics(string &msg, bool all = false);
312
313 virtual bool ops(BaseType *b, int op);
314 virtual bool d4_ops(BaseType *b, int op);
315
316 virtual unsigned int width(bool constrained = false) const;
317
318 virtual int64_t width_ll(bool constrained = false) const;
319
320 virtual void print_decl(FILE *out, string space = " ",
321 bool print_semi = true,
322 bool constraint_info = false,
323 bool constrained = false);
324
325 virtual void print_xml(FILE *out, string space = " ",
326 bool constrained = false);
327
328 virtual void print_decl(ostream &out, string space = " ",
329 bool print_semi = true,
330 bool constraint_info = false,
331 bool constrained = false);
332
333 virtual void print_xml(ostream &out, string space = " ",
334 bool constrained = false);
335
336 virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
337
338 virtual void print_dap4(XMLWriter &xml, bool constrained = false);
339
362 virtual unsigned int buf2val(void **val) = 0;
363
393 virtual unsigned int val2buf(void *val, bool reuse = false) = 0;
394
413 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
414
458 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
459
466 virtual void compute_checksum(Crc32 &checksum) = 0;
467
468 virtual void intern_data();
469
483 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
484
509 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
510
517 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
518
534 virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
535
550 virtual void print_val(ostream &out, string space = "", bool print_decl_p = true) = 0;
552
553 virtual bool is_dap4_projected(std::vector<string> &projected_dap4_inventory);
554
555};
556
557} // namespace libdap
558
559#endif // _basetype_h
Definition: crc.h:79
Contains the attributes for a dataset.
Definition: AttrTable.h:154
The basic data type for the DODS DAP types.
Definition: BaseType.h:120
void m_duplicate(const BaseType &bt)
Perform a deep copy.
Definition: BaseType.cc:86
virtual bool is_dap4_projected(std::vector< string > &projected_dap4_inventory)
Definition: BaseType.cc:1323
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition: BaseType.cc:1140
virtual string type_name() const
Returns the type of the class instance as a string.
Definition: BaseType.cc:376
virtual void intern_data()
Read data into this variable.
Definition: BaseType.cc:936
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:905
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: BaseType.cc:949
virtual AttrTable & get_attr_table()
Definition: BaseType.cc:579
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:317
virtual void set_in_selection(bool state)
Definition: BaseType.cc:715
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:1009
virtual BaseType * get_parent() const
Definition: BaseType.cc:748
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:477
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:1305
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:513
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:355
virtual bool d4_ops(BaseType *b, int op)
Evaluator a relop for DAP4.
Definition: BaseType.cc:1288
virtual void set_length_ll(int64_t)
Set the number of elements in this variable This version of the function deprecates set_length() whic...
Definition: BaseType.h:234
virtual void set_attr_table(const AttrTable &at)
Definition: BaseType.cc:587
virtual void set_synthesized_p(bool state)
Definition: BaseType.cc:460
virtual void set_parent(BaseType *parent)
Definition: BaseType.cc:730
virtual int element_count(bool leaves=false)
Count the members of constructor types.
Definition: BaseType.cc:440
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:399
virtual void print_xml(FILE *out, string space=" ", bool constrained=false)
Definition: BaseType.cc:1111
virtual void set_name(const string &n)
Sets the name of the class instance.
Definition: BaseType.cc:341
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: BaseType.cc:1262
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:409
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:596
virtual std::string FQN() const
Definition: BaseType.cc:329
virtual bool send_p()
Should this variable be sent?
Definition: BaseType.cc:551
virtual void set_length(int64_t)
Set the number of elements for this variable. use -1 to indicate nothing set.
Definition: BaseType.h:226
virtual int length() const
How many elements are in this variable? Uses -1 in places.
Definition: BaseType.h:209
virtual void clear_local_data()
Definition: BaseType.h:181
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
Definition: BaseType.cc:390
virtual void set_send_p(bool state)
Definition: BaseType.cc:565
virtual BaseType * ptr_duplicate()=0
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
virtual int64_t length_ll() const
Get the number of elements in this variable This version of the function deprecates length() which is...
Definition: BaseType.h:218
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:943
virtual void add_var(BaseType *bt, Part part=nil)
Add a variable.
Definition: BaseType.cc:821
virtual void transfer_attributes(AttrTable *at)
Definition: BaseType.cc:641
virtual bool is_in_selection()
Is this variable part of the current selection?
Definition: BaseType.cc:700
virtual bool synthesized_p()
Definition: BaseType.cc:449
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition: BaseType.cc:1215
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:764
virtual void set_type(const Type &t)
Sets the type of the class instance.
Definition: BaseType.cc:369
virtual Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:362
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: BaseType.cc:1096
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Definition: BaseType.cc:1170
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
Definition: UnMarshaller.h:55
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
Type
Identifies the data type.
Definition: Type.h:94
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48