Question

I am trying to create a simple manager that will map error codes to functions. But since a map copies the values and a signal is noncopyable that is not a solution. I cannot use a map of shared_ptr pointers since the * operator is blocked in boost::function.

Which collection should I use to store this?

typedef boost::function<bool (shared_ptr<EngineEvent> event,long timeSinceEvent)> EngineErrorHandler;
typedef boost::signal<bool (  EngineErrorHandler )> ErrorSignal;
typedef std::map<EventErrorType,ErrorSignal> ErrorHandlers;

class ServiceErrorManager {

    public:
        static ServiceErrorManager* getInstance();

        void registerErrorHandler(EngineErrorHandler& handler,EventErrorType subScribeTo);
        void signalEngineEventfail(shared_ptr<EngineEvent> event);

    private:
        static ServiceErrorManager* m_pInstance;

       ErrorHandlers errorTypeToSignal;

        ServiceErrorManager();
        ~ServiceErrorManager();
    };
}
Was it helpful?

Solution

You could always store everything into a struct and store shared_ptr or unique_ptr objects inside a map or set using a custom predicate. This seems like it would make your code a bit more self-explanatory as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top