libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Str.h
Go to the documentation of this file.
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 "BaseType.h"
42#include "dods-limits.h"
43
44namespace libdap {
45
46// max_str_len should be large since we always send strings with length bytes
47// as a prefix (so xdr_string will always know how much memory to malloc) but
48// if deserialize gets confused and thinks a ctor (in particular) is a string
49// xdr_string in turn will max_str_len if it cannot get a length byte. A long
50// term solution is to fix libdap, but strings should not routinely be > 32k
51// for the time being... jhrg 4/30/97
52
53const unsigned int max_str_len = DODS_USHRT_MAX - 1;
54
60
61class Str : public BaseType {
62protected:
63 string d_buf;
64
65public:
66 Str(const string &n);
67 Str(const string &n, const string &d);
68
69 virtual ~Str() {}
70
71 Str(const Str &copy_from);
72
73 Str &operator=(const Str &rhs);
74
75 BaseType *ptr_duplicate() override;
76
77 unsigned int width(bool = false) const override { return sizeof(string); }
78
79 int64_t width_ll(bool = false) const override { return sizeof(string); }
80
81 // Return the length of the stored string or zero if no string has been
82 // stored in the instance's internal buffer.
83 int length() const override;
84 int64_t length_ll() const override;
85
86 // DAP2
87 bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) override;
88 bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) override;
89
90 // DAP4
91 void compute_checksum(Crc32 &checksum) override;
92 void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false) override;
93 void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
94
95 unsigned int val2buf(void *val, bool reuse = false) override;
96 unsigned int buf2val(void **val) override;
97
98 virtual bool set_value(const string &value);
99 virtual string value() const;
100
101 virtual string esc_string_variable_value(const string &s);
102
103 void print_val(FILE *out, string space = "", bool print_decl_p = true) override;
104 void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
105
106 bool ops(BaseType *b, int op) override;
107 bool d4_ops(BaseType *b, int op) override;
108
109 void dump(ostream &strm) const override;
110};
111
112} // namespace libdap
113
114#endif // _str_h
Definition crc.h:43
The basic data type for the DODS DAP types.
Definition BaseType.h:118
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:124
Evaluate a constraint expression.
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.
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
Holds character string data.
Definition Str.h:61
Str & operator=(const Str &rhs)
Definition Str.cc:106
int64_t width_ll(bool=false) const override
Definition Str.h:79
unsigned int buf2val(void **val) override
Definition Str.cc:177
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:147
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:116
Str(const string &n)
Definition Str.cc:91
bool d4_ops(BaseType *b, int op) override
Definition Str.cc:281
int length() const override
How many elements are in this variable? Uses -1 in places.
Definition Str.cc:114
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:118
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
Definition Str.cc:141
virtual ~Str()
Definition Str.h:69
virtual string value() const
Definition Str.cc:228
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:77
void dump(ostream &strm) const override
dumps information about this object
Definition Str.cc:311
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition Str.cc:254
BaseType * ptr_duplicate() override
Definition Str.cc:104
unsigned int val2buf(void *val, bool reuse=false) override
Definition Str.cc:202
virtual bool set_value(const string &value)
Definition Str.cc:219
void print_val(FILE *out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition Str.cc:230
string d_buf
Definition Str.h:63
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:243
abstract base class used to unmarshall/deserialize dap data objects
#define DODS_USHRT_MAX
Definition dods-limits.h:70
top level DAP object to house generic methods
Definition AISConnect.cc:30
const unsigned int max_str_len
Definition Str.h:53