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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00024 00025 #ifndef D4DIMENSIONS_H_ 00026 #define D4DIMENSIONS_H_ 00027 00028 #include <string> 00029 #include <vector> 00030 00031 // #include "XMLWriter.h" 00032 00033 using namespace std; 00034 00035 namespace libdap { 00036 00037 class D4Group; 00038 class D4Dimensions; 00039 class XMLWriter; 00040 00041 class D4Dimension { 00042 string d_name; 00043 unsigned long d_size; 00044 00045 D4Dimensions *d_parent; // This is used to get the Dimensions and then the Group object 00046 00047 bool d_constrained; 00048 unsigned long long d_c_start, d_c_stride, d_c_stop; 00049 00050 bool d_used_by_projected_var; 00051 00052 public: 00053 D4Dimension() : d_name(""), d_size(0), d_parent(0), d_constrained(false), d_c_start(0), d_c_stride(0), 00054 d_c_stop(0), d_used_by_projected_var(false) {} 00055 D4Dimension(const string &name, unsigned long size, D4Dimensions *d = 0) : d_name(name), d_size(size), d_parent(d), 00056 d_constrained(false), d_c_start(0), d_c_stride(0), d_c_stop(0), d_used_by_projected_var(false) {} 00057 00058 string name() const {return d_name;} 00059 void set_name(const string &name) { d_name = name; } 00060 string fully_qualified_name() const; 00061 00062 unsigned long size() const { return d_size; } 00063 void set_size(unsigned long size) { d_size = size; } 00064 // Because we build these in the XML parser and it's all text... 00065 void set_size(const string &size); 00066 00067 D4Dimensions *parent() const { return d_parent; } 00068 void set_parent(D4Dimensions *d) { d_parent = d; } 00069 00070 bool constrained() const { return d_constrained; } 00071 unsigned long long c_start() const { return d_c_start; } 00072 unsigned long long c_stride() const { return d_c_stride; } 00073 unsigned long long c_stop() const { return d_c_stop; } 00074 00075 bool used_by_projected_var() const { return d_used_by_projected_var; } 00076 void set_used_by_projected_var(bool state) { d_used_by_projected_var = state; } 00077 00086 void set_constraint(unsigned long long start, unsigned long long stride, unsigned long long stop) { 00087 d_c_start = start; 00088 d_c_stride = stride; 00089 d_c_stop = stop; 00090 d_constrained = true; 00091 } 00092 00093 void print_dap4(XMLWriter &xml) const; 00094 }; 00095 00101 class D4Dimensions { 00102 vector<D4Dimension*> d_dims; 00103 00104 D4Group *d_parent; // the group that holds this set of D4Dimensions; weak pointer, don't delete 00105 00106 protected: 00107 // Note Code in Array depends on the order of these 'new' dimensions 00108 // matching the 'old' dimensions they are derived from. See 00109 // Array::update_dimension_pointers. jhrg 8/25/14 00110 void m_duplicate(const D4Dimensions &rhs) { 00111 D4DimensionsCIter i = rhs.d_dims.begin(); 00112 while (i != rhs.d_dims.end()) { 00113 d_dims.push_back(new D4Dimension(**i++)); // deep copy 00114 d_dims.back()->set_parent(this); // Set the Dimension's parent 00115 } 00116 00117 d_parent = rhs.d_parent; 00118 } 00119 00120 public: 00122 typedef vector<D4Dimension*>::iterator D4DimensionsIter; 00123 typedef vector<D4Dimension*>::const_iterator D4DimensionsCIter; 00124 00125 D4Dimensions() : d_parent(0) {} 00126 D4Dimensions(D4Group *g) : d_parent(g) {} 00127 D4Dimensions(const D4Dimensions &rhs) : d_parent(0) { m_duplicate(rhs); } 00128 00129 virtual ~D4Dimensions() { 00130 D4DimensionsIter i = d_dims.begin(); 00131 while (i != d_dims.end()) 00132 delete *i++; 00133 } 00134 00135 D4Dimensions &operator=(const D4Dimensions &rhs) { 00136 if (this == &rhs) return *this; 00137 m_duplicate(rhs); 00138 return *this; 00139 } 00140 00142 bool empty() const { return d_dims.empty(); } 00143 00144 D4Group *parent() const { return d_parent;} 00145 void set_parent(D4Group *g) { d_parent = g; } 00146 00155 void add_dim(D4Dimension *dim) { add_dim_nocopy(new D4Dimension(*dim)); } 00156 00160 void add_dim_nocopy(D4Dimension *dim) { dim->set_parent(this); d_dims.push_back(dim); } 00161 00163 D4DimensionsIter dim_begin() { return d_dims.begin(); } 00164 00166 D4DimensionsIter dim_end() { return d_dims.end(); } 00167 00168 D4Dimension *find_dim(const string &name); 00169 00177 void insert_dim(D4Dimension *dim, D4DimensionsIter i) { 00178 insert_dim_nocopy(new D4Dimension(*dim), i); 00179 } 00180 00185 void insert_dim_nocopy(D4Dimension *dim, D4DimensionsIter i) { 00186 dim->set_parent(this); 00187 d_dims.insert(i, dim); 00188 } 00189 00190 void print_dap4(XMLWriter &xml, bool constrained = false) const; 00191 }; 00192 00193 } /* namespace libdap */ 00194 #endif /* D4DIMENSIONS_H_ */