libdap  Updated for version 3.18.3
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 
59 using namespace std;
60 
61 class Crc32;
62 
63 namespace libdap
64 {
65 
66 class ConstraintEvaluator;
67 
68 class DDS;
69 class Marshaller;
70 class UnMarshaller;
71 
72 class Constructor;
73 class XMLWrter;
74 
75 class DMR;
76 class D4Group;
77 class XMLWriter;
78 class D4StreamMarshaller;
79 class D4StreamUnMarshaller;
80 
81 class D4Attributes;
82 
117 class BaseType : public DapObj
118 {
119 private:
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 protected:
142  // These were/are used for DAP2 CEs, but not for DAP4 ones
143  bool d_in_selection; // Is the variable in the selection?
144  bool d_is_synthesized; // true if the variable is synthesized
145 
146  void m_duplicate(const BaseType &bt);
147 
148 public:
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  virtual ~BaseType();
157 
158  virtual string toString();
159 
160  virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container);
161 
162  virtual void dump(ostream &strm) const ;
163 
164  BaseType &operator=(const BaseType &rhs);
165 
178  virtual void clear_local_data() { set_read_p(false); }
179 
180  virtual bool is_dap4() const { return d_is_dap4; }
181  virtual void set_is_dap4(const bool v) { d_is_dap4 = v;}
182 
189  virtual BaseType *ptr_duplicate() = 0;
190 
191  virtual string name() const;
192  virtual void set_name(const string &n);
193  virtual std::string FQN() const;
194 
195  virtual Type type() const;
196  virtual void set_type(const Type &t);
197  virtual string type_name() const;
198 
199  virtual string dataset() const ;
200 
206  virtual int length() const { return 1; }
207 
213  virtual void set_length(int) { }
214 
215  virtual bool is_simple_type() const;
216  virtual bool is_vector_type() const;
217  virtual bool is_constructor_type() const;
218 
219  virtual bool synthesized_p();
220  virtual void set_synthesized_p(bool state);
221 
222  virtual int element_count(bool leaves = false);
223 
224  virtual bool read_p();
225  virtual void set_read_p(bool state);
226 
227  virtual bool send_p();
228  virtual void set_send_p(bool state);
229 
230  virtual AttrTable &get_attr_table();
231  virtual void set_attr_table(const AttrTable &at);
232 
233  // DAP4 attributes
234  virtual D4Attributes *attributes();
235  virtual void set_attributes(D4Attributes *);
236  virtual void set_attributes_nocopy(D4Attributes *);
237 
238  virtual bool is_in_selection();
239  virtual void set_in_selection(bool state);
240 
241  virtual void set_parent(BaseType *parent);
242  virtual BaseType *get_parent() const;
243 
244  virtual void transfer_attributes(AttrTable *at);
245 
246  // I put this comment here because the version in BaseType.cc does not
247  // include the exact_match or s variables since they are not used. Doxygen
248  // was gaging on the comment.
249 
280  virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = 0);
281  virtual BaseType *var(const string &name, btp_stack &s);
282 
283  virtual void add_var(BaseType *bt, Part part = nil);
284  virtual void add_var_nocopy(BaseType *bt, Part part = nil);
285 
286  virtual bool read();
287 
288  virtual bool check_semantics(string &msg, bool all = false);
289 
290  virtual bool ops(BaseType *b, int op);
291  virtual bool d4_ops(BaseType *b, int op);
292 
293  virtual unsigned int width(bool constrained = false) const;
294 
295  virtual void print_decl(FILE *out, string space = " ",
296  bool print_semi = true,
297  bool constraint_info = false,
298  bool constrained = false);
299 
300  virtual void print_xml(FILE *out, string space = " ",
301  bool constrained = false);
302 
303  virtual void print_decl(ostream &out, string space = " ",
304  bool print_semi = true,
305  bool constraint_info = false,
306  bool constrained = false);
307 
308  virtual void print_xml(ostream &out, string space = " ",
309  bool constrained = false);
310 
311  virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
312 
313  virtual void print_dap4(XMLWriter &xml, bool constrained = false);
314 
317 #if 0
318 
329  virtual unsigned int width(bool constrained = false) = 0;
330 #endif
331 
351  virtual unsigned int buf2val(void **val) = 0;
352 
382  virtual unsigned int val2buf(void *val, bool reuse = false) = 0;
383 
398  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
399 
443  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
444 
445 #if 0
446 
466  virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) {
467  return serialize(eval, dds, m, ce_eval);
468  }
469 #endif
470 
477  virtual void compute_checksum(Crc32 &checksum) = 0;
478 
479  virtual void intern_data(/*Crc32 &checksum, DMR &dmr, ConstraintEvaluator &eval*/);
480 
494  virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
495 
496 #if 0
497 
515  virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false) {
516  serialize(m, dmr, filter);
517  }
518 #endif
519 
544  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
545 
552  virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
553 
569  virtual void print_val(FILE *out, string space = "",
570  bool print_decl_p = true);
571 
586  virtual void print_val(ostream &out, string space = "",
587  bool print_decl_p = true) = 0;
589 };
590 
591 } // namespace libdap
592 
593 #endif // _basetype_h
virtual int length() const
How many elements are in this variable.
Definition: BaseType.h:206
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
bool is_constructor_type(Type t)
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
Definition: util.cc:862
Contains the attributes for a dataset.
Definition: AttrTable.h:142
Definition: crc.h:76
STL namespace.
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
Definition: util.cc:816
Type
Identifies the data type.
Definition: Type.h:94
virtual void clear_local_data()
Definition: BaseType.h:178
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
Definition: util.cc:774
virtual void set_length(int)
Set the number of elements for this variable.
Definition: BaseType.h:213
Evaluate a constraint expression.
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
libdap base object for common functionality of libdap objects
Definition: DapObj.h:55
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:50
string type_name(Type t)
Definition: util.cc:759