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 using std::cout;
66 
67 #define FILE_METHODS 1
68 
69 namespace libdap
70 {
71 
174 class DDS : public DapObj
175 {
176 private:
177  BaseTypeFactory *d_factory;
178 
179  string name; // The dataset name
180  string d_filename; // File name (or other OS identifier) for
181  string d_container_name; // name of container structure
182  Structure *d_container; // current container for container name
183  // dataset or part of dataset.
184 
185  int d_dap_major; // The protocol major version number
186  int d_dap_minor; // ... and minor version number
187 
188  string d_request_xml_base;
189 
190  AttrTable d_attr; // Global attributes.
191 
192  vector<BaseType *> vars; // Variables at the top level
193 
194  BaseType *find_hdf4_dimension_attribute_home(AttrTable::entry *source);
195 
196  int d_timeout; // alarm time in seconds. If greater than
197  // zero, raise the alarm signal if more than
198  // d_timeout seconds are spent reading data.
199  friend class DDSTest;
200 
201 protected:
202  void duplicate(const DDS &dds);
203  BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
204  BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
205 #if 0
206  virtual AttrTable *find_matching_container(AttrTable::entry *source,
207  BaseType **dest_variable);
208 #endif
209 public:
210  typedef std::vector<BaseType *>::const_iterator Vars_citer ;
211  typedef std::vector<BaseType *>::iterator Vars_iter ;
212  typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
213 
214  DDS(BaseTypeFactory *factory, const string &n = "");
215  DDS(const DDS &dds);
216 
217  virtual ~DDS();
218 
219  DDS & operator=(const DDS &rhs);
220 
221  virtual void transfer_attributes(DAS *das);
222 
223  string get_dataset_name() const;
224  void set_dataset_name(const string &n);
225 
231  {
232  return d_factory;
233  }
234 
242  {
243  BaseTypeFactory *t = d_factory;
244  d_factory = factory;
245  return t;
246  }
247 
248  virtual AttrTable &get_attr_table();
249 
250  string filename();
251  void filename(const string &fn);
252 
254  int get_dap_major() const { return d_dap_major; }
256  int get_dap_minor() const { return d_dap_minor; }
257 
259  void set_dap_major(int p) { d_dap_major = p; }
261  void set_dap_minor(int p) { d_dap_minor = p; }
262 
263  void set_dap_version(const string &version_string);
264 
266  string get_request_xml_base() const { return d_request_xml_base; }
267 
269  void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
270 
271  string container_name() ;
272  void container_name( const string &cn ) ;
273  Structure *container() ;
274 
275  void add_var(BaseType *bt);
276 
278  void del_var(const string &n);
279 
280  BaseType *var(const string &n, BaseType::btp_stack &s);
281  BaseType *var(const string &n, BaseType::btp_stack *s = 0);
282  int num_var();
283 
285  Vars_iter var_begin();
287  Vars_riter var_rbegin();
289  Vars_iter var_end();
291  Vars_riter var_rend();
293  Vars_iter get_vars_iter(int i);
295  BaseType *get_var_index(int i);
297  void del_var(Vars_iter i);
299  void del_var(Vars_iter i1, Vars_iter i2);
300 
301  void timeout_on();
302  void timeout_off();
303  void set_timeout(int t);
304  int get_timeout();
305 
306  void parse(string fname);
307  void parse(int fd);
308  void parse(FILE *in = stdin);
309 #if FILE_METHODS
310  void print(FILE *out);
311  void print_constrained(FILE *out);
312  void print_xml(FILE *out, bool constrained, const string &blob = "");
313 #endif
314  void print(ostream &out);
315  void print_constrained(ostream &out);
316  void print_xml(ostream &out, bool constrained, const string &blob = "");
317 
318  void mark_all(bool state);
319  bool mark(const string &name, bool state);
320  bool check_semantics(bool all = false);
321 
322  void tag_nested_sequences();
323 
324  virtual void dump(ostream &strm) const ;
325 };
326 
327 } // namespace libdap
328 
329 #endif // _dds_h
void print(FILE *out)
Print the entire DDS to the specified file.
Definition: DDS.cc:936
DDS(BaseTypeFactory *factory, const string &n="")
Definition: DDS.cc:142
Contains the attributes for a dataset.
Definition: AttrTable.h:146
Vars_iter get_vars_iter(int i)
Get an iterator.
Definition: DDS.cc:793
BaseType * leaf_match(const string &name, BaseType::btp_stack *s=0)
Definition: DDS.cc:697
Vars_iter var_begin()
Return an iterator to the first variable.
Definition: DDS.cc:766
void set_timeout(int t)
Definition: DDS.cc:831
BaseType * var(const string &n, BaseType::btp_stack &s)
Definition: DDS.cc:659
virtual void transfer_attributes(DAS *das)
Definition: DDS.cc:367
void print_xml(FILE *out, bool constrained, const string &blob="")
Definition: DDS.cc:1054
friend class DDSTest
Definition: DDS.h:199
std::vector< BaseType * >::const_iterator Vars_citer
Definition: DDS.h:210
void timeout_off()
Definition: DDS.cc:823
Holds a structure (aggregate) type.
Definition: Structure.h:100
Vars_riter var_rend()
Return a reverse iterator.
Definition: DDS.cc:784
string get_dataset_name() const
Definition: DDS.cc:444
int num_var()
Returns the number of variables in the DDS.
Definition: DDS.cc:809
std::vector< BaseType * >::reverse_iterator Vars_riter
Definition: DDS.h:212
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:1254
void parse(string fname)
Parse a DDS from a file with the given name.
Definition: DDS.cc:858
DDS & operator=(const DDS &rhs)
Definition: DDS.cc:170
virtual ~DDS()
Definition: DDS.cc:160
void mark_all(bool state)
Definition: DDS.cc:1298
std::vector< BaseType * >::iterator Vars_iter
Definition: DDS.h:211
virtual AttrTable & get_attr_table()
Definition: DDS.cc:460
BaseType * get_var_index(int i)
Get a variable.
Definition: DDS.cc:802
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
Definition: DDS.cc:1208
void set_dap_version(const string &version_string)
Definition: DDS.cc:494
Structure * container()
Definition: DDS.cc:559
int get_dap_major() const
Get the DAP major version as sent by the client.
Definition: DDS.h:254
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
Definition: DDS.h:266
string container_name()
Definition: DDS.cc:523
virtual void dump(ostream &strm) const
dumps information about this object
Definition: DDS.cc:1312
void timeout_on()
Definition: DDS.cc:815
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
Definition: DDS.h:241
Vars_iter var_end()
Return an iterator.
Definition: DDS.cc:778
BaseType * exact_match(const string &name, BaseType::btp_stack *s=0)
Definition: DDS.cc:733
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
Definition: DDS.cc:846
void set_dap_minor(int p)
Set the DAP minor version (typically using info from the client)
Definition: DDS.h:261
void set_dataset_name(const string &n)
Definition: DDS.cc:451
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:603
Vars_riter var_rbegin()
Return a reverse iterator.
Definition: DDS.cc:772
Hold attribute data for a DAP2 dataset.
Definition: DAS.h:123
BaseTypeFactory * get_factory() const
Definition: DDS.h:230
void duplicate(const DDS &dds)
Definition: DDS.cc:110
int get_dap_minor() const
Get the DAP minor version as sent by the client.
Definition: DDS.h:256
void set_dap_major(int p)
Set the DAP major version (typically using info from the client)
Definition: DDS.h:259
string filename()
Definition: DDS.cc:475
int get_timeout()
Definition: DDS.cc:838
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Definition: DDS.cc:984
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:572
void set_request_xml_base(const string &xb)
Definition: DDS.h:269