Blame D4RValue.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) 2014 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 _D4RValue_h
Packit a4aae4
#define _D4RValue_h
Packit a4aae4
Packit a4aae4
#include <vector>
Packit a4aae4
#include <string>
Packit a4aae4
Packit a4aae4
#include <dods-datatypes.h>
Packit a4aae4
#include <D4Function.h>
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
class BaseType;
Packit a4aae4
class D4RValue;
Packit a4aae4
Packit a4aae4
// Factory class to build RValue objects. User by the parser/ce-evaluator
Packit a4aae4
D4RValue *D4RValueFactory(std::string cpps);
Packit a4aae4
Packit a4aae4
class D4RValueList
Packit a4aae4
{
Packit a4aae4
private:
Packit a4aae4
	std::vector<D4RValue *> d_rvalues;
Packit a4aae4
Packit a4aae4
	void m_duplicate(const D4RValueList &src;;
Packit a4aae4
Packit a4aae4
public:
Packit a4aae4
	typedef std::vector<D4RValue *>::iterator iter;
Packit a4aae4
Packit a4aae4
	D4RValueList() { }
Packit a4aae4
	D4RValueList(const D4RValueList &src) { m_duplicate(src); }
Packit a4aae4
	D4RValueList(D4RValue *rv) { add_rvalue(rv); }
Packit a4aae4
Packit a4aae4
	virtual ~D4RValueList();
Packit a4aae4
Packit a4aae4
	void add_rvalue(D4RValue *rv) {
Packit a4aae4
		d_rvalues.push_back(rv);
Packit a4aae4
	}
Packit a4aae4
Packit a4aae4
	D4RValue *get_rvalue(unsigned int i) {
Packit a4aae4
		return d_rvalues.at(i);
Packit a4aae4
	}
Packit a4aae4
Packit a4aae4
	iter begin() { return d_rvalues.begin(); }
Packit a4aae4
	iter end() { return d_rvalues.end(); }
Packit a4aae4
Packit a4aae4
	unsigned int size() const { return d_rvalues.size(); }
Packit a4aae4
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
/**
Packit a4aae4
 * Holds the RValues for the D4 function parser and for the filter
Packit a4aae4
 * expression evaluator.
Packit a4aae4
 */
Packit a4aae4
class D4RValue
Packit a4aae4
{
Packit a4aae4
public:
Packit a4aae4
    enum value_kind {
Packit a4aae4
        unknown,
Packit a4aae4
        basetype,
Packit a4aae4
        function,
Packit a4aae4
        constant
Packit a4aae4
    };
Packit a4aae4
Packit a4aae4
private:
Packit a4aae4
    BaseType *d_variable;	// This is a weak pointer; do not delete
Packit a4aae4
Packit a4aae4
    D4Function d_func;  	// (weak) pointer to a function returning BaseType *
Packit a4aae4
    D4RValueList *d_args;  	// pointer to arguments to the function; delete
Packit a4aae4
Packit a4aae4
    BaseType *d_constant;	// pointer; delete.
Packit a4aae4
Packit a4aae4
    value_kind d_value_kind;
Packit a4aae4
Packit a4aae4
    /** @brief Clone 'src' to 'this'. */
Packit a4aae4
    void m_duplicate(const D4RValue &src;;
Packit a4aae4
Packit a4aae4
    friend class D4RValueList;
Packit a4aae4
Packit a4aae4
public:
Packit a4aae4
    D4RValue() : d_variable(0), d_func(0), d_args(0), d_constant(0), d_value_kind(unknown) { }
Packit a4aae4
    D4RValue(const D4RValue &src) { m_duplicate(src); }
Packit a4aae4
    D4RValue(BaseType *btp)  : d_variable(btp), d_func(0), d_args(0), d_constant(0), d_value_kind(basetype) { }
Packit a4aae4
    D4RValue(D4Function f, D4RValueList *args)  : d_variable(0), d_func(f), d_args(args), d_constant(0), d_value_kind(function) { }
Packit a4aae4
Packit a4aae4
    D4RValue(unsigned long long ui);
Packit a4aae4
    D4RValue(long long i);
Packit a4aae4
    D4RValue(double r);
Packit a4aae4
    D4RValue(std::string s);
Packit a4aae4
    D4RValue(std::vector<dods_byte> &byte_args);
Packit a4aae4
    D4RValue(std::vector<dods_int8> &byte_int8);
Packit a4aae4
    D4RValue(std::vector<dods_uint16> &byte_uint16);
Packit a4aae4
    D4RValue(std::vector<dods_int16> &byte_int16);
Packit a4aae4
    D4RValue(std::vector<dods_uint32> &byte_uint32);
Packit a4aae4
    D4RValue(std::vector<dods_int32> &byte_int32);
Packit a4aae4
    D4RValue(std::vector<dods_uint64> &byte_uint64);
Packit a4aae4
    D4RValue(std::vector<dods_int64> &byte_int64);
Packit a4aae4
    D4RValue(std::vector<dods_float32> &byte_float32);
Packit a4aae4
    D4RValue(std::vector<dods_float64> &byte_float64);
Packit a4aae4
Packit a4aae4
    virtual ~D4RValue();
Packit a4aae4
Packit a4aae4
    D4RValue &operator=(D4RValue &rhs) {
Packit a4aae4
        if (this == &rhs)
Packit a4aae4
            return *this;
Packit a4aae4
Packit a4aae4
        m_duplicate(rhs);
Packit a4aae4
Packit a4aae4
        return *this;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /**
Packit a4aae4
     * @brief What kind of thing holds the value
Packit a4aae4
     * Values in DAP4 constraints are either constants, dataset variables
Packit a4aae4
     * or function results. It might be nice to know the source of a
Packit a4aae4
     * given value in order to optimize the evaluation of certain kinds of
Packit a4aae4
     * expressions.
Packit a4aae4
     * @return The 'value_kind' of this value.
Packit a4aae4
     */
Packit a4aae4
    value_kind get_kind() const { return d_value_kind; }
Packit a4aae4
Packit a4aae4
    // This is the call that will be used to return the value of a function.
Packit a4aae4
    // jhrg 3/10/14
Packit a4aae4
    virtual BaseType *value(DMR &dmr);
Packit a4aae4
    // And this optimizes value() for filters, where functions are not supported.
Packit a4aae4
    virtual BaseType *value();
Packit a4aae4
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
#endif // _RValue_h