<commit_before>
// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1995-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      jhrg,jimg       <NAME> <<EMAIL>>

// This is the interface definition file for the abstract class
// Vector. Vector is the parent class for List and Array.

#ifndef _vector_h
#define _vector_h 1

#ifndef _basetype_h
#include "BaseType.h"
#endif

#ifndef _dds_h
#include "DDS.h"
#endif

#ifndef constraint_evaluator_h
#include "ConstraintEvaluator.h"
#endif

class Crc32;

namespace libdap
{

/** Holds a one-dimensional array of DAP2 data types.  This class
    takes two forms, depending on whether the elements of the vector
    are themselves simple or compound objects. This class contains
    common functionality for the List and Array classes, and should
    rarely be used directly.

    When each element of the class is a simple data type, the Vector
    is implemented as a simple array of C types, rather than as an
    array of BaseType data types.  A single private ``template''
    BaseType instance (<tt>_var</tt>) is used to hold information in common
    to all the members of the array.  The template is also used as a
    container to pass values back and forth to an application
    program, as in <tt>var()</tt>.

    If the elements of the vector are themselves compound data
    types, the array is stored as a vector of BaseType pointers (see
    the libdap class <b>BaseTypePtrVec</b>). The template is still used to
    hold information in common to all the members of the array, but
    is not used to pass information to and from the application
    program.

    @brief Holds a one-dimensional collection of DAP2 data types.
    @see BaseType
    @see Array
*/
class Vector: public BaseType
{
private:
    int d_length;  		// number of elements in the vector
    BaseType *d_proto;  // element prototype for the Vector

    // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
    char *d_buf;   		// storage for cardinal data
    vector<string> d_str;		// special storage for strings. jhrg 2/11/05
    vector<BaseType *> d_compound_buf; 	// storage for data in compound types (e.g., Structure)

    // the number of elements we have allocated memory to store.
    // This should be either the sizeof(buf)/width(bool constrained = false) for cardinal data
    // or the capacity of d_str for strings or capacity of _vec.
    unsigned int d_capacity;

protected:
    // This function copies the private members of Vector.
    void m_duplicate(const Vector &v);

    bool m_is_cardinal_type() const;
    unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType);
    void m_delete_cardinal_data_buffer();

    template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int numElts);

public:
    Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false);
    Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false);
    Vector(const Vector &rhs);

    virtual ~Vector();

    Vector &operator=(const Vector &rhs);
    virtual BaseType *ptr_duplicate() = 0;

#if 0
    virtual bool is_dap2_only_type();
#endif

    virtual BaseType *prototype() const { return d_proto; }

    virtual void set_name(const std::string& name);

    virtual int element_count(bool leaves);

    virtual void set_send_p(bool state);

    virtual void set_read_p(bool state);

    virtual unsigned int width(bool constrained = false) const;

    virtual int length() const;

    virtual void set_length(int l);

    // DAP2
    virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
    virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
    virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);

    // DAP4
    virtual void compute_checksum(Crc32 &checksum);
    virtual void intern_data(Crc32 &checksum/*, DMR &dmr, ConstraintEvaluator &eval*/);
    virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
    virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);

    virtual unsigned int val2buf(void *val, bool reuse = false);
    virtual unsigned int buf2val(void **val);

    void set_vec(unsigned int i, BaseType *val);
    void set_vec_nocopy(unsigned int i, BaseType * val);

    void vec_resize(int l);

    void clear_local_data();

    virtual unsigned int get_value_capacity() const;
    virtual void reserve_value_capacity(unsigned int numElements);
    virtual void reserve_value_capacity();

    virtual unsigned int set_value_slice_from_row_major_vector(const Vector& rowMajorData, unsigned int startElement);

    // TODO Use templates?
    template <typename T> bool set_value(T *v, int sz);
    template <typename T> bool set_value(vector<T> &v, int sz);
#if 0
    virtual bool set_value(dods_byte *val, int sz);
    virtual bool set_value(vector<dods_byte> &val, int sz);

    virtual bool set_value(dods_int8 *val, int sz);
    virtual bool set_value(vector<dods_int8> &val, int sz);<commit_msg>Removed incorrect comment in Vector.h<commit_after>
// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1995-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      jhrg,jimg       <NAME> <<EMAIL>>

