libdap++  Updated for version 3.14.0
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 using namespace std;
32 
33 namespace libdap {
34 
35 class Array;
36 class XMLWriter;
37 
38 class D4Map {
39  std::string d_name;
40  Array *d_array; // the actual map data; weak pointer
41  Array *d_parent; // what array holds this map; weak pointer
42 
43 public:
44  D4Map() : d_name(""), d_array(0), d_parent(0) { }
45  D4Map(const string &name, Array *array, Array *parent = 0) : d_name(name), d_array(array), d_parent(parent) { }
46 
47  virtual ~D4Map() { }
48 
49  const string& name() const { return d_name; }
50  void set_name(const string& name) { d_name = name; }
51 
52  const Array* array() const { return d_array; }
53  void set_array(Array* array) { d_array = array; }
54 
58  const Array* parent() const { return d_parent; }
59  void set_parent(Array* parent) { d_parent = parent; }
60 
61  virtual void print_dap4(XMLWriter &xml);
62 };
63 
70 class D4Maps {
71 public:
72  typedef vector<D4Map*>::iterator D4MapsIter;
73  typedef vector<D4Map*>::const_iterator D4MapsCIter;
74 
75 private:
76  vector<D4Map*> d_maps;
77  Array *d_parent; // Array these Maps belong to; weak pointer
78 
79  void m_duplicate(const D4Maps &maps) {
80  d_parent = maps.d_parent;
81  for (D4MapsCIter ci = maps.d_maps.begin(), ce = maps.d_maps.end(); ci != ce; ++ci) {
82  d_maps.push_back(new D4Map(**ci));
83  }
84  }
85 
86 public:
87  D4Maps() {}
88  D4Maps(Array* parent) : d_parent(parent) { }
89  D4Maps(const D4Maps &maps) { m_duplicate(maps); }
90  virtual ~D4Maps() {
91  for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
92  delete *i;
93  }
94 
95  D4Maps &operator=(const D4Maps &rhs);
96 
97  void add_map(D4Map *map) {
98  d_maps.push_back(map);
99  // if the Map parent is not set, do so now
100  if (!d_maps.back()->parent())
101  d_maps.back()->set_parent(d_parent);
102  }
103 
104  D4Map* get_map(int i) { return d_maps.at(i); }
105 
106  D4MapsIter map_begin() { return d_maps.begin(); }
107  D4MapsIter map_end() { return d_maps.end(); }
108 
109  int size() const { return d_maps.size(); }
110  bool empty() const { return d_maps.empty(); }
111 
112  virtual void print_dap4(XMLWriter &xml) {
113  for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i)
114  (*i)->print_dap4(xml);
115  }
116 };
117 
118 } /* namespace libdap */
119 #endif /* D4MAPS_H_ */
D4MapsIter map_end()
Definition: D4Maps.h:107
vector< D4Map * >::iterator D4MapsIter
Definition: D4Maps.h:72
virtual void print_dap4(XMLWriter &xml)
Definition: D4Maps.h:112
const Array * parent() const
The Array that holds this Map.
Definition: D4Maps.h:58
D4Maps(const D4Maps &maps)
Definition: D4Maps.h:89
D4Map * get_map(int i)
Definition: D4Maps.h:104
virtual ~D4Map()
Definition: D4Maps.h:47
const string & name() const
Definition: D4Maps.h:49
void set_name(const string &name)
Definition: D4Maps.h:50
int size() const
Definition: D4Maps.h:109
virtual ~D4Maps()
Definition: D4Maps.h:90
D4Map(const string &name, Array *array, Array *parent=0)
Definition: D4Maps.h:45
const Array * array() const
Definition: D4Maps.h:52
void set_parent(Array *parent)
Definition: D4Maps.h:59
void add_map(D4Map *map)
Definition: D4Maps.h:97
D4Maps(Array *parent)
Definition: D4Maps.h:88
void set_array(Array *array)
Definition: D4Maps.h:53
A multidimensional array of identical data types.
Definition: Array.h:112
bool empty() const
Definition: D4Maps.h:110
vector< D4Map * >::const_iterator D4MapsCIter
Definition: D4Maps.h:73
D4MapsIter map_begin()
Definition: D4Maps.h:106