libdap++  Updated for version 3.8.2
BaseType.h
Go to the documentation of this file.
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 //         Dan Holloway <dan@hollywood.gso.uri.edu>
00010 //         Reza Nekovei <reza@intcomm.net>
00011 //
00012 // This library is free software; you can redistribute it and/or
00013 // modify it under the terms of the GNU Lesser General Public
00014 // License as published by the Free Software Foundation; either
00015 // version 2.1 of the License, or (at your option) any later version.
00016 //
00017 // This library is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00027 
00028 // (c) COPYRIGHT URI/MIT 1994-1999
00029 // Please read the full copyright statement in the file COPYRIGHT_URI.
00030 //
00031 // Authors:
00032 //      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
00033 //      dan             Dan Holloway <dan@hollywood.gso.uri.edu>
00034 //      reza            Reza Nekovei <reza@intcomm.net>
00035 
00036 // Abstract base class for the variables in a dataset. This is used to store
00037 // the type-invariant information that describes a variable as given in the
00038 // DODS API.
00039 //
00040 // jhrg 9/6/94
00041 
00042 #ifndef _basetype_h
00043 #define _basetype_h 1
00044 
00045 
00046 #include <vector>
00047 #include <stack>
00048 #include <iostream>
00049 #include <string>
00050 
00051 #ifndef _attrtable_h
00052 #include "AttrTable.h"
00053 #endif
00054 
00055 #ifndef _internalerr_h
00056 #include "InternalErr.h"
00057 #endif
00058 
00059 #ifndef __DODS_DATATYPES_
00060 #include "dods-datatypes.h"
00061 #endif
00062 
00063 #ifndef A_DapObj_h
00064 #include "DapObj.h"
00065 #endif
00066 
00067 #ifndef XMLWRITER_H_
00068 #include "XMLWriter.h"
00069 #endif
00070 
00071 #include "Marshaller.h"
00072 #include "UnMarshaller.h"
00073 
00074 #define FILE_METHODS 1
00075 
00076 using namespace std;
00077 
00078 namespace libdap
00079 {
00080 
00081 class DDS;
00082 class ConstraintEvaluator;
00083 
00102 enum Part {
00103     nil,   // nil is for types that don't have parts...
00104     array,
00105     maps
00106 };
00107 
00135 enum Type {
00136     dods_null_c,
00137     dods_byte_c,
00138     dods_int16_c,
00139     dods_uint16_c,
00140     dods_int32_c,  // Added `dods_' to fix clash with IRIX 5.3.
00141     dods_uint32_c,
00142     dods_float32_c,
00143     dods_float64_c,
00144     dods_str_c,
00145     dods_url_c,
00146     dods_array_c,
00147     dods_structure_c,
00148     dods_sequence_c,
00149     dods_grid_c
00150 };
00151 
00194 class BaseType : public DapObj
00195 {
00196 private:
00197     string _name;  // name of the instance
00198     Type _type;   // instance's type
00199     string _dataset; // name of the dataset used to create this BaseType
00200 
00201     bool _read_p;  // true if the value has been read
00202     bool _send_p;  // Is the variable in the projection?
00203     bool d_in_selection; // Is the variable in the selection?
00204     bool _synthesized_p; // true if the variable is synthesized
00205 
00206     // d_parent points to the Constructor or Vector which holds a particular
00207     // variable. It is null for simple variables. The Vector and Constructor
00208     // classes must maintain this variable.
00209     BaseType *d_parent;
00210 
00211     // Attributes for this variable. Added 05/20/03 jhrg
00212     AttrTable d_attr;
00213 
00214 protected:
00215     void _duplicate(const BaseType &bt);
00216 
00217 public:
00218     typedef stack<BaseType *> btp_stack;
00219 
00220     BaseType(const string &n, const Type &t);
00221     BaseType(const string &n, const string &d, const Type &t);
00222 
00223     BaseType(const BaseType &copy_from);
00224     virtual ~BaseType();
00225 
00226     virtual string toString();
00227 
00228     virtual void dump(ostream &strm) const ;
00229 
00230     BaseType &operator=(const BaseType &rhs);
00231 
00238     virtual BaseType *ptr_duplicate() = 0;
00239 
00240     string name() const;
00241     virtual void set_name(const string &n);
00242 
00243     Type type() const;
00244     void set_type(const Type &t);
00245     string type_name() const;
00246 
00247     string dataset() const ;
00248 
00249     virtual bool is_simple_type();
00250     virtual bool is_vector_type();
00251     virtual bool is_constructor_type();
00252 
00253     virtual bool synthesized_p();
00254     virtual void set_synthesized_p(bool state);
00255 
00256     virtual int element_count(bool leaves = false);
00257 
00258     virtual bool read_p();
00259     virtual void set_read_p(bool state);
00260 
00261     virtual bool send_p();
00262     virtual void set_send_p(bool state);
00263 
00264     virtual AttrTable &get_attr_table();
00265     virtual void set_attr_table(const AttrTable &at);
00266 
00267     virtual bool is_in_selection();
00268     virtual void set_in_selection(bool state);
00269 
00270     virtual void set_parent(BaseType *parent);
00271     virtual BaseType *get_parent();
00272 
00273     virtual void transfer_attributes(AttrTable *at);
00274 
00275     // I put this comment here because the version in BaseType.cc does not
00276     // include the exact_match or s variables since they are not used. Doxygen
00277     // was gaging on the comment.
00278 
00309     virtual BaseType *var(const string &name = "", bool exact_match = true,
00310                           btp_stack *s = 0);
00311     virtual BaseType *var(const string &name, btp_stack &s);
00312 
00313     virtual void add_var(BaseType *bt, Part part = nil);
00314 
00315     virtual bool read();
00316 
00317     virtual bool check_semantics(string &msg, bool all = false);
00318 
00319     virtual bool ops(BaseType *b, int op);
00320 #if FILE_METHODS
00321     virtual void print_decl(FILE *out, string space = "    ",
00322                             bool print_semi = true,
00323                             bool constraint_info = false,
00324                             bool constrained = false);
00325 
00326     virtual void print_xml(FILE *out, string space = "    ",
00327                            bool constrained = false);
00328 #endif
00329     virtual void print_decl(ostream &out, string space = "    ",
00330                             bool print_semi = true,
00331                             bool constraint_info = false,
00332                             bool constrained = false);
00333 
00334     virtual void print_xml(ostream &out, string space = "    ",
00335                            bool constrained = false);
00336 
00337     virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
00338 
00341 
00353     virtual unsigned int width() = 0;
00354     virtual unsigned int width(bool constrained);
00355 
00376     virtual unsigned int buf2val(void **val) = 0;
00377 
00407     virtual unsigned int val2buf(void *val, bool reuse = false) = 0;
00408 
00421     virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
00422 
00450     virtual bool serialize(ConstraintEvaluator &eval, DDS &dds,
00451                            Marshaller &m, bool ce_eval = true) = 0;
00452 
00477     virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) = 0;
00478 
00479 #if FILE_METHODS
00480 
00495     virtual void print_val(FILE *out, string space = "",
00496                            bool print_decl_p = true) = 0;
00497 #endif
00498 
00513     virtual void print_val(ostream &out, string space = "",
00514                            bool print_decl_p = true) = 0;
00516 };
00517 
00518 } // namespace libdap
00519 
00520 #endif // _basetype_h