Blame BaseTypeFactory.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) 2005 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
#ifndef base_type_factory_h
Packit a4aae4
#define base_type_factory_h
Packit a4aae4
Packit a4aae4
#include <string>
Packit a4aae4
Packit a4aae4
#include "Type.h"
Packit a4aae4
#include "InternalErr.h"
Packit a4aae4
Packit a4aae4
// Class declarations; Make sure to include the corresponding headers in the
Packit a4aae4
// implementation file.
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
class Byte;
Packit a4aae4
class Int16;
Packit a4aae4
class UInt16;
Packit a4aae4
class Int32;
Packit a4aae4
class UInt32;
Packit a4aae4
class Float32;
Packit a4aae4
class Float64;
Packit a4aae4
class Str;
Packit a4aae4
class Url;
Packit a4aae4
class Array;
Packit a4aae4
class Structure;
Packit a4aae4
class Sequence;
Packit a4aae4
class Grid;
Packit a4aae4
class BaseType;
Packit a4aae4
Packit a4aae4
/** A factory to create instances of the leaf nodes of BaseType (Byte, ...
Packit a4aae4
    Grid). Clients of libdap++ which require special behavior for the types
Packit a4aae4
    should subclass this factory and provide an implementation which creates
Packit a4aae4
    instances of those specializations. Make sure to pass a reference to the
Packit a4aae4
    new factory to DDS's constructor since by default it uses this factory.
Packit a4aae4
Packit a4aae4
    To define and use your own factory, first make sure that you are not
Packit a4aae4
    using the compile time constant 'DEFAULT_BASETYPE_FACTORY.' Then pass a
Packit a4aae4
    pointer to an instance of your factory to the DDS/DataDDS constructors.
Packit a4aae4
    When the parser is used to build a DDS from a DAP response, the factory
Packit a4aae4
    will be used to instantiate the different variable-type classes.
Packit a4aae4
Packit a4aae4
    @note The easiest way to subclass this is to follow the pattern of using
Packit a4aae4
    a separate class declaration and implementation. It's possible to use one
Packit a4aae4
    file to hold
Packit a4aae4
    both, but that is complicated somewhat because DDS.h, which includes this
Packit a4aae4
    class, also includes many of the type classes (Array.h, ..., Grid.h) and
Packit a4aae4
    the order of their inclusion can create compilation problems where the
Packit a4aae4
    Vector and/or Constructor base classes are not defined. It's easiest to
Packit a4aae4
    split the declaration and implementation and include forward declarations
Packit a4aae4
    of the type classes in the declaration (\c .h) file and then include the
Packit a4aae4
    type class' headers in the implementation (\c .cc) file.
Packit a4aae4
Packit a4aae4
    @author James Gallagher
Packit a4aae4
    @see DDS */
Packit a4aae4
class BaseTypeFactory
Packit a4aae4
{
Packit a4aae4
public:
Packit a4aae4
    BaseTypeFactory()
Packit a4aae4
    {}
Packit a4aae4
    virtual ~BaseTypeFactory()
Packit a4aae4
    {}
Packit a4aae4
Packit a4aae4
    /**
Packit a4aae4
     * Build a new variable and return it using a BaseType pointer. The
Packit a4aae4
     * type of the variable is given using  Type enumeration.
Packit a4aae4
     *
Packit a4aae4
     * @note Added for DAP4
Packit a4aae4
     *
Packit a4aae4
     * @param t The type of the variable to create
Packit a4aae4
     * @parma name The (optional) name of the variable.
Packit a4aae4
     */
Packit a4aae4
    virtual BaseType *NewVariable(Type t, const string &name = "") const;
Packit a4aae4
Packit a4aae4
    /**
Packit a4aae4
     * Clone this object and return a pointer to the clone.
Packit a4aae4
     *
Packit a4aae4
     * @note added for DAP4
Packit a4aae4
     */
Packit a4aae4
    virtual BaseTypeFactory *ptr_duplicate() const {
Packit a4aae4
        throw InternalErr(__FILE__, __LINE__, "Not Implemented.");
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    virtual Byte *NewByte(const string &n = "") const;
Packit a4aae4
    virtual Int16 *NewInt16(const string &n = "") const;
Packit a4aae4
    virtual UInt16 *NewUInt16(const string &n = "") const;
Packit a4aae4
    virtual Int32 *NewInt32(const string &n = "") const;
Packit a4aae4
    virtual UInt32 *NewUInt32(const string &n = "") const;
Packit a4aae4
    virtual Float32 *NewFloat32(const string &n = "") const;
Packit a4aae4
    virtual Float64 *NewFloat64(const string &n = "") const;
Packit a4aae4
Packit a4aae4
    virtual Str *NewStr(const string &n = "") const;
Packit a4aae4
    virtual Url *NewUrl(const string &n = "") const;
Packit a4aae4
Packit a4aae4
    virtual Array *NewArray(const string &n = "", BaseType *v = 0) const;
Packit a4aae4
    virtual Structure *NewStructure(const string &n = "") const;
Packit a4aae4
    virtual Sequence *NewSequence(const string &n = "") const;
Packit a4aae4
    virtual Grid *NewGrid(const string &n = "") const;
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif // base_type_factory_h