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 Street, Fifth Floor, Boston, MA  02110-1301  USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #ifndef _d4_opaque_h
26 #define _d4_opaque_h 1
27 
28 #include <vector>
29 
30 #include "BaseType.h"
31 #include "InternalErr.h"
32 
33 class Crc32;
34 
35 namespace libdap
36 {
37 
38 class D4Opaque: public BaseType
39 {
40 public:
41 	typedef std::vector<uint8_t> dods_opaque;
42 
43 protected:
44     dods_opaque d_buf;
45 
46 public:
D4Opaque(const std::string & n)47     D4Opaque(const std::string &n) : BaseType(n, dods_opaque_c, true /*is_dap4*/), d_buf(0) { }
D4Opaque(const std::string & n,const std::string & d)48     D4Opaque(const std::string &n, const std::string &d)  : BaseType(n, d, dods_opaque_c, true /*is_dap4*/), d_buf(0) { }
49 
~D4Opaque()50     virtual ~D4Opaque()  { }
51 
D4Opaque(const D4Opaque & copy_from)52     D4Opaque(const D4Opaque &copy_from) : BaseType(copy_from) {
53         d_buf = copy_from.d_buf;
54     }
55 
56     D4Opaque &operator=(const D4Opaque &rhs);
57 
ptr_duplicate()58     virtual BaseType *ptr_duplicate() {  return new D4Opaque(*this); }
59 
60     virtual void clear_local_data();
61 
62     virtual unsigned int width(bool = false) const { return sizeof(vector<uint8_t>); }
63 
64     // Return the length of the stored data or zero if no string has been
65     // stored in the instance's internal buffer.
length()66     virtual int length() const { return d_buf.size(); }
67 
68     // DAP2
69     virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool = true) {
70     	throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
71     }
72     virtual bool deserialize(UnMarshaller &, DDS *, bool = false) {
73     	throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
74     }
75 
76     // DAP4
77     virtual void compute_checksum(Crc32 &checksum);
78     virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
79 #if 0
80     virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
81 #endif
82     virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
83 
84     virtual unsigned int val2buf(void *val, bool reuse = false);
85     virtual unsigned int buf2val(void **val);
86 
87     virtual bool set_value(const dods_opaque &value);
88     virtual dods_opaque value() const;
89 
90     virtual void print_val(FILE *, std::string = "", bool = true)  {
91     	throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
92     }
93     virtual void print_val(std::ostream &out, std::string space = "", bool print_decl_p = true);
94 
95     //virtual void print_dap4(XMLWriter &xml, bool constrained = false);
96 
ops(BaseType *,int)97     virtual bool ops(BaseType *, int) {
98         throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
99     }
100 
101     virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
102 
103     virtual void dump(std::ostream &strm) const ;
104 
105 };
106 
107 } // namespace libdap
108 
109 #endif // _d4_opaque_h
110 
111