libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Opaque.cc
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 <sstream>
30#include <iterator>
31
32#include "D4Opaque.h"
33
34#include "DMR.h"
35#include "D4StreamMarshaller.h"
36#include "D4StreamUnMarshaller.h"
37
38#include "util.h"
39#include "crc.h"
40
41#include "debug.h"
42#include "DapIndent.h"
43
44#undef CLEAR_LOCAL_DATA
45
46using namespace std;
47
48namespace libdap {
49
50D4Opaque &
51D4Opaque::operator=(const D4Opaque &rhs)
52{
53 if (this == &rhs)
54 return *this;
55 BaseType::operator=(rhs);
56 d_buf = rhs.d_buf;
57 return *this;
58}
59
60void
62{
63 if (!d_buf.empty()) {
64 d_buf.erase(d_buf.begin(), d_buf.end());
65 d_buf.resize(0);
66 }
67
68 set_read_p(false);
69}
70
71void
73{
74 checksum.AddData(d_buf.data(), d_buf.size());
75}
76
77void
79{
80 if (!read_p())
81 read(); // read() throws Error
82
83 m.put_opaque_dap4( reinterpret_cast<char*>(d_buf.data()), d_buf.size() ) ;
84
85#ifdef CLEAR_LOCAL_DATA
87#endif
88
89}
90
91void
93{
94 um.get_opaque_dap4( d_buf ) ;
95}
96
97unsigned int
99{
100 assert(val);
101
102 // If *val is null, then the caller has not allocated storage for the
103 // value; we must. If there is storage there, assume it is a vector<uint8_t>
104 // (i.e., dods_opaque) and assign d_buf's value to that storage.
105 if (!*val)
106 *val = new vector<uint8_t>;
107 else
108 *static_cast<vector<uint8_t>*>(*val) = d_buf;
109
110 return sizeof(vector<uint8_t>*);
111}
112
113unsigned int
114D4Opaque::val2buf(void *val, bool)
115{
116 assert(val);
117
118 d_buf = *static_cast<dods_opaque*>(val);
119
120 return sizeof(dods_opaque*);
121}
122
127bool
128D4Opaque::set_value(const dods_opaque &value)
129{
130 d_buf = value;
131 set_read_p(true);
132
133 return true;
134}
135
138D4Opaque::dods_opaque
140{
141 return d_buf;
142}
143
144std::vector<BaseType *> *
146 DBG(cerr << __func__ << "() - Transform not implemented DAP4 Opaque type." << endl;);
147 return NULL;
148}
149
150
151void
152D4Opaque::print_val(ostream &out, string space, bool print_decl_p)
153{
154 if (print_decl_p) print_decl(out, space, false);
155
156 if (d_buf.size()) {
157 // end() - 1 is only OK if size() is > 0
158 std::ostream_iterator<unsigned int> out_it(out, ",");
159 std::copy(d_buf.begin(), d_buf.end() - 1, out_it);
160 out << (unsigned int) d_buf.back(); // can also use: *(d_buf.end()-1);
161 }
162
163 if (print_decl_p) out << ";" << endl;
164}
165
166void
167D4Opaque::dump(ostream &strm) const
168{
169 strm << DapIndent::LMarg << "D4Opaque::dump - ("
170 << (void *)this << ")" << endl ;
171 DapIndent::Indent() ;
172 BaseType::dump(strm) ;
173 //strm << DapIndent::LMarg << "value: " << d_buf << endl ;
174 ostream_iterator<uint8_t> out_it (strm," ");
175 std::copy ( d_buf.begin(), d_buf.end(), out_it );
176
177 DapIndent::UnIndent() ;
178}
179
180} // namespace libdap
181
Definition: crc.h:77
void AddData(const uint8_t *pData, const uint32_t length)
Definition: crc.h:98
Contains the attributes for a dataset.
Definition: AttrTable.h:143
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:895
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:999
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:476
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:512
void dump(ostream &strm) const override
dumps information about this object
Definition: BaseType.cc:287
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
DAP4 to DAP2 transform.
Definition: D4Opaque.cc:145
virtual bool deserialize(UnMarshaller &, DDS *, bool=false)
Receive data from the net.
Definition: D4Opaque.h:72
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition: D4Opaque.cc:72
virtual unsigned int buf2val(void **val)
Reads the class data.
Definition: D4Opaque.cc:98
virtual void clear_local_data()
Definition: D4Opaque.cc:61
virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool=true)
Move data to the net, then remove them from the object.
Definition: D4Opaque.h:69
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: D4Opaque.cc:167
virtual dods_opaque value() const
Definition: D4Opaque.cc:139
virtual unsigned int val2buf(void *val, bool reuse=false)
Loads class data.
Definition: D4Opaque.cc:114
virtual bool set_value(const dods_opaque &value)
Definition: D4Opaque.cc:128
virtual void print_val(FILE *, std::string="", bool=true)
Prints the value of the variable.
Definition: D4Opaque.h:90
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
virtual void get_opaque_dap4(char **val, int64_t &len)
top level DAP object to house generic methods
Definition: AlarmHandler.h:36