// This is the interface definition file for the abstract class
// Vector. Vector is the parent class for List and Array.

#ifndef _vector_h
#define _vector_h 1

#ifndef _basetype_h
#include "BaseType.h"
#endif

#ifndef _dds_h
#include "DDS.h"
#endif

#ifndef constraint_evaluator_h
#include "ConstraintEvaluator.h"
#endif

class Crc32;

namespace libdap
{

/** Holds a one-dimensional array of DAP2 data types.  This class
    takes two forms, depending on whether the elements of the vector
    are themselves simple or compound objects. This class contains
    common functionality for the List and Array classes, and should
    rarely be used directly.

    When each element of the class is a simple data type, the Vector
    is implemented as a simple array of C types, rather than as an
    array of BaseType data types.  A single private ``template''
    BaseType instance (<tt>_var</tt>) is used to hold information in common
    to all the members of the array.  The template is also used as a
    container to pass values back and forth to an application
    program, as in <tt>var()</tt>.

    If the elements of the vector are themselves compound data
    types, the array is stored as a vector of BaseType pointers (see
    the libdap class <b>BaseTypePtrVec</b>). The template is still used to
    hold information in common to all the members of the array, but
    is not used to pass information to and from the application
    program.

    @brief Holds a one-dimensional collection of DAP2 data types.
    @see BaseType
    @see Array
*/
class Vector: public BaseType
{
private:
    int d_length;  		// number of elements in the vector
    BaseType *d_proto;  // element prototype for the Vector

    // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
    char *d_buf;   		// storage for cardinal data
    vector<string> d_str;		// special storage for strings. jhrg 2/11/05
    vector<BaseType *> d_compound_buf; 	// storage for data in compound types (e.g., Structure)

    // the number of elements we have allocated memory to store.
    // This should be either the sizeof(buf)/width(bool constrained = false) for cardinal data
    // or the capacity of d_str for strings or capacity of _vec.
    unsigned int d_capacity;

protected:
    // This function copies the private members of Vector.
    void m_duplicate(const Vector &v);

    bool m_is_cardinal_type() const;
    unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType);
    void m_delete_cardinal_data_buffer();

    template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int numElts);

public:
    Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false);
    Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false);
    Vector(const Vector &rhs);

    virtual ~Vector();

    Vector &operator=(const Vector &rhs);
    virtual BaseType *ptr_duplicate() = 0;

#if 0
    virtual bool is_dap2_only_type();
#endif

    virtual BaseType *prototype() const { return d_proto; }

    virtual void set_name(const std::string& name);

    virtual int element_count(bool leaves);

    virtual void set_send_p(bool state);

    virtual void set_read_p(bool state);

    virtual unsigned int width(bool constrained = false) const;

    virtual int length() const;

    virtual void set_length(int l);

    // DAP2
    virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
    virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
    virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);

    // DAP4
    virtual void compute_checksum(Crc32 &checksum);
    virtual void intern_data(Crc32 &checksum/*, DMR &dmr, ConstraintEvaluator &eval*/);
    virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
    virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);

    virtual unsigned int val2buf(void *val, bool reuse = false);
    virtual unsigned int buf2val(void **val);

    void set_vec(unsigned int i, BaseType *val);
    void set_vec_nocopy(unsigned int i, BaseType * val);

    void vec_resize(int l);

    void clear_local_data();

    virtual unsigned int get_value_capacity() const;
    virtual void reserve_value_capacity(unsigned int numElements);
    virtual void reserve_value_capacity();

    virtual unsigned int set_value_slice_from_row_major_vector(const Vector& rowMajorData, unsigned int startElement);

    template <typename T> bool set_value(T *v, int sz);
    template <typename T> bool set_value(vector<T> &v, int sz);
#if 0
    virtual bool set_value(dods_byte *val, int sz);
    virtual bool set_value(vector<dods_byte> &val, int sz);

    virtual bool set_value(dods_int8 *val, int sz);
    virtual bool set_value(vector<dods_int8> &val, int sz);
{'fraction_non_alphanumeric': 0.08297405027251281, 'fraction_numerical': 0.012364760432766615, 'mean_word_length': 3.6044943820224717, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6210373', 'n_tokens_mistral': 3721, 'n_tokens_neox': 3568, 'n_words': 1522}