1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#ifndef Topics_h__
#define Topics_h__
#include <set>
#include <assert.h>
#include "ISubject.h"
#include "Filter.h"
#include "SignalConsts.h"
#include "TimerEvents.h"
namespace Publisher{
namespace Signals{
//Forward declarations...
struct ObservableObjects;
template<typename ArgumentType, typename EventTypes>
class ArgEvents;
//Template friend function definition... Gets the internal container to the event vector in Topics<>
namespace friends
{
template <typename T> inline
const typename T::EventContainer& GetEventsContainer(T& subject){
return subject._eventVec;
}
template <typename TE, typename TE_Event> inline
void InsertEvent(TE& subject, TE_Event event_type, const std::string& echo = ""){
subject._eventVec.insert(event_type);
}
}
template<typename ArgumentType, typename EventTypes>
class Topics : public ISubject
{
public:
typedef std::set<EventTypes> EventContainer;
typedef ArgEvents<ArgumentType, EventTypes> ArgEvent;
typedef Observable::SubjectTypes ObserveType;
//ISubject Implementations
Observable::SubjectTypes GetType()const{
return _observableTopic;
}
//Copy constructor
Topics(const Topics& rhs) :
_eventVec (rhs._eventVec),
_observableTopic(rhs._observableTopic),
_pArgEvent (rhs._pArgEvent ? new ArgumentType(*rhs._pArgEvent): 0),
_pFilter (rhs._pFilter ? new Filter(*rhs._pFilter) : 0)
{}
//Constructor that takes the argument type for the Publisher subject e.g. Filter object type
Topics(const ArgumentType& argument_type) :
_eventVec ((argument_type.p_subject)? (argument_type.p_subject->_eventVec) : EventContainer()),
_observableTopic((argument_type.p_subject)? (argument_type.p_subject->_observableTopic) : Observable::ST_Unknown),
_pArgEvent (new ArgumentType(argument_type)),
_pFilter(0)
{}
//Add events of interest...
ArgumentType& RegisterForEvents(){
assert(_pArgEvent);
return *static_cast<ArgumentType *>(_pArgEvent);
}
//Access to the registered events...
const EventContainer& GetRegisteredEvents()const{
return _eventVec;
}
const Publisher::IMDFilter * GetRegisteredFilter()const{
return _pFilter;
}
Topics& operator=(const ArgumentType& argument_type){
//assert(argument_type.p_subject);
if(!argument_type.p_subject)
return *this;
_eventVec = argument_type.p_subject->_eventVec;
_observableTopic = argument_type.p_subject->_observableTopic;
if(_pArgEvent)
delete _pArgEvent;
_pArgEvent = new ArgumentType(argument_type);
_pFilter = 0;
return *this;
}
//Virtual Destructor
virtual ~Topics(){
delete _pFilter;
_pFilter = 0;
delete _pArgEvent;
_pArgEvent = 0;
}
private:
//Constructor that takes the Topic type defined in NotificationConst.h
Topics(ObserveType obsTopic, const Publisher::Filter * pfilter):
_observableTopic(obsTopic),
_pFilter(pfilter ? new Publisher::Filter(*pfilter): 0),
_pArgEvent(0)
{
_pArgEvent = new ArgumentType(*this);
}
Topics(ObserveType obsTopic):
_observableTopic(obsTopic),
_pFilter(0),
_pArgEvent(0)
{
_pArgEvent = new ArgumentType(*this);
}
//members...
Filter * _pFilter; //Here is the first error, This is also the -int assumed errors.
ArgEvent * _pArgEvent;
ObserveType _observableTopic;
EventContainer _eventVec;
//friends...
friend struct ObservableObjects;
template <typename T>
friend const typename T::EventContainer& friends::GetEventsContainer(T& subject);
template <typename TE, typename TE_Event>
friend void friends::InsertEvent(TE& subject, TE_Event event_type, const std::string&);
};
}
}
#endif // Topics_h__
|