libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Dimensions.h
Go to the documentation of this file.
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of libdap, A C++ implementation of the OPeNDAP Data
4// Access Protocol.
5
6// Copyright (c) 2013 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#ifndef D4DIMENSIONS_H_
26#define D4DIMENSIONS_H_
27
28#include <string>
29#include <vector>
30
31// #include "XMLWriter.h"
32
33using namespace std;
34
35namespace libdap {
36
37class D4Group;
38class D4Dimensions;
39class XMLWriter;
40
42 string d_name;
43 unsigned long long d_size;
44
45 D4Dimensions *d_parent; // This is used to get the Dimensions and then the Group object
46
47 bool d_constrained;
48 int64_t d_c_start, d_c_stride, d_c_stop;
49
50 bool d_used_by_projected_var;
51
52public:
54 : d_name(""), d_size(0), d_parent(0), d_constrained(false), d_c_start(0), d_c_stride(0), d_c_stop(0),
55 d_used_by_projected_var(false) {}
56 D4Dimension(const string &name, unsigned long long size, D4Dimensions *d = 0)
57 : d_name(name), d_size(size), d_parent(d), d_constrained(false), d_c_start(0), d_c_stride(0), d_c_stop(0),
58 d_used_by_projected_var(false) {}
59
60 string name() const { return d_name; }
61 void set_name(const string &name) { d_name = name; }
62 string fully_qualified_name() const;
63
64 unsigned long long size() const { return d_size; }
65 void set_size(unsigned long long size) { d_size = size; }
66 // Because we build these in the XML parser and it's all text...
67 void set_size(const string &size);
68
69 D4Dimensions *parent() const { return d_parent; }
70 void set_parent(D4Dimensions *d) { d_parent = d; }
71
72 bool constrained() const { return d_constrained; }
73 int64_t c_start() const { return d_c_start; }
74 int64_t c_stride() const { return d_c_stride; }
75 int64_t c_stop() const { return d_c_stop; }
76
77 bool used_by_projected_var() const { return d_used_by_projected_var; }
78 void set_used_by_projected_var(bool state) { d_used_by_projected_var = state; }
79
88 void set_constraint(int64_t start, int64_t stride, int64_t stop) {
89 d_c_start = start;
90 d_c_stride = stride;
91 d_c_stop = stop;
92 d_constrained = true;
93 }
94
95 void print_dap4(XMLWriter &xml) const;
96};
97
104 vector<D4Dimension *> d_dims;
105
106 D4Group *d_parent; // the group that holds this set of D4Dimensions; weak pointer, don't delete
107
108protected:
109 // Note Code in Array depends on the order of these 'new' dimensions
110 // matching the 'old' dimensions they are derived from. See
111 // Array::update_dimension_pointers. jhrg 8/25/14
112 void m_duplicate(const D4Dimensions &rhs) {
113 D4DimensionsCIter i = rhs.d_dims.begin();
114 while (i != rhs.d_dims.end()) {
115 d_dims.push_back(new D4Dimension(**i++)); // deep copy
116 d_dims.back()->set_parent(this); // Set the Dimension's parent
117 }
118
119 d_parent = rhs.d_parent;
120 }
121
122public:
126
127 D4Dimensions() : d_parent(0) {}
128 D4Dimensions(D4Group *g) : d_parent(g) {}
129 D4Dimensions(const D4Dimensions &rhs) : d_parent(0) { m_duplicate(rhs); }
130
131 virtual ~D4Dimensions() {
132 D4DimensionsIter i = d_dims.begin();
133 while (i != d_dims.end())
134 delete *i++;
135 }
136
138 if (this == &rhs)
139 return *this;
140 m_duplicate(rhs);
141 return *this;
142 }
143
145 bool empty() const { return d_dims.empty(); }
146
147 D4Group *parent() const { return d_parent; }
148 void set_parent(D4Group *g) { d_parent = g; }
149
159
164 dim->set_parent(this);
165 d_dims.push_back(dim);
166 }
167
169 D4DimensionsIter dim_begin() { return d_dims.begin(); }
170
172 D4DimensionsIter dim_end() { return d_dims.end(); }
173
174 D4Dimension *find_dim(const string &name);
175
184
190 dim->set_parent(this);
191 d_dims.insert(i, dim);
192 }
193
194 void print_dap4(XMLWriter &xml, bool constrained = false) const;
195};
196
197} /* namespace libdap */
198#endif /* D4DIMENSIONS_H_ */
int64_t c_stop() const
void set_parent(D4Dimensions *d)
unsigned long long size() const
bool used_by_projected_var() const
string name() const
int64_t c_stride() const
D4Dimensions * parent() const
void print_dap4(XMLWriter &xml) const
Print the Dimension declaration. Print the Dimension in a form suitable for use in a Group definition...
void set_used_by_projected_var(bool state)
void set_size(unsigned long long size)
string fully_qualified_name() const
Get the FQN for the dimension.
int64_t c_start() const
bool constrained() const
D4Dimension(const string &name, unsigned long long size, D4Dimensions *d=0)
void set_name(const string &name)
void set_constraint(int64_t start, int64_t stride, int64_t stop)
D4Dimensions & operator=(const D4Dimensions &rhs)
D4Dimensions(D4Group *g)
vector< D4Dimension * >::iterator D4DimensionsIter
Iterator used for D4Dimensions.
void add_dim_nocopy(D4Dimension *dim)
vector< D4Dimension * >::const_iterator D4DimensionsCIter
void add_dim(D4Dimension *dim)
void m_duplicate(const D4Dimensions &rhs)
void insert_dim_nocopy(D4Dimension *dim, D4DimensionsIter i)
D4Dimension * find_dim(const string &name)
D4DimensionsIter dim_end()
Get an iterator to the end of the dimensions.
bool empty() const
Does this D4Dimensions object actually have dimensions?
D4DimensionsIter dim_begin()
Get an iterator to the start of the dimensions.
D4Dimensions(const D4Dimensions &rhs)
void insert_dim(D4Dimension *dim, D4DimensionsIter i)
void set_parent(D4Group *g)
D4Group * parent() const
void print_dap4(XMLWriter &xml, bool constrained=false) const
STL iterator class.
STL iterator class.
top level DAP object to house generic methods
Definition AISConnect.cc:30