libdap  Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
Constructor.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 //
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 _constructor_h
27 #define _constructor_h 1
28 
29 #include <vector>
30 
31 #include "BaseType.h"
32 
33 class Crc32;
34 
35 namespace libdap
36 {
37 
38 class DMR;
39 class XMLWriter;
40 class D4StreamUnMarshaller;
41 
43 class Constructor: public BaseType
44 {
45 private:
46  void m_duplicate(const Constructor &s);
47 
48 protected:
49  std::vector<BaseType *> d_vars;
50 
51  BaseType *m_leaf_match(const string &name, btp_stack *s = nullptr);
52  BaseType *m_exact_match(const string &name, btp_stack *s = nullptr);
53 
54  Constructor(const string &name, const Type &type, bool is_dap4 = false)
55  : BaseType(name, type, is_dap4) { }
56  Constructor(const string &name, const string &dataset, const Type &type, bool is_dap4 = false)
57  : BaseType(name, dataset, type, is_dap4) { }
58 
59  Constructor(const Constructor &copy_from) : BaseType(copy_from) {
60  m_duplicate(copy_from);
61  }
62 
63 public:
64  typedef std::vector<BaseType *>::const_iterator Vars_citer ;
65  typedef std::vector<BaseType *>::iterator Vars_iter ;
66  typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
67 
68  Constructor() = delete; // Why? jhrg 4/25/22
69 
70  ~Constructor() override {
71  for (auto var: d_vars)
72  delete var;
73  }
74 
75  Constructor &operator=(const Constructor &rhs) {
76  if (this == &rhs)
77  return *this;
78  BaseType::operator=(rhs);
79  m_duplicate(rhs);
80  return *this;
81  }
82 
83  void transform_to_dap4(D4Group *root, Constructor *dest) override;
84 
85  std::string FQN() const override ;
86 
87  int element_count(bool leaves = false) override;
88 
89  void set_send_p(bool state) override;
90  void set_read_p(bool state) override;
91 
92  unsigned int width(bool constrained = false) const override;
93 
95  BaseType *var(const string &name, bool exact_match = true, btp_stack *s = nullptr) override;
96 
99  BaseType *var(const string &n, btp_stack &s) override;
100 
101  Vars_iter var_begin();
102  Vars_iter var_end();
103  Vars_riter var_rbegin();
104  Vars_riter var_rend();
105  Vars_iter get_vars_iter(int i);
106  BaseType *get_var_index(int i);
107 
113  const vector<BaseType*> &variables() const { return d_vars; }
114 
115  void add_var(BaseType *bt, Part part = nil) override;
116  void add_var_nocopy(BaseType *bt, Part part = nil) override;
117 
118  virtual void del_var(const string &name);
119  virtual void del_var(Vars_iter i);
120 
121  bool read() override;
122 
123  // DAP2
124  void intern_data(ConstraintEvaluator &eval, DDS &dds) override;
125  bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) override;
126  bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) override;
127 
128  // DAP4
129  void compute_checksum(Crc32 &checksum) override;
130  void intern_data() override;
131  void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false) override;
132  void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
133 
134  // Do not store values in memory as for C; users work with the C++ objects for this class
135  unsigned int val2buf(void *, bool) override {
136  throw InternalErr(__FILE__, __LINE__, "Never use this method; see the programmer's guide documentation.");
137  }
138  unsigned int buf2val(void **) override {
139  throw InternalErr(__FILE__, __LINE__, "Never use this method; see the programmer's guide documentation.");
140  }
141 
142  virtual bool is_linear();
143 
144  void set_in_selection(bool state) override;
145 
146  void print_decl(ostream &out, string space = " ", bool print_semi = true, bool constraint_info = false,
147  bool constrained = false) override;
148 
149  void print_xml(ostream &out, string space = " ", bool constrained = false) override;
150 
151  void print_dap4(XMLWriter &xml, bool constrained = false) override;
152 
153  void print_xml_writer(XMLWriter &xml, bool constrained = false) override;
154 
155  void print_decl(FILE *out, string space = " ", bool print_semi = true, bool constraint_info = false,
156  bool constrained = false) override;
157  void print_xml(FILE *out, string space = " ", bool constrained = false) override;
158 
159  void print_val(FILE *out, string space = "", bool print_decl_p = true) override;
160  void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
161 
162  bool check_semantics(string &msg, bool all = false) override;
163 
164  void transfer_attributes(AttrTable *at) override;
165  static AttrTable *make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars);
166 
167  void dump(ostream &strm) const override;
168 };
169 
170 } // namespace libdap
171 
172 #endif // _constructor_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
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:316
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:354
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition: BaseType.cc:126
virtual Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:361
Evaluate a constraint expression.
int element_count(bool leaves=false) override
Count the members of constructor types.
Definition: Constructor.cc:115
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition: Constructor.cc:462
void transform_to_dap4(D4Group *root, Constructor *dest) override
DAP2 to DAP4 transform.
Definition: Constructor.cc:84
Vars_iter get_vars_iter(int i)
Definition: Constructor.cc:304
BaseType * var(const string &name, bool exact_match=true, btp_stack *s=nullptr) override
btp_stack no longer needed; use back pointers (BaseType::get_parent())
Definition: Constructor.cc:185
void add_var(BaseType *bt, Part part=nil) override
Definition: Constructor.cc:323
void transfer_attributes(AttrTable *at) override
Definition: Constructor.cc:703
void print_xml_writer(XMLWriter &xml, bool constrained=false) override
Definition: Constructor.cc:602
void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false) override
Print an ASCII representation of the variable structure.
Definition: Constructor.cc:529
unsigned int buf2val(void **) override
Reads the class data.
Definition: Constructor.h:138
void print_xml(ostream &out, string space=" ", bool constrained=false) override
Definition: Constructor.cc:594
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
Definition: Constructor.cc:452
void intern_data() override
Read data into this variable.
Definition: Constructor.cc:468
void set_read_p(bool state) override
Set the 'read_p' property for the Constructor and its members.
Definition: Constructor.cc:150
void print_val(FILE *out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition: Constructor.cc:553
void set_send_p(bool state) override
Definition: Constructor.cc:129
Vars_iter var_end()
Definition: Constructor.cc:280
bool read() override
Read the elements of Constructor marked for transmission.
Definition: Constructor.cc:393
void set_in_selection(bool state) override
Set the in_selection property.
Definition: Constructor.cc:694
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Move data to the net, then remove them from the object.
Definition: Constructor.cc:421
Vars_riter var_rbegin()
Definition: Constructor.cc:287
void add_var_nocopy(BaseType *bt, Part part=nil) override
Definition: Constructor.cc:345
unsigned int width(bool constrained=false) const override
Definition: Constructor.cc:167
BaseType * get_var_index(int i)
Definition: Constructor.cc:313
bool check_semantics(string &msg, bool all=false) override
Compare an object's current state with the semantics of its type.
Definition: Constructor.cc:654
Vars_iter var_begin()
Definition: Constructor.cc:272
void print_dap4(XMLWriter &xml, bool constrained=false) override
Definition: Constructor.cc:631
std::string FQN() const override
Definition: Constructor.cc:102
unsigned int val2buf(void *, bool) override
Loads class data.
Definition: Constructor.h:135
Vars_riter var_rend()
Definition: Constructor.cc:295
const vector< BaseType * > & variables() const
Definition: Constructor.h:113
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition: Constructor.cc:683
virtual void del_var(const string &name)
Remove an element from a Constructor.
Definition: Constructor.cc:362
void dump(ostream &strm) const override
dumps information about this object
Definition: Constructor.cc:767
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.
A class for software fault reporting.
Definition: InternalErr.h:65
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