libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Maps.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., 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) : d_name(std::move(name)), d_array(array) {}
83 D4Map(std::string name, Array *array, BaseType * /*parent*/) : d_name(std::move(name)), d_array(array) {}
84 D4Map(std::string name, std::string array) : d_name(std::move(name)), d_array_path(std::move(array)) {}
86 virtual ~D4Map() = default;
87
88 const string &name() const { return d_name; }
89 void set_name(const string &name) { d_name = name; }
90
91 const std::string &get_array_path() const { return d_array_path; }
93 void set_array_path(const std::string &array) { d_array_path = array; }
94
97
99 Array *array(D4Group *root);
101 Array *array() const { return d_array; }
103
105 d_array = array;
106 d_array_path = array->FQN();
107 }
108
109 virtual void print_dap4(XMLWriter &xml);
110};
111
116class D4Maps {
117public:
120
121private:
122 vector<D4Map *> d_maps;
123 const Array *d_parent; // Array these Maps belong to; weak pointer
124
125 void m_duplicate(const D4Maps &maps, const Array *parent) {
126 d_parent = parent;
127 d_maps.reserve(maps.size());
128 for (auto const map : maps.d_maps) {
129 d_maps.emplace_back(new D4Map(map->name(), map->get_array_path()));
130 }
131 }
132
133public:
134 D4Maps() = default;
135
136 // See comment below at operator=(). jhrg 9/12/23
137 D4Maps(const D4Maps &maps) = delete;
138
139 explicit D4Maps(const Array *parent) : d_parent(parent) {}
140 D4Maps(const D4Maps &maps, const Array *parent) { m_duplicate(maps, parent); }
141
142 virtual ~D4Maps() {
143 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
144 delete *i;
145 }
146
147 // I deleted this because this class needs to set the _parent_ pointer to
148 // the Array that holds these maps. The one argument assignment operator
149 // provides no way to include that information. jhrg 9/12/23
150 D4Maps &operator=(const D4Maps &rhs) = delete;
151
156 void add_map(D4Map *map) { d_maps.push_back(map); }
157
158 void remove_map(D4Map *map) {
159 // TODO Refactor this to use erase() and find_if(). There is no reason
160 // to code an explicit loop like this in C++11. jhrg 9/16/22
161 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i) {
162 /* && (*i)->parent() == map->parent() */
163 // Don't test if the map->parent() matches - we only care about the name and array.
164 // This method is intended for processing CE array slices that are edge cases and
165 // is only called from code where we know map->parent() matches *i->parent().
166 // jhrg 4/12/16
167 if ((*i)->name() == map->name()) {
168 d_maps.erase(i);
169 break;
170 }
171 }
172 }
173
174 D4Map *get_map(int i) { return d_maps.at(i); }
175
176 D4MapsIter map_begin() { return d_maps.begin(); }
177 D4MapsIter map_end() { return d_maps.end(); }
178
179 int size() const { return d_maps.size(); }
180 bool empty() const { return d_maps.empty(); }
181
182 virtual void print_dap4(XMLWriter &xml) {
183 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
184 (*i)->print_dap4(xml);
185 }
186};
187
188} /* namespace libdap */
189#endif /* D4MAPS_H_ */
A multidimensional array of identical data types.
Definition Array.h:121
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual void print_dap4(XMLWriter &xml)
Definition D4Maps.cc:47
Array * array(D4Group *root)
This will always return the correct pointer for a valid data set.
Definition D4Maps.cc:36
const string & name() const
Definition D4Maps.h:88
Array * array() const
Only use this accessor in code that can deal with a nullptr return!
Definition D4Maps.h:101
void set_array(Array *array)
Definition D4Maps.h:104
D4Map(std::string name, Array *array, BaseType *)
Definition D4Maps.h:83
D4Map(std::string name, std::string array)
Definition D4Maps.h:84
void set_array_path(const std::string &array)
Definition D4Maps.h:93
D4Map()=default
D4Map(std::string name, Array *array)
Definition D4Maps.h:80
virtual ~D4Map()=default
void set_name(const string &name)
Definition D4Maps.h:89
const std::string & get_array_path() const
Definition D4Maps.h:91
int size() const
Definition D4Maps.h:179
D4Maps(const Array *parent)
Definition D4Maps.h:139
D4MapsIter map_begin()
Definition D4Maps.h:176
vector< D4Map * >::iterator D4MapsIter
Definition D4Maps.h:118
D4Maps(const D4Maps &maps, const Array *parent)
Definition D4Maps.h:140
D4Maps()=default
vector< D4Map * >::const_iterator D4MapsCIter
Definition D4Maps.h:119
D4Maps(const D4Maps &maps)=delete
D4Maps & operator=(const D4Maps &rhs)=delete
D4MapsIter map_end()
Definition D4Maps.h:177
void remove_map(D4Map *map)
Definition D4Maps.h:158
virtual ~D4Maps()
Definition D4Maps.h:142
D4Map * get_map(int i)
Definition D4Maps.h:174
bool empty() const
Definition D4Maps.h:180
virtual void print_dap4(XMLWriter &xml)
Definition D4Maps.h:182
void add_map(D4Map *map)
Definition D4Maps.h:156
STL iterator class.
STL iterator class.
top level DAP object to house generic methods
Definition AISConnect.cc:30
@ maps
Definition Type.h:51