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 #ifdef WIN32
00047 #include <rpc.h>
00048 #include <winsock2.h>
00049 #include <xdr.h>
00050 #define xdr_proc_t int *
00051 #else
00052 #include <rpc/types.h>
00053 #include <netinet/in.h>
00054 #include <rpc/xdr.h>
00055 #endif
00056 
00057 #include <vector>
00058 #include <stack>
00059 #include <iostream>
00060 #include <string>
00061 
00062 #ifndef _attrtable_h
00063 #include "AttrTable.h"
00064 #endif
00065 
00066 #ifndef _internalerr_h
00067 #include "InternalErr.h"
00068 #endif
00069 
00070 #ifndef __DODS_DATATYPES_
00071 #include "dods-datatypes.h"
00072 #endif
00073 
00074 #ifndef A_DapObj_h
00075 #include "DapObj.h"
00076 #endif
00077 
00078 using namespace std;
00079 
00080 class BaseType;   // Forward declarations
00081 class DDS;
00082 class ConstraintEvaluator;
00083 
00084 typedef stack<BaseType *> btp_stack;
00085 
00104 enum Part {
00105     nil,   // nil is for types that don't have parts...
00106     array,
00107     maps
00108 };
00109 
00137 enum Type {
00138     dods_null_c,
00139     dods_byte_c,
00140     dods_int16_c,
00141     dods_uint16_c,
00142     dods_int32_c,  // Added `dods_' to fix clash with IRIX 5.3.
00143     dods_uint32_c,
00144     dods_float32_c,
00145     dods_float64_c,
00146     dods_str_c,
00147     dods_url_c,
00148     dods_array_c,
00149     dods_structure_c,
00150     dods_sequence_c,
00151     dods_grid_c
00152 };
00153 
00196 class BaseType : public DapObj
00197 {
00198 private:
00199     string _name;  // name of the instance
00200     Type _type;   // instance's type
00201 
00202     // xdr_coder is used as an argument to xdr procedures that encode groups
00203     // of things (e.g., xdr_array()). Each leaf class's constructor must set
00204     // this.
00205     xdrproc_t _xdr_coder;
00206 
00207     bool _read_p;  // true if the value has been read
00208     bool _send_p;  // Is the variable in the projection?
00209     bool d_in_selection; // Is the variable in the selection?
00210     bool _synthesized_p; // true if the variable is synthesized
00211 
00212     // d_parent points to the Constructor or Vector which holds a particular
00213     // variable. It is null for simple variables. The Vector and Constructor
00214     // classes must maintain this variable.
00215     BaseType *d_parent;
00216 
00217     // Attributes for this variable. Added 05/20/03 jhrg
00218     AttrTable d_attr;
00219 
00220 protected:
00221     void _duplicate(const BaseType &bt);
00222 
00223 public:
00224     BaseType(const string &n = "", const Type &t = dods_null_c,
00225              xdrproc_t xdr = NULL);
00226 
00227     BaseType(const BaseType &copy_from);
00228     virtual ~BaseType();
00229 
00230     virtual string toString();
00231 
00232     virtual void dump(ostream &strm) const ;
00233 
00234     BaseType &operator=(const BaseType &rhs);
00235 
00242     virtual BaseType *ptr_duplicate() = 0;
00243 
00244     string name() const;
00245     virtual void set_name(const string &n);
00246 
00247     Type type() const;
00248     void set_type(const Type &t);
00249     string type_name() const;
00250 
00251     virtual bool is_simple_type();
00252     virtual bool is_vector_type();
00253     virtual bool is_constructor_type();
00254 
00255     virtual bool synthesized_p();
00256     virtual void set_synthesized_p(bool state);
00257 
00258     virtual int element_count(bool leaves = false);
00259 
00260     virtual bool read_p();
00261     virtual void set_read_p(bool state);
00262 
00263     virtual bool send_p();
00264     virtual void set_send_p(bool state);
00265 
00266     virtual AttrTable &get_attr_table();
00267     virtual void set_attr_table(const AttrTable &at);
00268 
00269     virtual bool is_in_selection();
00270     virtual void set_in_selection(bool state);
00271 
00272     xdrproc_t xdr_coder();
00273 
00274     virtual void set_parent(BaseType *parent);
00275     virtual BaseType *get_parent();
00276 
00277     // I put this comment here because the version in BaseType.cc does not
00278     // include the exact_match or s variables since they are not used. Doxygen
00279     // was gaging on the comment.
00280 
00311     virtual BaseType *var(const string &name = "", bool exact_match = true,
00312                           btp_stack *s = 0);
00313     virtual BaseType *var(const string &name, btp_stack &s);
00314 
00315     virtual void add_var(BaseType *bt, Part part = nil);
00316 
00317     virtual bool read(const string &dataset);
00318 
00319     virtual bool check_semantics(string &msg, bool all = false);
00320 
00321     virtual bool ops(BaseType *b, int op, const string &dataset);
00322 
00323     virtual void print_decl(FILE *out, string space = "    ",
00324                             bool print_semi = true,
00325                             bool constraint_info = false,
00326                             bool constrained = false);
00327 
00328     virtual void print_xml(FILE *out, string space = "    ",
00329                            bool constrained = false);
00330 
00333 
00345     virtual unsigned int width() = 0;
00346 
00365     virtual unsigned int buf2val(void **val) = 0;
00366 
00394     virtual unsigned int val2buf(void *val, bool reuse = false) = 0;
00395 
00426     virtual bool serialize(const string &dataset, ConstraintEvaluator &eval,
00427                            DDS &dds, XDR *sink, bool ce_eval = true) = 0;
00428 
00455     virtual bool deserialize(XDR *source, DDS *dds, bool reuse = false) = 0;
00456 
00471     virtual void print_val(FILE *out, string space = "",
00472                            bool print_decl_p = true) = 0;
00474 };
00475 
00476 #endif // _basetype_h

Generated on Wed Jun 27 12:56:38 2007 for libdap++ by  doxygen 1.4.7