/*! * \file registration.hh * \brief Header file for the control port registration functionality. * \author ETSI STF525 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. * \version 0.1 */ #pragma once #include #include /** * \class registration * \brief This class provides a way to register items and its object reference * The registered items are accessible from any object (singleton pattern) * \remark There is one limitation: each item is uniquely defined in the process */ template class registration { // TODO Refine the naming, derive from std::map std::map _items; static registration* _instance; private: registration(): _items() { }; // can not be created manually public: static registration& get_instance(); virtual ~registration() { if (_instance != nullptr) delete _instance; }; public: void add_item(const std::string& type, TItem* f); TItem * get_item(const std::string& type); }; // End of class registration template registration* registration::_instance = nullptr; // static functions template registration& registration::get_instance() { return (_instance != nullptr) ? *_instance : *(_instance = new registration()); } template void registration::add_item(const std::string & type, TItem * f) { _items[type] = f; } template TItem* registration::get_item(const std::string & type) { typename std::map::const_iterator it =_items.find(type); if (it == _items.cend()) { return nullptr; } return it->second; } // End of class registration