libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
Str.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// (c) COPYRIGHT URI/MIT 1995-1999
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32// Interface for Str type.
33//
34// jhrg 9/7/94
35
36#ifndef _str_h
37#define _str_h 1
38
39#include <string>
40
41#include "dods-limits.h"
42#include "BaseType.h"
43
44namespace libdap
45{
46
47// max_str_len should be large since we always send strings with length bytes
48// as a prefix (so xdr_string will always know how much memory to malloc) but
49// if deserialize gets confused and thinks a ctor (in particular) is a string
50// xdr_string in turn will max_str_len if it cannot get a length byte. A long
51// term solution is to fix libdap, but strings should not routinely be > 32k
52// for the time being... jhrg 4/30/97
53
54const unsigned int max_str_len = DODS_USHRT_MAX - 1;
55
62class Str: public BaseType {
63protected:
64 string d_buf;
65
66public:
67 Str(const string &n);
68 Str(const string &n, const string &d);
69
70 virtual ~Str()
71 {}
72
73 Str(const Str &copy_from);
74
75 Str &operator=(const Str &rhs);
76
77 BaseType *ptr_duplicate() override;
78
79 unsigned int width(bool = false) const override
80 {
81 return sizeof(string);
82 }
83
84 int64_t width_ll(bool = false) const override
85 {
86 return sizeof(string);
87 }
88
89 // Return the length of the stored string or zero if no string has been
90 // stored in the instance's internal buffer.
91 int length() const override;
92 int64_t length_ll() const override;
93
94 // DAP2
95 bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) override;
96 bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) override;
97
98 // DAP4
99 void compute_checksum(Crc32 &checksum) override;
100 void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false) override;
101 void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
102
103 unsigned int val2buf(void *val, bool reuse = false) override;
104 unsigned int buf2val(void **val) override;
105
106 virtual bool set_value(const string &value);
107 virtual string value() const;
108
109 virtual string esc_string_variable_value(const string &s);
110
111 void print_val(FILE *out, string space = "",
112 bool print_decl_p = true) override;
113 void print_val(ostream &out, string space = "",
114 bool print_decl_p = true) override;
115
116 bool ops(BaseType *b, int op) override;
117 bool d4_ops(BaseType *b, int op) override;
118
119 void dump(ostream &strm) const override;
120};
121
122} // namespace libdap
123
124#endif // _str_h
125
Definition crc.h:77
The basic data type for the DODS DAP types.
Definition BaseType.h:120
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:126
Holds character string data.
Definition Str.h:62
unsigned int buf2val(void **val) override
Definition Str.cc:210
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition Str.cc:172
int64_t length_ll() const override
Get the number of elements in this variable This version of the function deprecates length() which is...
Definition Str.cc:133
Str(const string &n)
Definition Str.cc:92
bool d4_ops(BaseType *b, int op) override
Definition Str.cc:335
int length() const override
How many elements are in this variable? Uses -1 in places.
Definition Str.cc:127
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Move data to the net, then remove them from the object.
Definition Str.cc:139
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
Definition Str.cc:164
virtual string value() const
Definition Str.cc:268
unsigned int width(bool=false) const override
How many bytes does this variable use Return the number of bytes of storage this variable uses....
Definition Str.h:79
void dump(ostream &strm) const override
dumps information about this object
Definition Str.cc:367
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition Str.cc:307
BaseType * ptr_duplicate() override
Definition Str.cc:111
unsigned int val2buf(void *val, bool reuse=false) override
Definition Str.cc:238
virtual bool set_value(const string &value)
Definition Str.cc:257
void print_val(FILE *out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition Str.cc:274
virtual string esc_string_variable_value(const string &s)
Escape non-printable characters and quotes from a Str variable value. The value printed is used mostl...
Definition Str.cc:289
top level DAP object to house generic methods
Definition AISConnect.cc:30