// src/backend/dynamic_resource.hh - Copyright 2005, 2006, University
//               of Padova, dept. of Pure and Applied
//               Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// SGPEMv2 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.


#ifndef DYNAMIC_RESOURCE_HH
#define DYNAMIC_RESOURCE_HH 1

#include "glibmm/ustring.h"

#include <sgpemv2/resource.hh>
#include "static_resource.hh"

#include <memory>

namespace sgpem
{


  /// \brief Desribes the state of a resource entity in a particular moment
  /// of the simulation.
  ///
  /// Contains part of the information used by the scheduling policies to
  /// perform scheduling.
  /// DynamicResource objects may be created by the system
  /// via the Scheduler.step_forward() method (which then inserts them into a
  /// ::ConcreteEnvironment), or by the user on a resetted ::History by creating
  /// one of them anew.
  ///
  /// Actually this class does not provide any information to the system, nor it
  /// does play any particular role. It is here for the puropose of extensibility
  /// and beauty in general.
  ///
  /// These objects may be destroyed only by resetting an ::History, or via one
  /// of its methods.
  class DynamicResource;
  class SerializeVisitor;

  class SG_DLLLOCAL DynamicResource : public Resource
  {
  public:
    DynamicResource(StaticResource *core);

    virtual bool operator==(const Resource& op2) const;

    /// \brief Returns the name of the Resource.
    ///
    /// Returns the name of the Resource.
    /// \return the name of the Resource.
    Glib::ustring get_name() const;

    /// \brief Returns the number of places of the Resource.
    ///
    /// Returns the number of places of the Resource.
    /// \return the number of places of the Resource.
    unsigned int get_places() const;


    /// \brief Serializes this object via the provided translator.
    ///
    /// Calls translator->from_resource(this).
    void serialize(SerializeVisitor& translator) const;

    /// \brief Returns a reference to the static resource object.
    ///
    /// This function returns a reference to the actual schedable object
    /// represented, along with its status, by this instance.
    StaticResource& get_core();

    /// \brief Returns a constant reference to the static schedulable object.
    ///
    /// This function returns a constant reference to the actual schedable object
    /// represented, along with its status, by this instance.
    const StaticResource& get_core() const;

  private:
    std::shared_ptr<StaticResource> _static_resource;
  };

}

#endif

