/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/

#pragma once

#include "glmBinaryStream.h"
#include "glmAbstractBehavior.h"
#include "glmCloneFactory.h"

namespace glm
{
    // Defines an original Behavior model on which Behaviors instances are patterned
    class GLM_SDK_API BehaviorPrototype
    {
        friend class AbstractBehavior;

    private:
        AbstractBehavior* _prototype;
        mutable unsigned int _instancesCount;

    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation)

        BehaviorPrototype(const AbstractBehavior* prototype = NULL);
        ~BehaviorPrototype();

        inline const AbstractBehavior* getPrototype() const;
        inline AbstractBehavior* createBehavior() const;

    protected:
        GLM_DISALLOW_COPY_AND_ASSIGN(BehaviorPrototype);

        void setPrototype(const AbstractBehavior* behavior);
    };

    //-------------------------------------------------------------------------
    inline const AbstractBehavior* BehaviorPrototype::getPrototype() const
    {
        return _prototype;
    }

    //-------------------------------------------------------------------------
    inline AbstractBehavior* BehaviorPrototype::createBehavior() const
    {
        CloneFactory cloneFactory;
        AbstractBehavior* behavior = cloneFactory.clone(_prototype);
        ++_instancesCount;
        return behavior;
    }
} // namespace glm
