libdap  Updated for version 3.17.0
Constructor.h
00001 
00002 // -*- mode: c++; c-basic-offset:4 -*-
00003 
00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00005 // Access Protocol.
00006 
00007 // Copyright (c) 2002,2003 OPeNDAP, Inc.
00008 // Author: James Gallagher <jgallagher@opendap.org>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00025 
00026 #ifndef _constructor_h
00027 #define _constructor_h 1
00028 
00029 #include <vector>
00030 
00031 #include "BaseType.h"
00032 
00033 class Crc32;
00034 
00035 namespace libdap
00036 {
00037 
00038 class DMR;
00039 class XMLWriter;
00040 class D4StreamUnMarshaller;
00041 
00043 class Constructor: public BaseType
00044 {
00045 private:
00046     Constructor();  // No default ctor.
00047 
00048 protected:
00049     std::vector<BaseType *> d_vars;
00050 
00051     void m_duplicate(const Constructor &s);
00052     BaseType *m_leaf_match(const string &name, btp_stack *s = 0);
00053     BaseType *m_exact_match(const string &name, btp_stack *s = 0);
00054 
00055     Constructor(const string &name, const Type &type, bool is_dap4 = false);
00056     Constructor(const string &name, const string &d, const Type &type, bool is_dap4 = false);
00057 
00058     Constructor(const Constructor &copy_from);
00059 
00060 public:
00061     typedef std::vector<BaseType *>::const_iterator Vars_citer ;
00062     typedef std::vector<BaseType *>::iterator Vars_iter ;
00063     typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
00064 
00065     virtual ~Constructor();
00066 
00067     Constructor &operator=(const Constructor &rhs);
00068     BaseType *transform_to_dap4(D4Group *root, Constructor *dest);
00069 
00070     virtual std::string FQN() const;
00071 
00072     virtual int element_count(bool leaves = false);
00073 
00074     virtual void set_send_p(bool state);
00075     virtual void set_read_p(bool state);
00076 
00077     virtual unsigned int width(bool constrained = false) const;
00078 #if 0
00079     virtual unsigned int width(bool constrained);
00080 #endif
00081     // TODO Rewrite these methods to use the back pointers and keep this
00082     // for older code.
00084     virtual BaseType *var(const string &name, bool exact_match = true, btp_stack *s = 0);
00086     virtual BaseType *var(const string &n, btp_stack &s);
00087 
00088     Vars_iter var_begin();
00089     Vars_iter var_end();
00090     Vars_riter var_rbegin();
00091     Vars_riter var_rend();
00092     Vars_iter get_vars_iter(int i);
00093     BaseType *get_var_index(int i);
00094 
00095     virtual void add_var(BaseType *bt, Part part = nil);
00096     virtual void add_var_nocopy(BaseType *bt, Part part = nil);
00097 
00098     virtual void del_var(const string &name);
00099     virtual void del_var(Vars_iter i);
00100 
00101     virtual bool read();
00102 
00103     // DAP2
00104     virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
00105     virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
00106     virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
00107 
00108     // DAP4
00109     virtual void compute_checksum(Crc32 &checksum);
00110     virtual void intern_data(/*Crc32 &checksum, DMR &dmr, ConstraintEvaluator &eval*/);
00111     virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
00112     virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
00113 
00114     // Do not store values in memory as for C; users work with the C++ objects
00115     virtual unsigned int val2buf(void *, bool) {
00116         throw InternalErr(__FILE__, __LINE__, "Never use this method; see the programmer's guide documentation.");
00117     }
00118     virtual unsigned int buf2val(void **) {
00119         throw InternalErr(__FILE__, __LINE__, "Never use this method; see the programmer's guide documentation.");
00120     }
00121 
00122     virtual bool is_linear();
00123     virtual void set_in_selection(bool state);
00124 
00125     virtual void print_decl(ostream &out, string space = "    ",
00126                             bool print_semi = true,
00127                             bool constraint_info = false,
00128                             bool constrained = false);
00129 
00130     virtual void print_xml(ostream &out, string space = "    ",
00131                            bool constrained = false);
00132 
00133     void print_dap4(XMLWriter &xml, bool constrained = false);
00134 
00135     virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
00136 
00137     virtual void print_decl(FILE *out, string space = "    ",
00138                             bool print_semi = true,
00139                             bool constraint_info = false,
00140                             bool constrained = false);
00141     virtual void print_xml(FILE *out, string space = "    ",
00142                            bool constrained = false);
00143 
00144     virtual void print_val(FILE *out, string space = "",
00145                            bool print_decl_p = true);
00146     virtual void print_val(ostream &out, string space = "",
00147                            bool print_decl_p = true);
00148 
00149     virtual bool check_semantics(string &msg, bool all = false);
00150 
00151     virtual void dump(ostream &strm) const ;
00152 };
00153 
00154 } // namespace libdap
00155 
00156 #endif // _constructor_h