Blame Str.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1995-1999
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
Packit a4aae4
Packit a4aae4
// Interface for Str type.
Packit a4aae4
//
Packit a4aae4
// jhrg 9/7/94
Packit a4aae4
Packit a4aae4
#ifndef _str_h
Packit a4aae4
#define _str_h 1
Packit a4aae4
Packit a4aae4
#include <string>
Packit a4aae4
Packit a4aae4
#include "dods-limits.h"
Packit a4aae4
#include "BaseType.h"
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
// max_str_len should be large since we always send strings with length bytes
Packit a4aae4
// as a prefix (so xdr_string will always know how much memory to malloc) but
Packit a4aae4
// if deserialize gets confused and thinks a ctor (in particular) is a string
Packit a4aae4
// xdr_string in turn will max_str_len if it cannot get a length byte. A long
Packit a4aae4
// term solution is to fix libdap, but strings should not routinely be > 32k
Packit a4aae4
// for the time being... jhrg 4/30/97
Packit a4aae4
Packit a4aae4
const unsigned int max_str_len = DODS_USHRT_MAX - 1;
Packit a4aae4
Packit a4aae4
/** @brief Holds character string data.
Packit a4aae4
Packit a4aae4
    @see BaseType
Packit a4aae4
    @see Url
Packit a4aae4
    */
Packit a4aae4
Packit a4aae4
class Str: public BaseType
Packit a4aae4
{
Packit a4aae4
protected:
Packit a4aae4
    string d_buf;
Packit a4aae4
Packit a4aae4
public:
Packit a4aae4
    Str(const string &n);
Packit a4aae4
    Str(const string &n, const string &d);
Packit a4aae4
Packit a4aae4
    virtual ~Str()
Packit a4aae4
    {}
Packit a4aae4
Packit a4aae4
    Str(const Str &copy_from);
Packit a4aae4
Packit a4aae4
    Str &operator=(const Str &rhs;;
Packit a4aae4
Packit a4aae4
    virtual BaseType *ptr_duplicate();
Packit a4aae4
Packit a4aae4
    virtual unsigned int width(bool constrained = false) const;
Packit a4aae4
Packit a4aae4
    // Return the length of the stored string or zero if no string has been
Packit a4aae4
    // stored in the instance's internal buffer.
Packit a4aae4
    virtual int length() const;
Packit a4aae4
Packit a4aae4
    // DAP2
Packit a4aae4
    virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
Packit a4aae4
    virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
Packit a4aae4
Packit a4aae4
    // DAP4
Packit a4aae4
    virtual void compute_checksum(Crc32 &checksum);
Packit a4aae4
    virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
Packit a4aae4
    virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
Packit a4aae4
Packit a4aae4
    virtual unsigned int val2buf(void *val, bool reuse = false);
Packit a4aae4
    virtual unsigned int buf2val(void **val);
Packit a4aae4
Packit a4aae4
    virtual bool set_value(const string &value);
Packit a4aae4
    virtual string value() const;
Packit a4aae4
Packit a4aae4
    virtual void print_val(FILE *out, string space = "",
Packit a4aae4
                           bool print_decl_p = true);
Packit a4aae4
    virtual void print_val(ostream &out, string space = "",
Packit a4aae4
                           bool print_decl_p = true);
Packit a4aae4
Packit a4aae4
    virtual bool ops(BaseType *b, int op);
Packit a4aae4
    virtual bool d4_ops(BaseType *b, int op);
Packit a4aae4
Packit a4aae4
    virtual void dump(ostream &strm) const ;
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif // _str_h
Packit a4aae4