libdap++  Updated for version 3.11.7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #define FILE_METHODS 1
76 
77 namespace libdap
78 {
79 
182 class DDS : public DapObj
183 {
184 private:
185  BaseTypeFactory *d_factory;
186 
187  string name; // The dataset name
188  string d_filename; // File name (or other OS identifier) for
189  string d_container_name; // name of container structure
190  Structure *d_container; // current container for container name
191  // dataset or part of dataset.
192 
193  int d_dap_major; // The protocol major version number
194  int d_dap_minor; // ... and minor version number
195  string d_dap_version; // String version of the protocol
196  string d_request_xml_base;
197 
198  AttrTable d_attr; // Global attributes.
199 
200  vector<BaseType *> vars; // Variables at the top level
201 
202  // BaseType *find_hdf4_dimension_attribute_home(AttrTable::entry *source);
203 
204  int d_timeout; // alarm time in seconds. If greater than
205  // zero, raise the alarm signal if more than
206  // d_timeout seconds are spent reading data.
207  Keywords d_keywords; // Holds keywords parsed from the CE
208 
209  long d_max_response_size; // In bytes
210 
211  friend class DDSTest;
212 
213 protected:
214  void duplicate(const DDS &dds);
215  BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
216  BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
217 
218 public:
219  typedef std::vector<BaseType *>::const_iterator Vars_citer ;
220  typedef std::vector<BaseType *>::iterator Vars_iter ;
221  typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
222 
223  DDS(BaseTypeFactory *factory, const string &n = "");
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 
268  void set_dap_major(int p);
270  void set_dap_minor(int p);
271 
272  void set_dap_version(const string &version_string);
273  void set_dap_version(double d);
274 
275  string get_dap_version() const { return d_dap_version; }
276 
277  Keywords &get_keywords() { return d_keywords; }
278 
280  string get_request_xml_base() const { return d_request_xml_base; }
281 
283  void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
284 
286  long get_response_limit() { return d_max_response_size; }
287 
291  void set_response_limit(long size) { d_max_response_size = size * 1024; }
292 
294  int get_request_size(bool constrained);
295 
296  string container_name() ;
297  void container_name( const string &cn ) ;
298  Structure *container() ;
299 
300  void add_var(BaseType *bt);
301  void add_var_nocopy(BaseType *bt);
302 
304  void del_var(const string &n);
305 
306  BaseType *var(const string &n, BaseType::btp_stack &s);
307  BaseType *var(const string &n, BaseType::btp_stack *s = 0);
308  int num_var();
309 
315  Vars_iter var_end();
319  Vars_iter get_vars_iter(int i);
321  BaseType *get_var_index(int i);
323  void insert_var(Vars_iter i, BaseType *ptr);
324  void insert_var_nocopy(Vars_iter i, BaseType *ptr);
326  void del_var(Vars_iter i);
328  void del_var(Vars_iter i1, Vars_iter i2);
329 
330  void timeout_on();
331  void timeout_off();
332  void set_timeout(int t);
333  int get_timeout();
334 
335  void parse(string fname);
336  void parse(int fd);
337  void parse(FILE *in = stdin);
338 #if FILE_METHODS
339  void print(FILE *out);
340  void print_constrained(FILE *out);
341  void print_xml(FILE *out, bool constrained, const string &blob = "");
342 #endif
343  void print(ostream &out);
344  void print_constrained(ostream &out);
345  void print_xml(ostream &out, bool constrained, const string &blob = "");
346 
347  void print_xml_writer(ostream &out, bool constrained, const string &blob = "");
348 
349  void print_das(ostream &out);
350 
351  void mark_all(bool state);
352  bool mark(const string &name, bool state);
353  bool check_semantics(bool all = false);
354 
355  void tag_nested_sequences();
356 
357  virtual void dump(ostream &strm) const ;
358 };
359 
360 } // namespace libdap
361 
362 #endif // _dds_h
void print(FILE *out)
Print the entire DDS to the specified file.
Definition: DDS.cc:871
DDS(BaseTypeFactory *factory, const string &n="")
Definition: DDS.cc:148
void insert_var_nocopy(Vars_iter i, BaseType *ptr)
Definition: DDS.cc:737
Contains the attributes for a dataset.
Definition: AttrTable.h:150
Vars_iter get_vars_iter(int i)
Get an iterator.
Definition: DDS.cc:705
void set_response_limit(long size)
Definition: DDS.h:291
BaseType * leaf_match(const string &name, BaseType::btp_stack *s=0)
Definition: DDS.cc:609
void insert_var(Vars_iter i, BaseType *ptr)
Insert a variable before the referenced element.
Definition: DDS.cc:724
Vars_iter var_begin()
Return an iterator to the first variable.
Definition: DDS.cc:678
long get_response_limit()
Get the maximum response size, in KB. Zero indicates no limit.
Definition: DDS.h:286
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
Definition: DDS.h:280
void set_timeout(int t)
Definition: DDS.cc:766
int get_request_size(bool constrained)
Get the estimated response size.
Definition: DDS.cc:449
BaseType * var(const string &n, BaseType::btp_stack &s)
Definition: DDS.cc:571
virtual void transfer_attributes(DAS *das)
Definition: DDS.cc:201
void print_xml(FILE *out, bool constrained, const string &blob="")
Definition: DDS.cc:1012
friend class DDSTest
Definition: DDS.h:211
std::vector< BaseType * >::const_iterator Vars_citer
Definition: DDS.h:219
void timeout_off()
Definition: DDS.cc:758
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
Definition: DDS.cc:1179
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
Definition: DDS.cc:493
Holds a structure (aggregate) type.
Definition: Structure.h:100
Vars_riter var_rend()
Return a reverse iterator.
Definition: DDS.cc:696
int num_var()
Returns the number of variables in the DDS.
Definition: DDS.cc:744
std::vector< BaseType * >::reverse_iterator Vars_riter
Definition: DDS.h:221
stack< BaseType * > btp_stack
Definition: BaseType.h:218
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
Definition: DDS.cc:1325
void parse(string fname)
Parse a DDS from a file with the given name.
Definition: DDS.cc:793
DDS & operator=(const DDS &rhs)
Definition: DDS.cc:176
virtual ~DDS()
Definition: DDS.cc:166
string get_dap_version() const
Definition: DDS.h:275
int get_dap_major() const
Get the DAP major version as sent by the client.
Definition: DDS.h:263
void mark_all(bool state)
Definition: DDS.cc:1371
Keywords & get_keywords()
Definition: DDS.h:277
std::vector< BaseType * >::iterator Vars_iter
Definition: DDS.h:220
void print_das(ostream &out)
Definition: DDS.cc:917
virtual AttrTable & get_attr_table()
Definition: DDS.cc:274
BaseType * get_var_index(int i)
Get a variable.
Definition: DDS.cc:714
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
Definition: DDS.cc:1279
void set_dap_version(const string &version_string)
Definition: DDS.cc:337
Structure * container()
Definition: DDS.cc:431
string container_name()
Definition: DDS.cc:395
void timeout_on()
Definition: DDS.cc:750
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
Definition: DDS.h:250
Vars_iter var_end()
Return an iterator.
Definition: DDS.cc:690
BaseType * exact_match(const string &name, BaseType::btp_stack *s=0)
Definition: DDS.cc:645
BaseTypeFactory * get_factory() const
Definition: DDS.h:239
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
Definition: DDS.cc:781
void set_dap_minor(int p)
Set the DAP minor version (typically using info from the client)
Definition: DDS.cc:319
void set_dataset_name(const string &n)
Definition: DDS.cc:265
The basic data type for the DODS DAP types.
Definition: BaseType.h:194
libdap base object for common functionality of libdap objects
Definition: DapObj.h:55
void del_var(const string &n)
Removes a variable from the DDS.
Definition: DDS.cc:515
Vars_riter var_rbegin()
Return a reverse iterator.
Definition: DDS.cc:684
Hold attribute data for a DAP2 dataset.
Definition: DAS.h:121
int get_dap_minor() const
Get the DAP minor version as sent by the client.
Definition: DDS.h:265
string get_dataset_name() const
Definition: DDS.cc:258
void duplicate(const DDS &dds)
Definition: DDS.cc:114
void set_dap_major(int p)
Set the DAP major version (typically using info from the client)
Definition: DDS.cc:303
string filename()
Definition: DDS.cc:289
int get_timeout()
Definition: DDS.cc:773
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Definition: DDS.cc:941
virtual void dump(ostream &strm) const
dumps information about this object
Definition: DDS.cc:1385
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:470
void set_request_xml_base(const string &xb)
Definition: DDS.h:283