/* osgCompute - Copyright (C) 2008-2009 SVT Group
 *                                                                     
 * 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 3 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 Lesse General Public License for more details.
 *
 * The full license is in LICENSE file included with this distribution.
*/

#ifndef OSGCOMPUTE_PARAM
#define OSGCOMPUTE_PARAM 1

#include <vector>
#include <map>
#include <osg/ref_ptr>
#include <osg/Object>
#include "osgCompute/Export"
#include "osgCompute/Context"
#include "osgCompute/Callback"

namespace osgCompute
{
    /**
    */
    class LIBRARY_EXPORT Param : public ContextResource
    {
    public:
        Param() : ContextResource() { clearLocal(); }

        virtual bool init(); 
        virtual void clear();
        inline bool isDirty() const;

        virtual bool isConstant() { return false; }
        virtual bool isBuffer() { return false; }
        virtual unsigned int getByteSize() const = 0;

        inline void setSubloadCallback( SubloadCallback* sc );
        inline SubloadCallback* getSubloadCallback();
        inline const SubloadCallback* getSubloadCallback() const;
        inline void setUpdateCallback( UpdateCallback* uc );
        inline UpdateCallback* getUpdateCallback();
        inline const UpdateCallback* getUpdateCallback() const;
        inline void setEventCallback( EventCallback* ec );
        inline EventCallback* getEventCallback();
        inline const EventCallback* getEventCallback() const;

    protected:
        virtual ~Param() { clearLocal(); }
        void clearLocal();

        virtual bool init( const Context& context ) const;
        virtual void clear( const Context& context ) const;

        osg::ref_ptr<SubloadCallback>       _subloadCallback;
        osg::ref_ptr<UpdateCallback>        _updateCallback;
        osg::ref_ptr<EventCallback>         _eventCallback;
        bool                                _dirty;

    private:
        // copy constructor and operator should not be called
        Param( const Param&, const osg::CopyOp& ) {}
        Param& operator=( const Param& ) { return (*this); }
    };

    /////////////////////////////////////////////////////////////////////////////////////////////////
    // PUBLIC FUNCTIONS /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////
    //------------------------------------------------------------------------------
    inline void Param::setSubloadCallback( SubloadCallback* sc ) 
    { 
        _subloadCallback = sc; 
    }

    //------------------------------------------------------------------------------
    inline SubloadCallback* Param::getSubloadCallback() 
    { 
        return _subloadCallback.get(); 
    }

    //------------------------------------------------------------------------------
    inline const SubloadCallback* Param::getSubloadCallback() const 
    { 
        return _subloadCallback.get(); 
    }

    //------------------------------------------------------------------------------
    inline void Param::setUpdateCallback( UpdateCallback* uc ) 
    { 
        _updateCallback = uc; 
    }

    //------------------------------------------------------------------------------
    inline UpdateCallback* Param::getUpdateCallback() 
    { 
        return _updateCallback.get(); 
    }

    //------------------------------------------------------------------------------
    inline const UpdateCallback* Param::getUpdateCallback() const 
    { 
        return _updateCallback.get(); 
    }

    //------------------------------------------------------------------------------
    inline void Param::setEventCallback( EventCallback* ec ) 
    { 
        _eventCallback = ec; 
    }

    //------------------------------------------------------------------------------
    inline EventCallback* Param::getEventCallback() 
    { 
        return _eventCallback.get(); 
    }

    //------------------------------------------------------------------------------
    inline const EventCallback* Param::getEventCallback() const 
    { 
        return _eventCallback.get(); 
    }

    //------------------------------------------------------------------------------
    inline bool Param::isDirty() const 
    { 
        return _dirty; 
    }
}

#endif //OSGCOMPUTE_PARAM
