libdap++  Updated for version 3.8.2
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 using std::cout;
70 
71 #define FILE_METHODS 1
72 
73 namespace libdap
74 {
75 
178 class DDS : public DapObj
179 {
180 private:
181  BaseTypeFactory *d_factory;
182 
183  string name; // The dataset name
184  string d_filename; // File name (or other OS identifier) for
185  string d_container_name; // name of container structure
186  Structure *d_container; // current container for container name
187  // dataset or part of dataset.
188 
189  int d_dap_major; // The protocol major version number
190  int d_dap_minor; // ... and minor version number
191  string d_dap_version; // String version of the protocol
192  string d_request_xml_base;
193 
194  AttrTable d_attr; // Global attributes.
195 
196  vector<BaseType *> vars; // Variables at the top level
197 
198  BaseType *find_hdf4_dimension_attribute_home(AttrTable::entry *source);
199 
200  int d_timeout; // alarm time in seconds. If greater than
201  // zero, raise the alarm signal if more than
202  // d_timeout seconds are spent reading data.
203  Keywords d_keywords; // Holds keywords parsed from the CE
204 
205  friend class DDSTest;
206 
207 protected:
208  void duplicate(const DDS &dds);
209  BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
210  BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
211 
212 public:
213  typedef std::vector<BaseType *>::const_iterator Vars_citer ;
214  typedef std::vector<BaseType *>::iterator Vars_iter ;
215  typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
216 
217  DDS(BaseTypeFactory *factory, const string &n = "");
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();
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 
262  void set_dap_major(int p);
264  void set_dap_minor(int p);
265 
266  void set_dap_version(const string &version_string);
267  void set_dap_version(double d);
268 
269  string get_dap_version() const { return d_dap_version; }
270 
271  Keywords &get_keywords() { return d_keywords; }
272 
274  string get_request_xml_base() const { return d_request_xml_base; }
275 
277  void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
278 
279  string container_name() ;
280  void container_name( const string &cn ) ;
281  Structure *container() ;
282 
283  void add_var(BaseType *bt);
284 
286  void del_var(const string &n);
287 
288  BaseType *var(const string &n, BaseType::btp_stack &s);
289  BaseType *var(const string &n, BaseType::btp_stack *s = 0);
290  int num_var();
291 
297  Vars_iter var_end();
301  Vars_iter get_vars_iter(int i);
303  BaseType *get_var_index(int i);
305  void del_var(Vars_iter i);
307  void del_var(Vars_iter i1, Vars_iter i2);
308 
309  void timeout_on();
310  void timeout_off();
311  void set_timeout(int t);
312  int get_timeout();
313 
314  void parse(string fname);
315  void parse(int fd);
316  void parse(FILE *in = stdin);
317 #if FILE_METHODS
318  void print(FILE *out);
319  void print_constrained(FILE *out);
320  void print_xml(FILE *out, bool constrained, const string &blob = "");
321 #endif
322  void print(ostream &out);
323  void print_constrained(ostream &out);
324  void print_xml(ostream &out, bool constrained, const string &blob = "");
325 
326  void mark_all(bool state);
327  bool mark(const string &name, bool state);
328  bool check_semantics(bool all = false);
329 
330  void tag_nested_sequences();
331 
332  virtual void dump(ostream &strm) const ;
333 };
334 
335 } // namespace libdap
336 
337 #endif // _dds_h
void print(FILE *out)
Print the entire DDS to the specified file.
Definition: DDS.cc:800
DDS(BaseTypeFactory *factory, const string &n="")
Definition: DDS.cc:145
Contains the attributes for a dataset.
Definition: AttrTable.h:146
Vars_iter get_vars_iter(int i)
Get an iterator.
Definition: DDS.cc:657
BaseType * leaf_match(const string &name, BaseType::btp_stack *s=0)
Definition: DDS.cc:561
Vars_iter var_begin()
Return an iterator to the first variable.
Definition: DDS.cc:630
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
Definition: DDS.h:274
void set_timeout(int t)
Definition: DDS.cc:695
BaseType * var(const string &n, BaseType::btp_stack &s)
Definition: DDS.cc:523
virtual void transfer_attributes(DAS *das)
Definition: DDS.cc:199
void print_xml(FILE *out, bool constrained, const string &blob="")
Definition: DDS.cc:918
friend class DDSTest
Definition: DDS.h:205
std::vector< BaseType * >::const_iterator Vars_citer
Definition: DDS.h:213
void timeout_off()
Definition: DDS.cc:687
Holds a structure (aggregate) type.
Definition: Structure.h:100
Vars_riter var_rend()
Return a reverse iterator.
Definition: DDS.cc:648
int num_var()
Returns the number of variables in the DDS.
Definition: DDS.cc:673
std::vector< BaseType * >::reverse_iterator Vars_riter
Definition: DDS.h:215
stack< BaseType * > btp_stack
Definition: BaseType.h:214
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
Definition: DDS.cc:1118
void parse(string fname)
Parse a DDS from a file with the given name.
Definition: DDS.cc:722
DDS & operator=(const DDS &rhs)
Definition: DDS.cc:173
virtual ~DDS()
Definition: DDS.cc:163
string get_dap_version() const
Definition: DDS.h:269
int get_dap_major() const
Get the DAP major version as sent by the client.
Definition: DDS.h:257
void mark_all(bool state)
Definition: DDS.cc:1162
Keywords & get_keywords()
Definition: DDS.h:271
std::vector< BaseType * >::iterator Vars_iter
Definition: DDS.h:214
virtual AttrTable & get_attr_table()
Definition: DDS.cc:266
BaseType * get_var_index(int i)
Get a variable.
Definition: DDS.cc:666
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
Definition: DDS.cc:1072
void set_dap_version(const string &version_string)
Definition: DDS.cc:329
Structure * container()
Definition: DDS.cc:423
string container_name()
Definition: DDS.cc:387
void timeout_on()
Definition: DDS.cc:679
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
Definition: DDS.h:244
Vars_iter var_end()
Return an iterator.
Definition: DDS.cc:642
BaseType * exact_match(const string &name, BaseType::btp_stack *s=0)
Definition: DDS.cc:597
BaseTypeFactory * get_factory() const
Definition: DDS.h:233
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
Definition: DDS.cc:710
void set_dap_minor(int p)
Set the DAP minor version (typically using info from the client)
Definition: DDS.cc:311
void set_dataset_name(const string &n)
Definition: DDS.cc:257
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
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:467
Vars_riter var_rbegin()
Return a reverse iterator.
Definition: DDS.cc:636
Hold attribute data for a DAP2 dataset.
Definition: DAS.h:123
int get_dap_minor() const
Get the DAP minor version as sent by the client.
Definition: DDS.h:259
string get_dataset_name() const
Definition: DDS.cc:250
void duplicate(const DDS &dds)
Definition: DDS.cc:111
void set_dap_major(int p)
Set the DAP major version (typically using info from the client)
Definition: DDS.cc:295
string filename()
Definition: DDS.cc:281
int get_timeout()
Definition: DDS.cc:702
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Definition: DDS.cc:848
virtual void dump(ostream &strm) const
dumps information about this object
Definition: DDS.cc:1176
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:436
void set_request_xml_base(const string &xb)
Definition: DDS.h:277