libdap
Updated for version 3.17.0
|
00001 // -*- mode: c++; c-basic-offset:4 -*- 00002 00003 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00004 // Access Protocol. 00005 00006 // Copyright (c) 2013 OPeNDAP, Inc. 00007 // Author: James Gallagher <jgallagher@opendap.org> 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 // 00023 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00024 00025 #ifndef D4MAPS_H_ 00026 #define D4MAPS_H_ 00027 00028 #include <string> 00029 #include <vector> 00030 00031 using namespace std; 00032 00033 namespace libdap { 00034 00035 class Array; 00036 class XMLWriter; 00037 00038 class D4Map { 00039 std::string d_name; 00040 Array *d_array; // the actual map data; weak pointer 00041 Array *d_parent; // what array holds this map; weak pointer 00042 00043 public: 00044 D4Map() : d_name(""), d_array(0), d_parent(0) { } 00045 D4Map(const string &name, Array *array, Array *parent = 0) : d_name(name), d_array(array), d_parent(parent) { } 00046 00047 virtual ~D4Map() { } 00048 00049 const string& name() const { return d_name; } 00050 void set_name(const string& name) { d_name = name; } 00051 00052 const Array* array() const { return d_array; } 00053 void set_array(Array* array) { d_array = array; } 00054 00058 const Array* parent() const { return d_parent; } 00059 void set_parent(Array* parent) { d_parent = parent; } 00060 00061 virtual void print_dap4(XMLWriter &xml); 00062 }; 00063 00070 class D4Maps { 00071 public: 00072 typedef vector<D4Map*>::iterator D4MapsIter; 00073 typedef vector<D4Map*>::const_iterator D4MapsCIter; 00074 00075 private: 00076 vector<D4Map*> d_maps; 00077 Array *d_parent; // Array these Maps belong to; weak pointer 00078 00079 void m_duplicate(const D4Maps &maps) { 00080 d_parent = maps.d_parent; 00081 for (D4MapsCIter ci = maps.d_maps.begin(), ce = maps.d_maps.end(); ci != ce; ++ci) { 00082 d_maps.push_back(new D4Map(**ci)); 00083 } 00084 } 00085 00086 public: 00087 D4Maps() {} 00088 D4Maps(Array* parent) : d_parent(parent) { } 00089 D4Maps(const D4Maps &maps) { m_duplicate(maps); } 00090 virtual ~D4Maps() { 00091 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i) 00092 delete *i; 00093 } 00094 00095 D4Maps &operator=(const D4Maps &rhs); 00096 00097 void add_map(D4Map *map) { 00098 d_maps.push_back(map); 00099 // if the Map parent is not set, do so now 00100 if (!d_maps.back()->parent()) 00101 d_maps.back()->set_parent(d_parent); 00102 } 00103 00104 D4Map* get_map(int i) { return d_maps.at(i); } 00105 00106 D4MapsIter map_begin() { return d_maps.begin(); } 00107 D4MapsIter map_end() { return d_maps.end(); } 00108 00109 int size() const { return d_maps.size(); } 00110 bool empty() const { return d_maps.empty(); } 00111 00112 virtual void print_dap4(XMLWriter &xml) { 00113 for (D4MapsIter i = d_maps.begin(), e = d_maps.end(); i != e; ++i) 00114 (*i)->print_dap4(xml); 00115 } 00116 }; 00117 00118 } /* namespace libdap */ 00119 #endif /* D4MAPS_H_ */