libdap
Updated for version 3.17.0
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #ifndef KEYWORDS_H_ 00066 #include "Keywords2.h" 00067 #endif 00068 00069 #ifndef XMLWRITER_H_ 00070 #include "XMLWriter.h" 00071 #endif 00072 00073 using std::cout; 00074 00075 namespace libdap 00076 { 00077 00180 class DDS : public DapObj 00181 { 00182 private: 00183 BaseTypeFactory *d_factory; 00184 00185 string d_name; // The dataset d_name 00186 string d_filename; // File d_name (or other OS identifier) for 00187 string d_container_name; // d_name of container structure 00188 Structure *d_container; // current container for container d_name 00189 // dataset or part of dataset. 00190 00191 int d_dap_major; // The protocol major version number 00192 int d_dap_minor; // ... and minor version number 00193 string d_dap_version; // String version of the protocol 00194 string d_request_xml_base; 00195 string d_namespace; 00196 00197 AttrTable d_attr; // Global attributes. 00198 00199 vector<BaseType *> vars; // Variables at the top level 00200 00201 int d_timeout; // alarm time in seconds. If greater than 00202 // zero, raise the alarm signal if more than 00203 // d_timeout seconds are spent reading data. 00204 Keywords d_keywords; // Holds keywords parsed from the CE 00205 00206 long d_max_response_size; // In bytes... 00207 00208 friend class DDSTest; 00209 00210 protected: 00211 void duplicate(const DDS &dds); 00212 BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0); 00213 BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0); 00214 00215 public: 00216 typedef std::vector<BaseType *>::const_iterator Vars_citer ; 00217 typedef std::vector<BaseType *>::iterator Vars_iter ; 00218 typedef std::vector<BaseType *>::reverse_iterator Vars_riter ; 00219 00220 DDS(BaseTypeFactory *factory, const string &name = ""); 00221 DDS(BaseTypeFactory *factory, const string &name, const string &version); 00222 DDS(const DDS &dds); 00223 00224 virtual ~DDS(); 00225 00226 DDS & operator=(const DDS &rhs); 00227 00228 virtual void transfer_attributes(DAS *das); 00229 00230 string get_dataset_name() const; 00231 void set_dataset_name(const string &n); 00232 00237 BaseTypeFactory *get_factory() const 00238 { 00239 return d_factory; 00240 } 00241 00248 BaseTypeFactory *set_factory(BaseTypeFactory *factory) 00249 { 00250 BaseTypeFactory *t = d_factory; 00251 d_factory = factory; 00252 return t; 00253 } 00254 00255 virtual AttrTable &get_attr_table(); 00256 00257 string filename() const; 00258 void filename(const string &fn); 00259 00261 int get_dap_major() const { return d_dap_major; } 00263 int get_dap_minor() const { return d_dap_minor; } 00264 00265 void set_dap_version(const string &version_string = "2.0"); 00266 string get_dap_version() const { return d_dap_version; } 00267 string get_dmr_version() const { return "1.0"; } 00268 00270 void set_dap_major(int p); 00272 void set_dap_minor(int p); 00274 void set_dap_version(double d); 00275 00276 Keywords &get_keywords() { return d_keywords; } 00277 00279 string get_request_xml_base() const { return d_request_xml_base; } 00280 00282 void set_request_xml_base(const string &xb) { d_request_xml_base = xb; } 00283 00285 string get_namespace() const { return d_namespace; } 00286 00288 void set_namespace(const string &ns) { d_namespace = ns; } 00289 00291 long get_response_limit() { return d_max_response_size; } 00292 00296 void set_response_limit(long size) { d_max_response_size = size * 1024; } 00297 00299 int get_request_size(bool constrained); 00300 00301 string container_name() ; 00302 void container_name( const string &cn ) ; 00303 Structure *container() ; 00304 00305 void add_var(BaseType *bt); 00306 void add_var_nocopy(BaseType *bt); 00307 00309 void del_var(const string &n); 00310 00311 BaseType *var(const string &n, BaseType::btp_stack &s); 00312 BaseType *var(const string &n, BaseType::btp_stack *s = 0); 00313 int num_var(); 00314 00316 Vars_iter var_begin(); 00317 #if 0 00318 00319 Vars_citer var_cbegin() const { return vars.cbegin(); } 00320 #endif 00321 00322 Vars_riter var_rbegin(); 00324 Vars_iter var_end(); 00325 #if 0 00326 00327 Vars_citer var_cend() const { return vars.cend(); } 00328 #endif 00329 00330 Vars_riter var_rend(); 00332 Vars_iter get_vars_iter(int i); 00334 BaseType *get_var_index(int i); 00336 void insert_var(Vars_iter i, BaseType *ptr); 00337 void insert_var_nocopy(Vars_iter i, BaseType *ptr); 00339 void del_var(Vars_iter i); 00341 void del_var(Vars_iter i1, Vars_iter i2); 00342 00347 00348 void timeout_on(); 00349 void timeout_off(); 00350 void set_timeout(int t); 00351 int get_timeout(); 00353 00354 // These parse the DAP2 curly-brace document and make a C++ object. 00355 void parse(string fname); 00356 void parse(int fd); 00357 void parse(FILE *in = stdin); 00358 00359 // These print the Binary object in either the curly-brace or XML reps 00360 void print(FILE *out); 00361 void print_constrained(FILE *out); 00362 void print_xml(FILE *out, bool constrained, const string &blob = ""); 00363 00364 // Same as above, but using C++ i/o streams 00365 void print(ostream &out); 00366 void print_constrained(ostream &out); 00367 void print_xml(ostream &out, bool constrained, const string &blob = ""); 00368 00369 // Print the XML using libxml2; the other print_xml methods use this impl. 00370 void print_xml_writer(ostream &out, bool constrained, const string &blob = ""); 00371 00372 // Print the DAP4 DMR 'object' 00373 void print_dmr(ostream &out, bool constrained); 00374 00375 void print_das(ostream &out); 00376 00377 void mark_all(bool state); 00378 bool mark(const string &name, bool state); 00379 bool check_semantics(bool all = false); 00380 00381 void tag_nested_sequences(); 00382 00383 virtual void dump(ostream &strm) const ; 00384 }; 00385 00386 } // namespace libdap 00387 00388 #endif // _dds_h