libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Maps.h
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#ifndef D4MAPS_H_
26#define D4MAPS_H_
27
28#include <string>
29#include <vector>
30
31#include "Array.h"
32
33using namespace std;
34
35namespace libdap {
36
37class Array;
38class XMLWriter;
39
71class D4Map {
72 std::string d_name;
73 std::string d_array_path;
74 Array *d_array = nullptr; // the actual map data; cached weak pointer
75
76public:
77 D4Map() = default;
80 D4Map(std::string name, Array *array)
81 : d_name(std::move(name)), d_array(array) { }
82
84 D4Map(std::string name, Array *array, BaseType * /*parent*/)
85 : d_name(std::move(name)), d_array(array) { }
86 D4Map(std::string name, std::string array)
87 : d_name(std::move(name)), d_array_path(std::move(array)) { }
89 virtual ~D4Map() = default;
90
91 const string& name() const { return d_name; }
92 void set_name(const string& name) { d_name = name; }
93
94 const std::string &get_array_path() const { return d_array_path; }
96 void set_array_path(const std::string &array) { d_array_path = array; }
97
100
102 Array* array(D4Group *root);
104 Array* array() const { return d_array; }
106
107 void set_array(Array *array) {
108 d_array = array;
109 d_array_path = array->FQN();
110 }
111
112 virtual void print_dap4(XMLWriter &xml);
113};
114
119class D4Maps {
120public:
121 typedef vector<D4Map*>::iterator D4MapsIter;
122 typedef vector<D4Map*>::const_iterator D4MapsCIter;
123
124private:
125 vector<D4Map*> d_maps;
126 const Array *d_parent; // Array these Maps belong to; weak pointer
127
128 void m_duplicate(const D4Maps &maps, const Array *parent) {
129 d_parent = parent;
130 d_maps.reserve(maps.size());
131 for (auto const map: maps.d_maps) {
132 d_maps.emplace_back(new D4Map(map->name(), map->get_array_path()));
133 }
134 }
135
136public:
137 D4Maps() = default;
138
139 // See comment below at operator=(). jhrg 9/12/23
140 D4Maps(const D4Maps &maps) = delete;
141
142 explicit D4Maps(const Array* parent) : d_parent(parent) { }
143 D4Maps(const D4Maps &maps, const Array *parent) { m_duplicate(maps, parent); }
144
145 virtual ~D4Maps() {
146 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
147 delete *i;
148 }
149
150 // I deleted this because this class needs to set the _parent_ pointer to
151 // the Array that holds these maps. The one argument assignment operator
152 // provides no way to include that information. jhrg 9/12/23
153 D4Maps &operator=(const D4Maps &rhs) = delete;
154
159 void add_map(D4Map *map) {
160 d_maps.push_back(map);
161 }
162
163 void remove_map(D4Map *map) {
164 // TODO Refactor this to use erase() and find_if(). There is no reason
165 // to code an explicit loop like this in C++11. jhrg 9/16/22
166 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i) {
167 /* && (*i)->parent() == map->parent() */
168 // Don't test if the map->parent() matches - we only care about the name and array.
169 // This method is intended for processing CE array slices that are edge cases and
170 // is only called from code where we know map->parent() matches *i->parent().
171 // jhrg 4/12/16
172 if ((*i)->name() == map->name()) {
173 d_maps.erase(i);
174 break;
175 }
176 }
177 }
178
179 D4Map* get_map(int i) { return d_maps.at(i); }
180
181 D4MapsIter map_begin() { return d_maps.begin(); }
182 D4MapsIter map_end() { return d_maps.end(); }
183
184 int size() const { return d_maps.size(); }
185 bool empty() const { return d_maps.empty(); }
186
187 virtual void print_dap4(XMLWriter &xml) {
188 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
189 (*i)->print_dap4(xml);
190 }
191};
192
193} /* namespace libdap */
194#endif /* D4MAPS_H_ */
A multidimensional array of identical data types.
Definition Array.h:123
The basic data type for the DODS DAP types.
Definition BaseType.h:120
Array * array(D4Group *root)
This will always return the correct pointer for a valid data set.
Definition D4Maps.cc:36
Array * array() const
Only use this accessor in code that can deal with a nullptr return!
Definition D4Maps.h:104
D4Map(std::string name, Array *array, BaseType *)
Definition D4Maps.h:84
void set_array_path(const std::string &array)
Definition D4Maps.h:96
D4Map(std::string name, Array *array)
Definition D4Maps.h:80
void add_map(D4Map *map)
Definition D4Maps.h:159
STL iterator class.
STL iterator class.
top level DAP object to house generic methods
Definition AISConnect.cc:30