// src/backend/sgpemv2/serializers_gatekeeper.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 SERIALIZERS_GATEKEEPER_HH
#define SERIALIZERS_GATEKEEPER_HH 1

namespace sgpem
{
  class Serializer;
  class SerializersGatekeeper;
}

#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/templates/singleton.hh>

#include <vector>

namespace sgpem
{

  /** \brief Manages instances of Serializer subclasses
   *
   * Normally you will use only the get_registered method, since
   * the Serializer base class automatically registers/unregisters
   * himself when appropriate.
   */
  class SG_DLLEXPORT SerializersGatekeeper : public Singleton<SerializersGatekeeper>
  {
    friend class Singleton<SerializersGatekeeper>;

  public:
    std::vector<Serializer*>     get_registered() const;

    /** \brief Registers a serializer
     * \param serializer The serializer, cannot be nullptr
     */
    void       register_serializer(Serializer* serializer);
    
    /** \brief Unregisters a serializer
     * \param serializer The serializer, cannot be nullptr. If the serializer
     * wasn't previously registered, this method is a no-op.
     */
    void       unregister_serializer(Serializer* serializer);

  private:
    SerializersGatekeeper();     //private constructor.
    SerializersGatekeeper(const SerializersGatekeeper&);
    SerializersGatekeeper& operator=(const SerializersGatekeeper&);

    std::vector<Serializer*>     _registered;
  };

}//~ namespace sgpem

#endif //SERIALIZERS_GATEKEEPER_HH

