DDS.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// (c) COPYRIGHT URI/MIT 1994-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
// Provide access to the DDS. This class is used to parse DDS text files, to
// produce a printed representation of the in-memory variable table, and to
// update the table on a per-variable basis.
//
// jhrg 9/8/94
#ifndef _dds_h
#define _dds_h 1
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#ifndef _basetype_h
#include "BaseType.h"
#endif
#ifndef _constructor_h
#include "Constructor.h"
#endif
#ifndef base_type_factory_h
#include "BaseTypeFactory.h"
#endif
#ifndef _das_h
#include "DAS.h"
#endif
#ifndef A_DapObj_h
#include "DapObj.h"
#endif
#if 0
#ifndef KEYWORDS_H_
#include "Keywords2.h"
#endif
#endif
#ifndef XMLWRITER_H_
#include "XMLWriter.h"
#endif
namespace libdap
{
bool has_dap2_attributes(BaseType *btp);
bool has_dap2_attributes(AttrTable &a);
class DDS : public DapObj
{
private:
BaseTypeFactory *d_factory;
string d_name; // The dataset d_name
string d_filename; // File d_name (or other OS identifier) for
string d_container_name; // d_name of container structure
Structure *d_container; // current container for container d_name
// dataset or part of dataset.
int d_dap_major; // The protocol major version number
int d_dap_minor; // ... and minor version number
string d_dap_version; // String version of the protocol
string d_request_xml_base;
string d_namespace;
AttrTable d_attr; // Global attributes.
vector<BaseType *> vars; // Variables at the top level
int d_timeout; // alarm time in seconds. If greater than
// zero, raise the alarm signal if more than
// d_timeout seconds are spent reading data.
#if 0
Keywords d_keywords; // Holds keywords parsed from the CE
#endif
uint64_t d_max_response_size_kb; // In kilobytes...
friend class DDSTest;
protected:
void duplicate(const DDS &dds);
BaseType *leaf_match(const string &name, BaseType::btp_stack *s = 0);
BaseType *exact_match(const string &name, BaseType::btp_stack *s = 0);
public:
typedef std::vector<BaseType *>::const_iterator Vars_citer ;
typedef std::vector<BaseType *>::iterator Vars_iter ;
typedef std::vector<BaseType *>::reverse_iterator Vars_riter ;
DDS(BaseTypeFactory *factory, const string &name = "");
DDS(BaseTypeFactory *factory, const string &name, const string &version);
DDS(const DDS &dds);
virtual ~DDS();
DDS & operator=(const DDS &rhs);
virtual void transfer_attributes(DAS *das);
string get_dataset_name() const;
void set_dataset_name(const string &n);
BaseTypeFactory *get_factory() const
{
return d_factory;
}
BaseTypeFactory *set_factory(BaseTypeFactory *factory)
{
BaseTypeFactory *t = d_factory;
d_factory = factory;
return t;
}
virtual AttrTable &get_attr_table();
string filename() const;
void filename(const string &fn);
int get_dap_major() const { return d_dap_major; }
int get_dap_minor() const { return d_dap_minor; }
void set_dap_version(const string &version_string = "2.0");
string get_dap_version() const { return d_dap_version; }
string get_dmr_version() const { return "1.0"; }
void set_dap_major(int p);
void set_dap_minor(int p);
void set_dap_version(double d);
#if 0
Keywords &get_keywords() {return d_keywords;}
#endif
string get_request_xml_base() const { return d_request_xml_base; }
void set_request_xml_base(const string &xb) { d_request_xml_base = xb; }
string get_namespace() const { return d_namespace; }
void set_namespace(const string &ns) { d_namespace = ns; }
[[deprecated("Use DDS::get_response_limit_kb()")]]
long get_response_limit() { return (long)(d_max_response_size_kb * 1024); }
uint64_t get_response_limit_kb() const { return d_max_response_size_kb; }
[[deprecated("Use DDS::set_response_limit_kb(uint64_t &size)")]]
void set_response_limit(long size) { d_max_response_size_kb = size; }
void set_response_limit_kb(uint64_t size) { d_max_response_size_kb = size; }
bool too_big() {
return d_max_response_size_kb != 0 && get_request_size_kb(true) > d_max_response_size_kb;
}
[[deprecated("Use DDS::get_request_size_kb()")]]
int get_request_size(bool constrained);
uint64_t get_request_size_kb(bool constrained);
string container_name() ;
void container_name( const string &cn ) ;
Structure *container() ;
void add_var(BaseType *bt);
void add_var_nocopy(BaseType *bt);
void del_var(const string &n);
BaseType *var(const string &n, BaseType::btp_stack &s);
BaseType *var(const string &n, BaseType::btp_stack *s = 0);
int num_var();
Vars_iter var_begin();
#if 0
Vars_citer var_cbegin() const { return vars.cbegin(); }
#endif
Vars_riter var_rbegin();
Vars_iter var_end();
#if 0
Vars_citer var_cend() const { return vars.cend(); }
#endif
Vars_riter var_rend();
Vars_iter get_vars_iter(int i);
BaseType *get_var_index(int i);
void insert_var(Vars_iter i, BaseType *ptr);
void insert_var_nocopy(Vars_iter i, BaseType *ptr);
void del_var(Vars_iter i);
void del_var(Vars_iter i1, Vars_iter i2);
void timeout_on();
void timeout_off();
void set_timeout(int t);
int get_timeout();
// These parse the DAP2 curly-brace document and make a C++ object.
void parse(string fname);
void parse(int fd);
void parse(FILE *in = stdin);
// These print the Binary object in either the curly-brace or XML reps
void print(FILE *out);
void print_constrained(FILE *out);
void print_xml(FILE *out, bool constrained, const string &blob = "");
// Same as above, but using C++ i/o streams
void print(ostream &out);
void print_constrained(ostream &out);
void print_xml(ostream &out, bool constrained, const string &blob = "");
// Print the XML using libxml2; the other print_xml methods use this impl.
void print_xml_writer(ostream &out, bool constrained, const string &blob = "");
// Print the DAP4 DMR 'object'
void print_dmr(ostream &out, bool constrained);
void print_das(ostream &out);
DAS *get_das();
void get_das(DAS *das);
void mark_all(bool state);
bool mark(const string &name, bool state);
bool check_semantics(bool all = false);
void tag_nested_sequences();
virtual void dump(ostream &strm) const ;
};
} // namespace libdap
#endif // _dds_h
libdap::AttrTable
Contains the attributes for a dataset.
Definition: AttrTable.h:143
libdap::BaseTypeFactory
Definition: BaseTypeFactory.h:81
libdap::BaseType
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
libdap::DAS
Hold attribute data for a DAP2 dataset.
Definition: DAS.h:122
libdap::DDS
Definition: DDS.h:184
libdap::DDS::set_dataset_name
void set_dataset_name(const string &n)
Definition: DDS.cc:364
libdap::DDS::set_dap_major
void set_dap_major(int p)
Definition: DDS.cc:405
libdap::DDS::mark_all
void mark_all(bool state)
Definition: DDS.cc:1849
libdap::DDS::print_dmr
void print_dmr(ostream &out, bool constrained)
Print the DAP4 DMR object using a DDS.
Definition: DDS.cc:1677
libdap::DDS::var_rend
Vars_riter var_rend()
Return a reverse iterator.
Definition: DDS.cc:845
libdap::DDS::add_var_nocopy
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
Definition: DDS.cc:641
libdap::DDS::check_semantics
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
Definition: DDS.cc:1748
libdap::DDS::set_namespace
void set_namespace(const string &ns)
Set the namespace for this DDS/DDX object/response.
Definition: DDS.h:295
libdap::DDS::filename
string filename() const
Definition: DDS.cc:388
libdap::DDS::get_attr_table
virtual AttrTable & get_attr_table()
Definition: DDS.cc:373
libdap::DDS::set_request_xml_base
void set_request_xml_base(const string &xb)
Definition: DDS.h:289
libdap::DDS::set_response_limit
void set_response_limit(long size)
Definition: DDS.h:313
libdap::DDS::get_request_size_kb
uint64_t get_request_size_kb(bool constrained)
Get the estimated response size in kilobytes.
Definition: DDS.cc:593
libdap::DDS::transfer_attributes
virtual void transfer_attributes(DAS *das)
Definition: DDS.cc:287
libdap::DDS::get_factory
BaseTypeFactory * get_factory() const
Definition: DDS.h:242
libdap::DDS::set_dap_minor
void set_dap_minor(int p)
Definition: DDS.cc:424
libdap::DDS::var_rbegin
Vars_riter var_rbegin()
Return a reverse iterator.
Definition: DDS.cc:833
libdap::DDS::get_namespace
string get_namespace() const
Get the namespace associated with the DDS - likely set only by DDX responses.
Definition: DDS.h:292
libdap::DDS::num_var
int num_var()
Returns the number of variables in the DDS.
Definition: DDS.cc:901
libdap::DDS::get_vars_iter
Vars_iter get_vars_iter(int i)
Get an iterator.
Definition: DDS.cc:854
libdap::DDS::print
void print(FILE *out)
Print the entire DDS to the specified file.
Definition: DDS.cc:1051
libdap::DDS::get_var_index
BaseType * get_var_index(int i)
Get a variable.
Definition: DDS.cc:863
libdap::DDS::get_request_size
int get_request_size(bool constrained)
Get the estimated response size in bytes.
Definition: DDS.cc:566
libdap::DDS::get_dataset_name
string get_dataset_name() const
Definition: DDS.cc:357
libdap::DDS::too_big
bool too_big()
Definition: DDS.h:325
libdap::DDS::del_var
void del_var(const string &n)
Removes a variable from the DDS.
Definition: DDS.cc:664
libdap::DDS::parse
void parse(string fname)
Parse a DDS from a file with the given d_name.
Definition: DDS.cc:970
libdap::DDS::var
BaseType * var(const string &n, BaseType::btp_stack &s)
Definition: DDS.cc:720
libdap::DDS::print_xml
void print_xml(FILE *out, bool constrained, const string &blob="")
Definition: DDS.cc:1406
libdap::DDS::insert_var
void insert_var(Vars_iter i, BaseType *ptr)
Insert a variable before the referenced element.
Definition: DDS.cc:873
libdap::DDS::mark
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
Definition: DDS.cc:1792
libdap::DDS::get_dap_minor
int get_dap_minor() const
Get the DAP minor version as sent by the client.
Definition: DDS.h:268
libdap::DDS::get_response_limit_kb
uint64_t get_response_limit_kb() const
The maximum allowed response size, in kilobytes. Zero indicates no limit (default).
Definition: DDS.h:305
libdap::DDS::DDS
DDS(BaseTypeFactory *factory, const string &name="")
Definition: DDS.cc:205
libdap::DDS::tag_nested_sequences
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
Definition: DDS.cc:958
libdap::DDS::get_das
DAS * get_das()
Get a DAS object.
Definition: DDS.cc:1239
libdap::DDS::print_constrained
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Definition: DDS.cc:1360
libdap::DDS::var_begin
Vars_iter var_begin()
Return an iterator to the first variable.
Definition: DDS.cc:827
libdap::DDS::container_name
string container_name()
Definition: DDS.cc:512
libdap::DDS::set_factory
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
Definition: DDS.h:253
libdap::DDS::insert_var_nocopy
void insert_var_nocopy(Vars_iter i, BaseType *ptr)
Definition: DDS.cc:890
libdap::DDS::get_request_xml_base
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
Definition: DDS.h:286
libdap::DDS::set_response_limit_kb
void set_response_limit_kb(uint64_t size)
Set the maximum response size, in kilobytes. The size is given in kilobytes..
Definition: DDS.h:320
libdap::DDS::get_dap_major
int get_dap_major() const
Get the DAP major version as sent by the client.
Definition: DDS.h:266
libdap::DDS::var_end
Vars_iter var_end()
Return an iterator.
Definition: DDS.cc:839
libdap::DDS::set_dap_version
void set_dap_version(const string &version_string="2.0")
Definition: DDS.cc:441
libdap::DDS::container
Structure * container()
Definition: DDS.cc:548
libdap::DDS::add_var
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:614
libdap::DDS::print_xml_writer
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
Definition: DDS.cc:1461
libdap::DDS::get_response_limit
long get_response_limit()
Get the maximum response size, in bytes. Zero indicates no limit.
Definition: DDS.h:299
libdap::DDS::print_das
void print_das(ostream &out)
write the DAS response given the attribute information in the DDS
Definition: DDS.cc:1210
libdap::DDS::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: DDS.cc:1863
libdap::DapObj
libdap base object for common functionality of libdap objects
Definition: DapObj.h:51
libdap::Keywords
Definition: Keywords2.h:52
libdap::Structure
Holds a structure (aggregate) type.
Definition: Structure.h:84
libdap
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
libdap::has_dap2_attributes
bool has_dap2_attributes(AttrTable &a)
Definition: DDS.cc:1081