libdap++ Updated for version 3.8.2

DDS.h

Go to the documentation of this file.
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) 2002,2003 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 // (c) COPYRIGHT URI/MIT 1994-1999
00026 // Please read the full copyright statement in the file COPYRIGHT_URI.
00027 //
00028 // Authors:
00029 //      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
00030 
00031 // Provide access to the DDS. This class is used to parse DDS text files, to
00032 // produce a printed representation of the in-memory variable table, and to
00033 // update the table on a per-variable basis.
00034 //
00035 // jhrg 9/8/94
00036 
00037 #ifndef _dds_h
00038 #define _dds_h 1
00039 
00040 #include <cstdio>
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 
00045 #ifndef _basetype_h
00046 #include "BaseType.h"
00047 #endif
00048 
00049 #ifndef _constructor_h
00050 #include "Constructor.h"
00051 #endif
00052 
00053 #ifndef base_type_factory_h
00054 #include "BaseTypeFactory.h"
00055 #endif
00056 
00057 #ifndef _das_h
00058 #include "DAS.h"
00059 #endif
00060 
00061 #ifndef A_DapObj_h
00062 #include "DapObj.h"
00063 #endif
00064 
00065 using std::cout;
00066 
00067 #define FILE_METHODS 1
00068 
00069 namespace libdap
00070 {
00071 
00174 class DDS : public DapObj
00175 {
00176 private:
00177     BaseTypeFactory *d_factory;
00178 
00179     string name;                // The dataset name
00180     string d_filename;          // File name (or other OS identifier) for
00181     string d_container_name;    // name of container structure
00182     Structure *d_container;     // current container for container name
00183                                 // dataset or part of dataset.
00184 
00185     int d_dap_major;       // The protocol major version number
00186     int d_dap_minor;       // ... and minor version number
00187 
00188     string d_request_xml_base;
00189 
00190     AttrTable d_attr;           // Global attributes.
00191 
00192     vector<BaseType *> vars;    // Variables at the top level
00193 
00194     BaseType *find_hdf4_dimension_attribute_home(AttrTable::entry *source);
00195 
00196     int d_timeout;              // alarm time in seconds. If greater than
00197                                 // zero, raise the alarm signal if more than
00198                                 // d_timeout seconds are spent reading data.
00199     friend class DDSTest;
00200 
00201 protected:
00202     void duplicate(const DDS &dds);
00203     BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
00204     BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
00205 #if 0
00206     virtual AttrTable *find_matching_container(AttrTable::entry *source,
00207             BaseType **dest_variable);
00208 #endif
00209 public:
00210     typedef std::vector<BaseType *>::const_iterator Vars_citer ;
00211     typedef std::vector<BaseType *>::iterator Vars_iter ;
00212     typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
00213 
00214     DDS(BaseTypeFactory *factory, const string &n = "");
00215     DDS(const DDS &dds);
00216 
00217     virtual ~DDS();
00218 
00219     DDS & operator=(const DDS &rhs);
00220 
00221     virtual void transfer_attributes(DAS *das);
00222 
00223     string get_dataset_name() const;
00224     void set_dataset_name(const string &n);
00225 
00230     BaseTypeFactory *get_factory() const
00231     {
00232         return d_factory;
00233     }
00234 
00241     BaseTypeFactory *set_factory(BaseTypeFactory *factory)
00242     {
00243         BaseTypeFactory *t = d_factory;
00244         d_factory = factory;
00245         return t;
00246     }
00247 
00248     virtual AttrTable &get_attr_table();
00249 
00250     string filename();
00251     void filename(const string &fn);
00252 
00254     int get_dap_major() const { return d_dap_major; }
00256     int get_dap_minor() const { return d_dap_minor; }
00257 
00259     void set_dap_major(int p) { d_dap_major = p; }
00261     void set_dap_minor(int p) { d_dap_minor = p; }
00262 
00263     void set_dap_version(const string &version_string);
00264 
00266     string get_request_xml_base() const { return d_request_xml_base; }
00267 
00269     void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
00270 
00271     string container_name() ;
00272     void container_name( const string &cn ) ;
00273     Structure *container() ;
00274 
00275     void add_var(BaseType *bt);
00276 
00278     void del_var(const string &n);
00279 
00280     BaseType *var(const string &n, BaseType::btp_stack &s);
00281     BaseType *var(const string &n, BaseType::btp_stack *s = 0);
00282     int num_var();
00283 
00285     Vars_iter var_begin();
00287     Vars_riter var_rbegin();
00289     Vars_iter var_end();
00291     Vars_riter var_rend();
00293     Vars_iter get_vars_iter(int i);
00295     BaseType *get_var_index(int i);
00297     void del_var(Vars_iter i);
00299     void del_var(Vars_iter i1, Vars_iter i2);
00300 
00301     void timeout_on();
00302     void timeout_off();
00303     void set_timeout(int t);
00304     int get_timeout();
00305 
00306     void parse(string fname);
00307     void parse(int fd);
00308     void parse(FILE *in = stdin);
00309 #if FILE_METHODS
00310     void print(FILE *out);
00311     void print_constrained(FILE *out);
00312     void print_xml(FILE *out, bool constrained, const string &blob = "");
00313 #endif
00314     void print(ostream &out);
00315     void print_constrained(ostream &out);
00316     void print_xml(ostream &out, bool constrained, const string &blob = "");
00317 
00318     void mark_all(bool state);
00319     bool mark(const string &name, bool state);
00320     bool check_semantics(bool all = false);
00321 
00322     void tag_nested_sequences();
00323 
00324     virtual void dump(ostream &strm) const ;
00325 };
00326 
00327 } // namespace libdap
00328 
00329 #endif // _dds_h