libdap  Updated for version 3.17.0
D4Group.h
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 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00021 
00022 #ifndef D4GROUP_H_
00023 #define D4GROUP_H_
00024 
00025 #include <string>
00026 
00027 #include "Constructor.h"
00028 #include "D4Dimensions.h"
00029 #include "D4EnumDefs.h"
00030 
00031 class Crc32;
00032 
00033 namespace libdap {
00034 
00035 class BaseType;
00036 class Array;
00037 
00043 class D4Group :public Constructor {
00044 private:
00045     // Note that because Constructor is a BaseType, this class inherits
00046     // both a back pointer to its parent, an AttrTable and, directly from the
00047     // Constructor class, a vector of BaseTypes.
00048 
00049     // This instance of D4Dimensions holds the Group's definitions; the same
00050     // class is used by Array to hold the actual dimensions for a variable.
00051     D4Dimensions *d_dims;
00052 
00053     // This holds the Group's enumeration definitions; a different class is
00054     // used for the Enumeration type
00055     D4EnumDefs *d_enum_defs;
00056 
00057     // This is a pointer so that the factory class(es) that return pointers
00058     // work as expected when making Groups.
00059     vector<D4Group*> d_groups;
00060 
00061     BaseType *m_find_map_source_helper(const string &name);
00062 
00063 protected:
00064     void m_duplicate(const D4Group &g);
00065 
00066 public:
00067     typedef vector<D4Group*>::iterator groupsIter;
00068     typedef vector<D4Group*>::const_iterator groupsCIter;
00069 
00070     D4Group(const string &name);
00071     D4Group(const string &name, const string &dataset);
00072 
00073     D4Group(const D4Group &rhs);
00074     virtual ~D4Group();
00075 
00076     D4Group &operator=(const D4Group &rhs);
00077     virtual D4Group *ptr_duplicate();
00078 
00080     D4Dimensions *dims() {
00081         // If not built yet, make one and set this as parent.
00082         if (!d_dims) d_dims = new D4Dimensions(this);
00083         return d_dims;
00084     }
00085 
00086     virtual std::string FQN() const;
00087 
00088     D4Dimension *find_dim(const string &path);
00089 
00090     Array *find_map_source(const string &path);
00091 
00092     D4EnumDef *find_enum_def(const string &path);
00093 
00095     D4EnumDefs *enum_defs() {
00096         if (!d_enum_defs) {
00097                 d_enum_defs = new D4EnumDefs;
00098                 d_enum_defs->set_parent(this);
00099         }
00100         return d_enum_defs;
00101     }
00102 
00103     BaseType *find_first_var_that_uses_dimension(D4Dimension *dim);
00104     BaseType *find_first_var_that_uses_enumeration(D4EnumDef *enum_def);
00105 
00106     BaseType *find_var(const string &name);
00107 
00109     groupsIter grp_begin() { return d_groups.begin(); }
00110 
00112     groupsIter grp_end() { return d_groups.end(); }
00113 
00114     void add_group(const D4Group *g) {
00115         add_group_nocopy(new D4Group(*g));
00116     }
00117 
00118     void add_group_nocopy(D4Group *g) {
00119         g->set_parent(this);
00120         d_groups.push_back(g);
00121     }
00122     void insert_group_nocopy(D4Group *g, groupsIter i) {
00123         g->set_parent(this);
00124         d_groups.insert(i, g);
00125     }
00126 
00127     D4Group *find_child_grp(const string &grp_name);
00128 
00129     long request_size(bool constrained);
00130 
00131     virtual void set_send_p(bool state);
00132     virtual void set_read_p(bool state);
00133 
00134     // DAP4
00135     virtual void intern_data(/*Crc32 &checksum, DMR &dmr, ConstraintEvaluator &eval*/);
00136     virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
00137     virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
00138 
00139     void print_dap4(XMLWriter &xml, bool constrained = false);
00140 };
00141 
00142 } /* namespace libdap */
00143 #endif /* D4GROUP_H_ */