libdap Updated for version 3.20.11
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
31using namespace std;
32
33namespace libdap {
34
35class Array;
36class XMLWriter;
37
54class D4Map {
55 std::string d_name;
56 Array *d_array; // the actual map data; weak pointer
57 Array *d_parent; // what array holds this map; weak pointer
58
59public:
60 D4Map() : d_name(""), d_array(0), d_parent(0) { }
61 D4Map(const string &name, Array *array, Array *parent = 0) : d_name(name), d_array(array), d_parent(parent) { }
62
63 virtual ~D4Map() { }
64
65 const string& name() const { return d_name; }
66 void set_name(const string& name) { d_name = name; }
67
68 const Array* array() const { return d_array; }
69 void set_array(Array* array) { d_array = array; }
70
74 const Array* parent() const { return d_parent; }
75 void set_parent(Array* parent) { d_parent = parent; }
76
77 virtual void print_dap4(XMLWriter &xml);
78};
79
84class D4Maps {
85public:
86 typedef vector<D4Map*>::iterator D4MapsIter;
87 typedef vector<D4Map*>::const_iterator D4MapsCIter;
88
89private:
90 vector<D4Map*> d_maps;
91 Array *d_parent; // Array these Maps belong to; weak pointer
92
93 void m_duplicate(const D4Maps &maps) {
94 d_parent = maps.d_parent;
95 for (D4MapsCIter ci = maps.d_maps.begin(), ce = maps.d_maps.end(); ci != ce; ++ci) {
96 d_maps.push_back(new D4Map(**ci));
97 }
98 }
99
100public:
101 D4Maps() {}
102 D4Maps(Array* parent) : d_parent(parent) { }
103 D4Maps(const D4Maps &maps) { m_duplicate(maps); }
104 virtual ~D4Maps() {
105 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
106 delete *i;
107 }
108
109 D4Maps &operator=(const D4Maps &rhs);
110
115 void add_map(D4Map *map) {
116 d_maps.push_back(map);
117 // if the Map parent is not set, do so now
118 if (!d_maps.back()->parent())
119 d_maps.back()->set_parent(d_parent);
120 }
121
122 void remove_map(D4Map *map) {
123 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i) {
124 /* && (*i)->parent() == map->parent() */
125 // Don't test if the map->parent() matches - we only care about the name and array.
126 // This method is intended for processing CE array slices that are edge cases and
127 // is only called from code where we know map->parent() matches *i->parent().
128 // jhrg 4/12/16
129 if ((*i)->name() == map->name() && (*i)->array() == map->array()) {
130 d_maps.erase(i);
131 break;
132 }
133 }
134 }
135
136 D4Map* get_map(int i) { return d_maps.at(i); }
137
138 D4MapsIter map_begin() { return d_maps.begin(); }
139 D4MapsIter map_end() { return d_maps.end(); }
140
141 int size() const { return d_maps.size(); }
142 bool empty() const { return d_maps.empty(); }
143
144 virtual void print_dap4(XMLWriter &xml) {
145 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
146 (*i)->print_dap4(xml);
147 }
148};
149
150} /* namespace libdap */
151#endif /* D4MAPS_H_ */
A multidimensional array of identical data types.
Definition: Array.h:113
const Array * parent() const
The Array that holds this Map.
Definition: D4Maps.h:74
void add_map(D4Map *map)
Definition: D4Maps.h:115
top level DAP object to house generic methods
Definition: AlarmHandler.h:36