libdap++  Updated for version 3.12.0
DDS.h
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2002,2003 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 // (c) COPYRIGHT URI/MIT 1994-1999
26 // Please read the full copyright statement in the file COPYRIGHT_URI.
27 //
28 // Authors:
29 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
30 
31 // Provide access to the DDS. This class is used to parse DDS text files, to
32 // produce a printed representation of the in-memory variable table, and to
33 // update the table on a per-variable basis.
34 //
35 // jhrg 9/8/94
36 
37 #ifndef _dds_h
38 #define _dds_h 1
39 
40 #include <cstdio>
41 #include <iostream>
42 #include <string>
43 #include <vector>
44 
45 #ifndef _basetype_h
46 #include "BaseType.h"
47 #endif
48 
49 #ifndef _constructor_h
50 #include "Constructor.h"
51 #endif
52 
53 #ifndef base_type_factory_h
54 #include "BaseTypeFactory.h"
55 #endif
56 
57 #ifndef _das_h
58 #include "DAS.h"
59 #endif
60 
61 #ifndef A_DapObj_h
62 #include "DapObj.h"
63 #endif
64 
65 #ifndef KEYWORDS_H_
66 #include "Keywords2.h"
67 #endif
68 
69 #ifndef XMLWRITER_H_
70 #include "XMLWriter.h"
71 #endif
72 
73 using std::cout;
74 
75 namespace libdap
76 {
77 
180 class DDS : public DapObj
181 {
182 private:
183  BaseTypeFactory *d_factory;
184 
185  string d_name; // The dataset d_name
186  string d_filename; // File d_name (or other OS identifier) for
187  string d_container_name; // d_name of container structure
188  Structure *d_container; // current container for container d_name
189  // dataset or part of dataset.
190 
191  int d_dap_major; // The protocol major version number
192  int d_dap_minor; // ... and minor version number
193  string d_dap_version; // String version of the protocol
194  string d_request_xml_base;
195  string d_namespace;
196 
197  AttrTable d_attr; // Global attributes.
198 
199  vector<BaseType *> vars; // Variables at the top level
200 
201  int d_timeout; // alarm time in seconds. If greater than
202  // zero, raise the alarm signal if more than
203  // d_timeout seconds are spent reading data.
204  Keywords d_keywords; // Holds keywords parsed from the CE
205 
206  long d_max_response_size; // In bytes...
207 
208 
209 
210  friend class DDSTest;
211 
212 protected:
213  void duplicate(const DDS &dds);
214  BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
215  BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
216 
217 public:
218  typedef std::vector<BaseType *>::const_iterator Vars_citer ;
219  typedef std::vector<BaseType *>::iterator Vars_iter ;
220  typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
221 
222  DDS(BaseTypeFactory *factory, const string &name = "");
223  DDS(BaseTypeFactory *factory, const string &name, const string &version);
224  DDS(const DDS &dds);
225 
226  virtual ~DDS();
227 
228  DDS & operator=(const DDS &rhs);
229 
230  virtual void transfer_attributes(DAS *das);
231 
232  string get_dataset_name() const;
233  void set_dataset_name(const string &n);
234 
240  {
241  return d_factory;
242  }
243 
251  {
252  BaseTypeFactory *t = d_factory;
253  d_factory = factory;
254  return t;
255  }
256 
257  virtual AttrTable &get_attr_table();
258 
259  string filename();
260  void filename(const string &fn);
261 
263  int get_dap_major() const { return d_dap_major; }
265  int get_dap_minor() const { return d_dap_minor; }
266 
267  void set_dap_version(const string &version_string = "2.0");
268  string get_dap_version() const { return d_dap_version; }
269  string get_dmr_version() const { return "1.0"; }
270 
272  void set_dap_major(int p);
274  void set_dap_minor(int p);
276  void set_dap_version(double d);
277 
278  Keywords &get_keywords() { return d_keywords; }
279 
281  string get_request_xml_base() const { return d_request_xml_base; }
282 
284  void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
285 
287  string get_namespace() const { return d_namespace; }
288 
290  void set_namespace(const string &ns) { d_namespace = ns; }
291 
293  long get_response_limit() { return d_max_response_size; }
294 
298  void set_response_limit(long size) { d_max_response_size = size * 1024; }
299 
301  int get_request_size(bool constrained);
302 
303  string container_name() ;
304  void container_name( const string &cn ) ;
305  Structure *container() ;
306 
307  void add_var(BaseType *bt);
308  void add_var_nocopy(BaseType *bt);
309 
311  void del_var(const string &n);
312 
313  BaseType *var(const string &n, BaseType::btp_stack &s);
314  BaseType *var(const string &n, BaseType::btp_stack *s = 0);
315  int num_var();
316 
322  Vars_iter var_end();
326  Vars_iter get_vars_iter(int i);
328  BaseType *get_var_index(int i);
330  void insert_var(Vars_iter i, BaseType *ptr);
331  void insert_var_nocopy(Vars_iter i, BaseType *ptr);
333  void del_var(Vars_iter i);
335  void del_var(Vars_iter i1, Vars_iter i2);
336 
337  void timeout_on();
338  void timeout_off();
339  void set_timeout(int t);
340  int get_timeout();
341 
342  // These parse the DAP2 curly-brace document and make a C++ object.
343  void parse(string fname);
344  void parse(int fd);
345  void parse(FILE *in = stdin);
346 
347  // These print the Binary object in either the curly-brace or XML reps
348  void print(FILE *out);
349  void print_constrained(FILE *out);
350  void print_xml(FILE *out, bool constrained, const string &blob = "");
351 
352  // Same as above, but using C++ i/o streams
353  void print(ostream &out);
354  void print_constrained(ostream &out);
355  void print_xml(ostream &out, bool constrained, const string &blob = "");
356 
357  // Print the XML using libxml2; the other print_xml methods use this impl.
358  void print_xml_writer(ostream &out, bool constrained, const string &blob = "");
359 
360  // Print the DAP4 DMR 'object'
361  void print_dmr(ostream &out, bool constrained);
362 
363  void print_das(ostream &out);
364 
365  void mark_all(bool state);
366  bool mark(const string &name, bool state);
367  bool check_semantics(bool all = false);
368 
369  void tag_nested_sequences();
370 
371  virtual void dump(ostream &strm) const ;
372 };
373 
374 } // namespace libdap
375 
376 #endif // _dds_h