-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathD4Group.h
More file actions
216 lines (171 loc) · 7.49 KB
/
D4Group.h
File metadata and controls
216 lines (171 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#ifndef D4GROUP_H_
#define D4GROUP_H_
#include <cstdint>
#include <string>
#include "Constructor.h"
#include "D4Dimensions.h"
#include "D4EnumDefs.h"
class Crc32;
namespace libdap {
class BaseType;
class Array;
/** A DAP4 Group object. A Group is-a Constructor, so it inherits a set of
* BaseType objects and an attribute table, along with methods to search for
* variables by name where dots (.) in a fully qualified name serve as
* separators.
*/
class D4Group : public Constructor {
private:
// Note that because Constructor is a BaseType, this class inherits
// both a back pointer to its parent, an AttrTable and, directly from the
// Constructor class, a vector of BaseTypes.
// This instance of D4Dimensions holds the Group's definitions; the same
// class is used by Array to hold the actual dimensions for a variable.
D4Dimensions *d_dims;
// This holds the Group's enumeration definitions; a different class is
// used for the Enumeration type
D4EnumDefs *d_enum_defs;
// This is a pointer so that the factory class(es) that return pointers
// work as expected when making Groups.
vector<D4Group *> d_groups;
BaseType *m_find_map_source_helper(const string &name);
D4Group *find_grp_internal(const string &grp_path);
protected:
/**
* @brief Deep-copies group-local members from another group.
* @param g Source group.
*/
void m_duplicate(const D4Group &g);
public:
/** @brief Mutable iterator over child groups. */
typedef vector<D4Group *>::iterator groupsIter;
/** @brief Read-only iterator over child groups. */
typedef vector<D4Group *>::const_iterator groupsCIter;
/** @brief Builds a group with a name. @param name Group name. */
D4Group(const string &name);
/** @brief Builds a group with name and dataset context. @param name Group name. @param dataset Dataset context. */
D4Group(const string &name, const string &dataset);
D4Group(const D4Group &rhs);
~D4Group() override;
/**
* @brief Assigns this group from another group.
* @param rhs Source group.
* @return This group after assignment.
*/
D4Group &operator=(const D4Group &rhs);
// This method returned a D4Group * previously. jhrg 11/17/16
BaseType *ptr_duplicate() override;
/** @brief Updates array dimension pointers after copy/parse operations. */
void update_variables_d4dimension_pointers();
// TODO Wire up the new D4Dimensions object to have this group as its parent. jhrg 8/22/22
/// Get the dimensions defined for this Group
D4Dimensions *dims() {
// If not built yet, make one and set this as parent.
if (!d_dims)
d_dims = new D4Dimensions(this);
return d_dims;
}
std::string FQN() const override;
D4Dimension *find_dim(const string &path);
Array *find_map_source(const string &path);
/**
* @brief Finds an enumeration definition by path.
* @param path Enumeration definition path.
* @return Matching definition or null.
*/
D4EnumDef *find_enum_def(const string &path);
/// Get the enumerations defined for this Group
D4EnumDefs *enum_defs() {
if (!d_enum_defs) {
d_enum_defs = new D4EnumDefs;
d_enum_defs->set_parent(this);
}
return d_enum_defs;
}
/// Check if this group contains enumerations.
bool has_enum_defs() const { return (d_enum_defs != nullptr); }
/**
* @brief Finds the first variable in this group hierarchy that uses a dimension.
* @param dim Dimension to search for.
* @return First matching variable or null.
*/
BaseType *find_first_var_that_uses_dimension(D4Dimension *dim);
/**
* @brief Finds the first variable in this group hierarchy that uses an enumeration.
* @param enum_def Enumeration definition to search for.
* @return First matching variable or null.
*/
BaseType *find_first_var_that_uses_enumeration(D4EnumDef *enum_def);
BaseType *find_var(const string &name);
/** @brief Returns all immediate child groups. */
const vector<D4Group *> &groups() const { return d_groups; }
/// Get an iterator to the start of the values
groupsIter grp_begin() { return d_groups.begin(); }
/// Get an iterator to the end of the values
groupsIter grp_end() { return d_groups.end(); }
/**
* @brief Appends a deep copy of a child group.
* @param g Child group to copy and append.
*/
void add_group(const D4Group *g) { add_group_nocopy(new D4Group(*g)); }
/**
* @brief Appends a child group pointer without copying.
* @param g Child group to append.
*/
void add_group_nocopy(D4Group *g) {
g->set_parent(this);
d_groups.push_back(g);
}
/**
* @brief Inserts a child group pointer before the given iterator.
* @param g Child group to insert.
* @param i Insertion point.
*/
void insert_group_nocopy(D4Group *g, groupsIter i) {
g->set_parent(this);
d_groups.insert(i, g);
}
/**
* @brief Finds an immediate child group by name.
* @param grp_name Child group name.
* @return Matching child group or null.
*/
D4Group *find_child_grp(const string &grp_name);
long request_size(bool constrained);
uint64_t request_size_kb(bool constrained);
void set_send_p(bool state) override;
void set_read_p(bool state) override;
bool is_dap4_projected(std::vector<std::string> &inventory) override;
// DAP4
void intern_data() override;
void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false) override;
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
void print_dap4(XMLWriter &xml, bool constrained = false) override;
void print_decl(ostream &out, string space = " ", bool print_semi = true, bool constraint_info = false,
bool constrained = false, bool is_root_grp = true, bool array_member = false) override;
void print_decl(FILE *out, string space = " ", bool print_semi = true, bool constraint_info = false,
bool constrained = false, bool is_root_grp = true, bool array_member = false) override;
void print_val(FILE *out, string space = "", bool print_decl_p = true, bool is_root_grp = true) override;
void print_val(ostream &out, string space = "", bool print_decl_p = true, bool is_root_grp = true) override;
std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table, bool show_shared_dims = false) override;
};
} /* namespace libdap */
#endif /* D4GROUP_H_ */