libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Opaque.cc
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) 2013 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 D4Opaqueeet, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25// #define DODS_DEBUG
26
27#include "config.h"
28
29#include <iterator>
30#include <sstream>
31
32#include "D4Opaque.h"
33
34#include "D4StreamMarshaller.h"
36#include "DMR.h"
37
38#include "crc.h"
39#include "util.h"
40
41#include "DapIndent.h"
42#include "debug.h"
43
44#undef CLEAR_LOCAL_DATA
45
46using namespace std;
47
48namespace libdap {
49
51 if (this == &rhs)
52 return *this;
54 d_buf = rhs.d_buf;
55 return *this;
56}
57
59 if (!d_buf.empty()) {
60 d_buf.erase(d_buf.begin(), d_buf.end());
61 d_buf.resize(0);
62 }
63
64 set_read_p(false);
65}
66
67void D4Opaque::compute_checksum(Crc32 &checksum) { checksum.AddData(d_buf.data(), d_buf.size()); }
68
70 if (!read_p())
71 read(); // read() throws Error
72
73 m.put_opaque_dap4(reinterpret_cast<char *>(d_buf.data()), d_buf.size());
74
75#ifdef CLEAR_LOCAL_DATA
77#endif
78}
79
81
82unsigned int D4Opaque::buf2val(void **val) {
83 assert(val);
84
85 // If *val is null, then the caller has not allocated storage for the
86 // value; we must. If there is storage there, assume it is a vector<uint8_t>
87 // (i.e., dods_opaque) and assign d_buf's value to that storage.
88 if (!*val)
89 *val = new vector<uint8_t>;
90 else
91 *static_cast<vector<uint8_t> *>(*val) = d_buf;
92
93 return sizeof(vector<uint8_t> *);
94}
95
96unsigned int D4Opaque::val2buf(void *val, bool) {
97 assert(val);
98
99 d_buf = *static_cast<dods_opaque *>(val);
100
101 return sizeof(dods_opaque *);
102}
103
109 d_buf = value;
110 set_read_p(true);
111
112 return true;
113}
114
118
119std::vector<BaseType *> *D4Opaque::transform_to_dap2(AttrTable *) {
120 DBG(cerr << __func__ << "() - Transform not implemented DAP4 Opaque type." << endl;);
121 return NULL;
122}
123
124void D4Opaque::print_val(ostream &out, string space, bool print_decl_p) {
125 if (print_decl_p)
126 print_decl(out, space, false);
127
128 if (d_buf.size()) {
129 // end() - 1 is only OK if size() is > 0
130 std::ostream_iterator<unsigned int> out_it(out, ",");
131 std::copy(d_buf.begin(), d_buf.end() - 1, out_it);
132 out << (unsigned int)d_buf.back(); // can also use: *(d_buf.end()-1);
133 }
134
135 if (print_decl_p)
136 out << ";" << endl;
137}
138
139void D4Opaque::dump(ostream &strm) const {
140 strm << DapIndent::LMarg << "D4Opaque::dump - (" << (void *)this << ")" << endl;
142 BaseType::dump(strm);
143 // strm << DapIndent::LMarg << "value: " << d_buf << endl ;
144 ostream_iterator<uint8_t> out_it(strm, " ");
145 std::copy(d_buf.begin(), d_buf.end(), out_it);
146
148}
149
150} // namespace libdap
Definition crc.h:43
void AddData(const uint8_t *pData, const uint32_t length)
Definition crc.h:64
Contains the attributes for a dataset.
Definition AttrTable.h:150
BaseType & operator=(const BaseType &rhs)
Definition BaseType.cc:159
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:775
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
Definition BaseType.cc:868
virtual bool read_p()
Has this variable been read?
Definition BaseType.cc:410
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition BaseType.cc:442
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:269
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
DAP4 to DAP2 transform.
Definition D4Opaque.cc:119
void print_val(FILE *, std::string="", bool=true) override
Prints the value of the variable.
Definition D4Opaque.h:88
std::vector< uint8_t > dods_opaque
Definition D4Opaque.h:39
void dump(std::ostream &strm) const override
dumps information about this object
Definition D4Opaque.cc:139
D4Opaque(const std::string &n)
Definition D4Opaque.h:45
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition D4Opaque.cc:67
void clear_local_data() override
Definition D4Opaque.cc:58
virtual dods_opaque value() const
Definition D4Opaque.cc:117
unsigned int buf2val(void **val) override
Reads the class data.
Definition D4Opaque.cc:82
unsigned int val2buf(void *val, bool reuse=false) override
Loads class data.
Definition D4Opaque.cc:96
dods_opaque d_buf
Definition D4Opaque.h:42
bool deserialize(UnMarshaller &, DDS *, bool=false) override
Receive data from the net.
Definition D4Opaque.h:70
D4Opaque & operator=(const D4Opaque &rhs)
Definition D4Opaque.cc:50
virtual bool set_value(const dods_opaque &value)
Definition D4Opaque.cc:108
bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool=true) override
Move data to the net, then remove them from the object.
Definition D4Opaque.h:67
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void put_opaque_dap4(const char *val, int64_t len)
Read data from the stream made by D4StreamMarshaller.
virtual void get_opaque_dap4(char **val, int64_t &len)
static ostream & LMarg(ostream &strm)
Definition DapIndent.cc:61
static void Indent()
Definition DapIndent.cc:44
static void UnIndent()
Definition DapIndent.cc:46
#define DBG(x)
Definition debug.h:58
top level DAP object to house generic methods
Definition AISConnect.cc:30