libdap  Updated for version 3.20.10
libdap4 is an implementation of OPeNDAP's DAP protocol.
DDS.h
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 XMLWRITER_H_
66 #include "XMLWriter.h"
67 #endif
68 
69 namespace libdap
70 {
71 
72 bool has_dap2_attributes(BaseType *btp);
73 bool has_dap2_attributes(AttrTable &a);
74 
177 class DDS : public DapObj
178 {
179 private:
180  BaseTypeFactory *d_factory;
181 
182  string d_name; // The dataset d_name
183  string d_filename; // File d_name (or other OS identifier) for
184  string d_container_name; // d_name of container structure
185  Structure *d_container; // current container for container d_name
186  // dataset or part of dataset.
187 
188  int d_dap_major; // The protocol major version number
189  int d_dap_minor; // ... and minor version number
190  string d_dap_version; // String version of the protocol
191  string d_request_xml_base;
192  string d_namespace;
193 
194  AttrTable d_attr; // Global attributes.
195 
196  vector<BaseType *> vars; // Variables at the top level
197 
198  int d_timeout; // alarm time in seconds. If greater than
199  // zero, raise the alarm signal if more than
200  // d_timeout seconds are spent reading data.
201 
202  uint64_t d_max_response_size_kb; // In kilobytes...
203 
204  friend class DDSTest;
205 
206 protected:
207  void duplicate(const DDS &dds);
208  BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
209  BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
210 
211 public:
212  typedef std::vector<BaseType *>::const_iterator Vars_citer ;
213  typedef std::vector<BaseType *>::iterator Vars_iter ;
214  typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
215 
216  DDS(BaseTypeFactory *factory, const string &name = "");
217  DDS(BaseTypeFactory *factory, const string &name, const string &version);
218  DDS(const DDS &dds);
219 
220  virtual ~DDS();
221 
222  DDS & operator=(const DDS &rhs);
223 
224  virtual void transfer_attributes(DAS *das);
225 
226  string get_dataset_name() const;
227  void set_dataset_name(const string &n);
228 
234  {
235  return d_factory;
236  }
237 
245  {
246  BaseTypeFactory *t = d_factory;
247  d_factory = factory;
248  return t;
249  }
250 
251  virtual AttrTable &get_attr_table();
252 
253  string filename() const;
254  void filename(const string &fn);
255 
257  int get_dap_major() const { return d_dap_major; }
259  int get_dap_minor() const { return d_dap_minor; }
260 
261  void set_dap_version(const string &version_string = "2.0");
262  string get_dap_version() const { return d_dap_version; }
263  string get_dmr_version() const { return "1.0"; }
264 
266  void set_dap_major(int p);
268  void set_dap_minor(int p);
270  void set_dap_version(double d);
271 
273  string get_request_xml_base() const { return d_request_xml_base; }
274 
276  void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
277 
279  string get_namespace() const { return d_namespace; }
280 
282  void set_namespace(const string &ns) { d_namespace = ns; }
283 
285  long get_response_limit() { return (long)(d_max_response_size_kb * 1024); }
286 
291  uint64_t get_response_limit_kb() const { return d_max_response_size_kb; }
292 
298  void set_response_limit(long size) { d_max_response_size_kb = size; }
299 
305  void set_response_limit_kb(uint64_t size) { d_max_response_size_kb = size; }
306 
310  bool too_big() {
311  return d_max_response_size_kb != 0 && get_request_size_kb(true) > d_max_response_size_kb;
312  }
313 
315  int get_request_size(bool constrained);
316 
318  uint64_t get_request_size_kb(bool constrained);
319 
320  string container_name() ;
321  void container_name( const string &cn ) ;
322  Structure *container() ;
323 
324  void add_var(BaseType *bt);
325  void add_var_nocopy(BaseType *bt);
326 
328  void del_var(const string &n);
329 
330  BaseType *var(const string &n, BaseType::btp_stack &s);
331  BaseType *var(const string &n, BaseType::btp_stack *s = 0);
332  int num_var();
333 
339  const vector<BaseType*> &variables() const { return vars; }
340 
344  Vars_iter var_begin() { return vars.begin(); }
346  Vars_riter var_rbegin() { return vars.rbegin(); }
347 
349  Vars_iter var_end() { return vars.end() ; }
351  Vars_riter var_rend() { return vars.rend() ; }
352 
354  Vars_iter get_vars_iter(int i) { return vars.begin() + i; }
356  BaseType *get_var_index(int i) { return *(vars.begin() + i); }
357 
359  void insert_var(Vars_iter i, BaseType *ptr);
360  void insert_var_nocopy(Vars_iter i, BaseType *ptr);
362  void del_var(Vars_iter i);
364  void del_var(Vars_iter i1, Vars_iter i2);
365 
371  void timeout_on();
372  void timeout_off();
373  void set_timeout(int t);
374  int get_timeout();
376 
377  // These parse the DAP2 curly-brace document and make a C++ object.
378  void parse(string fname);
379  void parse(int fd);
380  void parse(FILE *in = stdin);
381 
382  // These print the Binary object in either the curly-brace or XML reps
383  void print(FILE *out);
384  void print_constrained(FILE *out);
385  void print_xml(FILE *out, bool constrained, const string &blob = "");
386 
387  // Same as above, but using C++ i/o streams
388  void print(ostream &out);
389  void print_constrained(ostream &out);
390  void print_xml(ostream &out, bool constrained, const string &blob = "");
391 
392  // Print the XML using libxml2; the other print_xml methods use this impl.
393  void print_xml_writer(ostream &out, bool constrained, const string &blob = "");
394 
395  // Print the DAP4 DMR 'object'
396  void print_dmr(ostream &out, bool constrained);
397 
398  void print_das(ostream &out);
399  DAS *get_das();
400  void get_das(DAS *das);
401 
402  void mark_all(bool state);
403  bool mark(const string &name, bool state);
404  bool check_semantics(bool all = false);
405 
406  void tag_nested_sequences();
407 
408  virtual void dump(ostream &strm) const ;
409 };
410 
411 } // namespace libdap
412 
413 #endif // _dds_h
Contains the attributes for a dataset.
Definition: AttrTable.h:143
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
Hold attribute data for a DAP2 dataset.
Definition: DAS.h:122
void set_dataset_name(const string &n)
Definition: DDS.cc:292
void set_dap_major(int p)
Definition: DDS.cc:333
void mark_all(bool state)
Definition: DDS.cc:1533
void print_dmr(ostream &out, bool constrained)
Print the DAP4 DMR object using a DDS.
Definition: DDS.cc:1376
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
Definition: DDS.cc:567
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
Definition: DDS.cc:1447
void set_namespace(const string &ns)
Set the namespace for this DDS/DDX object/response.
Definition: DDS.h:282
string filename() const
Definition: DDS.cc:316
virtual AttrTable & get_attr_table()
Definition: DDS.cc:301
void set_request_xml_base(const string &xb)
Definition: DDS.h:276
void set_response_limit(long size)
Definition: DDS.h:298
uint64_t get_request_size_kb(bool constrained)
Get the estimated response size in kilobytes.
Definition: DDS.cc:522
virtual void transfer_attributes(DAS *das)
Definition: DDS.cc:246
BaseTypeFactory * get_factory() const
Definition: DDS.h:233
void set_dap_minor(int p)
Definition: DDS.cc:352
string get_namespace() const
Get the namespace associated with the DDS - likely set only by DDX responses.
Definition: DDS.h:279
int num_var()
Returns the number of variables in the DDS.
Definition: DDS.cc:774
void print(FILE *out)
Print the entire DDS to the specified file.
Definition: DDS.cc:924
BaseType * get_var_index(int i)
Get a variable.
Definition: DDS.h:356
int get_request_size(bool constrained)
Get the estimated response size in bytes.
Definition: DDS.cc:495
Vars_riter var_rbegin()
Return a reverse iterator.
Definition: DDS.h:346
string get_dataset_name() const
Definition: DDS.cc:285
bool too_big()
Definition: DDS.h:310
void del_var(const string &n)
Removes a variable from the DDS.
Definition: DDS.cc:589
void parse(string fname)
Parse a DDS from a file with the given d_name.
Definition: DDS.cc:843
BaseType * var(const string &n, BaseType::btp_stack &s)
Definition: DDS.cc:645
void print_xml(FILE *out, bool constrained, const string &blob="")
Definition: DDS.cc:1249
void insert_var(Vars_iter i, BaseType *ptr)
Insert a variable before the referenced element.
Definition: DDS.cc:754
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
Definition: DDS.cc:1491
int get_dap_minor() const
Get the DAP minor version as sent by the client.
Definition: DDS.h:259
uint64_t get_response_limit_kb() const
The maximum allowed response size, in kilobytes. Zero indicates no limit (default).
Definition: DDS.h:291
DDS(BaseTypeFactory *factory, const string &name="")
Definition: DDS.cc:168
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
Definition: DDS.cc:831
DAS * get_das()
Get a DAS object.
Definition: DDS.cc:1082
Vars_iter var_begin()
Definition: DDS.h:344
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Definition: DDS.cc:1203
string container_name()
Definition: DDS.cc:440
Vars_riter var_rend()
Return a reverse iterator.
Definition: DDS.h:351
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
Definition: DDS.h:244
void insert_var_nocopy(Vars_iter i, BaseType *ptr)
Definition: DDS.cc:767
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
Definition: DDS.h:273
void set_response_limit_kb(uint64_t size)
Set the maximum response size, in kilobytes. The size is given in kilobytes..
Definition: DDS.h:305
Vars_iter var_end()
Return an iterator.
Definition: DDS.h:349
int get_dap_major() const
Get the DAP major version as sent by the client.
Definition: DDS.h:257
const vector< BaseType * > & variables() const
Definition: DDS.h:339
void set_dap_version(const string &version_string="2.0")
Definition: DDS.cc:369
Structure * container()
Definition: DDS.cc:476
void add_var(BaseType *bt)
Adds a copy of the variable to the DDS. Using the ptr_duplicate() method, perform a deep copy on the ...
Definition: DDS.cc:543
Vars_iter get_vars_iter(int i)
Get an iterator.
Definition: DDS.h:354
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
Definition: DDS.cc:1304
long get_response_limit()
Get the maximum response size, in bytes. Zero indicates no limit.
Definition: DDS.h:285
void print_das(ostream &out)
write the DAS response given the attribute information in the DDS
Definition: DDS.cc:1065
virtual void dump(ostream &strm) const
dumps information about this object
Definition: DDS.cc:1547
libdap base object for common functionality of libdap objects
Definition: DapObj.h:51
Holds a structure (aggregate) type.
Definition: Structure.h:84
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
bool has_dap2_attributes(AttrTable &a)
Definition: DDS.cc:954