libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Constructor.h
Go to the documentation of this file.
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
33class Crc32;
34
35namespace libdap {
36
37class DMR;
38class XMLWriter;
40
42class Constructor : public BaseType {
43private:
44 void m_duplicate(const Constructor &s);
45
46protected:
47 std::vector<BaseType *> d_vars;
48
49 BaseType *m_leaf_match(const string &name, btp_stack *s = nullptr);
50 BaseType *m_exact_match(const string &name, btp_stack *s = nullptr);
51
52 Constructor(const string &name, const Type &type, bool is_dap4 = false) : BaseType(name, type, is_dap4) {}
53 Constructor(const string &name, const string &dataset, const Type &type, bool is_dap4 = false)
55
56 Constructor(const Constructor &copy_from) : BaseType(copy_from) { m_duplicate(copy_from); }
57
58public:
59 typedef std::vector<BaseType *>::const_iterator Vars_citer;
60 typedef std::vector<BaseType *>::iterator Vars_iter;
61 typedef std::vector<BaseType *>::reverse_iterator Vars_riter;
62
63 Constructor() = delete; // Why? jhrg 4/25/22
64
65 ~Constructor() override {
66 for (auto var : d_vars)
67 delete var;
68 }
69
71 if (this == &rhs)
72 return *this;
74 m_duplicate(rhs);
75 return *this;
76 }
77
78 void transform_to_dap4(D4Group *root, Constructor *dest) override;
79
80 std::string FQN() const override;
81
82 int element_count(bool leaves = false) override;
83
84 void set_send_p(bool state) override;
85 void set_read_p(bool state) override;
86
87 unsigned int width(bool constrained = false) const override;
88 int64_t width_ll(bool constrained = false) const override;
89
91 BaseType *var(const string &name, bool exact_match = true, btp_stack *s = nullptr) override;
92
95 BaseType *var(const string &n, btp_stack &s) override;
96
102 BaseType *get_var_index(int i);
103 void set_var_index(BaseType *bt, int i);
104
110 const vector<BaseType *> &variables() const { return d_vars; }
111
112 bool is_dap4_projected(std::vector<std::string> &inventory) override;
113
114 void add_var(BaseType *bt, Part part = nil) override;
115 void add_var_nocopy(BaseType *bt, Part part = nil) override;
116
117 virtual void del_var(const string &name);
118 virtual void del_var(Vars_iter i);
119
120 bool read() override;
121
122 // DAP2
123 void intern_data(ConstraintEvaluator &eval, DDS &dds) override;
124 bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) override;
125 bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) override;
126
127 // DAP4
128 void compute_checksum(Crc32 &checksum) override;
129 void intern_data() override;
130 void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false) override;
131 void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
132
133 // Do not store values in memory as for C; users work with the C++ objects for this class
134 unsigned int val2buf(void *, bool) override {
135 throw InternalErr(__FILE__, __LINE__, "Never use this method; see the programmer's guide documentation.");
136 }
137 unsigned int buf2val(void **) override {
138 throw InternalErr(__FILE__, __LINE__, "Never use this method; see the programmer's guide documentation.");
139 }
140
141 virtual bool is_linear();
142
143 void set_in_selection(bool state) override;
144
145 void print_decl(ostream &out, string space = " ", bool print_semi = true, bool constraint_info = false,
146 bool constrained = false) override;
147
148 void print_xml(ostream &out, string space = " ", bool constrained = false) override;
149
150 void print_dap4(XMLWriter &xml, bool constrained = false) override;
151
152 void print_xml_writer(XMLWriter &xml, bool constrained = false) override;
153
154 void print_decl(FILE *out, string space = " ", bool print_semi = true, bool constraint_info = false,
155 bool constrained = false) override;
156 void print_xml(FILE *out, string space = " ", bool constrained = false) override;
157
158 void print_val(FILE *out, string space = "", bool print_decl_p = true) override;
159 void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
160
161 bool check_semantics(string &msg, bool all = false) override;
162
163 void transfer_attributes(AttrTable *at) override;
164 static AttrTable *make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars);
165
166 void dump(ostream &strm) const override;
167};
168
169} // namespace libdap
170
171#endif // _constructor_h
Definition crc.h:43
Contains the attributes for a dataset.
Definition AttrTable.h:150
The basic data type for the DODS DAP types.
Definition BaseType.h:118
BaseType & operator=(const BaseType &rhs)
Definition BaseType.cc:159
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:326
virtual bool is_dap4() const
Definition BaseType.h:181
stack< BaseType * > btp_stack
Definition BaseType.h:149
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:124
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:329
Evaluate a constraint expression.
std::vector< BaseType * >::reverse_iterator Vars_riter
Definition Constructor.h:61
int element_count(bool leaves=false) override
Count the members of constructor types.
Constructor(const string &name, const string &dataset, const Type &type, bool is_dap4=false)
Definition Constructor.h:53
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
void transform_to_dap4(D4Group *root, Constructor *dest) override
DAP2 to DAP4 transform.
Vars_iter get_vars_iter(int i)
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())
void set_var_index(BaseType *bt, int i)
Set the ith element of d_vars to a variable object.
void add_var(BaseType *bt, Part part=nil) override
void transfer_attributes(AttrTable *at) override
void print_xml_writer(XMLWriter &xml, bool constrained=false) override
std::vector< BaseType * >::const_iterator Vars_citer
Definition Constructor.h:59
Constructor(const Constructor &copy_from)
Definition Constructor.h:56
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.
unsigned int buf2val(void **) override
Reads the class data.
void print_xml(ostream &out, string space=" ", bool constrained=false) override
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
void intern_data() override
Read data into this variable.
void set_read_p(bool state) override
Set the 'read_p' property for the Constructor and its members.
void print_val(FILE *out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
static AttrTable * make_dropped_vars_attr_table(vector< BaseType * > *dropped_vars)
std::vector< BaseType * >::iterator Vars_iter
Definition Constructor.h:60
std::vector< BaseType * > d_vars
Definition Constructor.h:47
void set_send_p(bool state) override
bool is_dap4_projected(std::vector< std::string > &inventory) override
bool read() override
Read the elements of Constructor marked for transmission.
void set_in_selection(bool state) override
Set the in_selection property.
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Move data to the net, then remove them from the object.
Vars_riter var_rbegin()
BaseType * m_exact_match(const string &name, btp_stack *s=nullptr)
void add_var_nocopy(BaseType *bt, Part part=nil) override
const vector< BaseType * > & variables() const
unsigned int width(bool constrained=false) const override
BaseType * get_var_index(int i)
BaseType * m_leaf_match(const string &name, btp_stack *s=nullptr)
bool check_semantics(string &msg, bool all=false) override
Compare an object's current state with the semantics of its type.
Vars_iter var_begin()
Constructor & operator=(const Constructor &rhs)
Definition Constructor.h:70
~Constructor() override
Definition Constructor.h:65
void print_dap4(XMLWriter &xml, bool constrained=false) override
std::string FQN() const override
unsigned int val2buf(void *, bool) override
Loads class data.
Vars_riter var_rend()
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Constructor(const string &name, const Type &type, bool is_dap4=false)
Definition Constructor.h:52
virtual void del_var(const string &name)
Remove an element from a Constructor.
void dump(ostream &strm) const override
dumps information about this object
int64_t width_ll(bool constrained=false) const override
Get the width of the Constructor's fields.
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:61
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
Definition AISConnect.cc:30
Type
Identifies the data type.
Definition Type.h:94
Part
Names the parts of multi-section constructor data types.
Definition Type.h:48
@ nil
Definition Type.h:49