OpenASIP  2.0
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
OSEdInformer Class Reference

#include <OSEdInformer.hh>

Collaboration diagram for OSEdInformer:
Collaboration graph

Public Types

enum  EventId { EVENT_REGISTER, EVENT_RESET, EVENT_MEMORY }
 

Public Member Functions

 OSEdInformer ()
 
virtual ~OSEdInformer ()
 
void handleEvent (EventId event)
 
void registerListener (EventId event, OSEdListener *listener)
 
void unregisterListener (EventId event, OSEdListener *listener)
 

Private Types

typedef std::map< EventId, std::vector< OSEdListener * > > ListenerContainer
 Container for mapping event ids to Listener objects. More...
 

Private Member Functions

 OSEdInformer (const OSEdInformer &)
 Copying not allowed. More...
 
OSEdInformeroperator= (const OSEdInformer &)
 Assignment not allowed. More...
 

Private Attributes

ListenerContainer listeners_
 All listeners. More...
 

Detailed Description

Notifies listeners that a certain event has occurred.

Listeners are OSEdListener objects that are interested on events.

Definition at line 47 of file OSEdInformer.hh.

Member Typedef Documentation

◆ ListenerContainer

typedef std::map<EventId, std::vector<OSEdListener*> > OSEdInformer::ListenerContainer
private

Container for mapping event ids to Listener objects.

Definition at line 67 of file OSEdInformer.hh.

Member Enumeration Documentation

◆ EventId

All possible events.

Enumerator
EVENT_REGISTER 

Event when register value might change.

EVENT_RESET 

Event when operation is reseted.

EVENT_MEMORY 

Event when memory may be changed.

Definition at line 52 of file OSEdInformer.hh.

52  {
53  EVENT_REGISTER, ///< Event when register value might change.
54  EVENT_RESET, ///< Event when operation is reseted.
55  EVENT_MEMORY ///< Event when memory may be changed.
56  };

Constructor & Destructor Documentation

◆ OSEdInformer() [1/2]

OSEdInformer::OSEdInformer ( )

Constructor.

Definition at line 41 of file OSEdInformer.cc.

41  {
42 }

◆ ~OSEdInformer()

OSEdInformer::~OSEdInformer ( )
virtual

Destructor.

Definition at line 47 of file OSEdInformer.cc.

47  {
48 }

◆ OSEdInformer() [2/2]

OSEdInformer::OSEdInformer ( const OSEdInformer )
private

Copying not allowed.

Member Function Documentation

◆ handleEvent()

void OSEdInformer::handleEvent ( EventId  event)

Handles event of given id.

If no such id exists, nothing is done.

Parameters
eventEvent to be handled.

Definition at line 58 of file OSEdInformer.cc.

58  {
59  ListenerContainer::iterator iter = listeners_.find(event);
60  if (iter != listeners_.end()) {
61  for (size_t i = 0; i < (*iter).second.size(); i++) {
62  (*iter).second[i]->handleEvent(event);
63  }
64  }
65 }

References listeners_.

Referenced by SimulateDialog::onAdvanceClock(), SimulateDialog::onFormatChanged(), SimulateDialog::onReset(), and SimulateDialog::onTrigger().

◆ operator=()

OSEdInformer& OSEdInformer::operator= ( const OSEdInformer )
private

Assignment not allowed.

◆ registerListener()

void OSEdInformer::registerListener ( EventId  event,
OSEdListener listener 
)

Registers listener to informers data base.

Parameters
eventEvent of which given listener is interested in.
listenerListener to be registered.

Definition at line 74 of file OSEdInformer.cc.

74  {
75  ListenerContainer::iterator iter = listeners_.find(event);
76  if (iter != listeners_.end()) {
77  (*iter).second.push_back(listener);
78  } else {
79  vector<OSEdListener*> newListenerContainer;
80  newListenerContainer.push_back(listener);
81  listeners_[event] = newListenerContainer;
82  }
83 }

References listeners_.

Referenced by MemoryDialog::MemoryDialog(), and SimulateDialog::SimulateDialog().

◆ unregisterListener()

void OSEdInformer::unregisterListener ( EventId  event,
OSEdListener listener 
)

Unregisters listener from the informer.

Parameters
eventEvent for which given listener is registered to listen.
listenerListener to be unregistered.

Definition at line 92 of file OSEdInformer.cc.

92  {
93  ListenerContainer::iterator iter = listeners_.find(event);
94  if (iter != listeners_.end()) {
95  vector<OSEdListener*>::iterator vecIter = (*iter).second.begin();
96  while (vecIter != (*iter).second.end()) {
97  if (*vecIter == listener) {
98  (*iter).second.erase(vecIter);
99  return;
100  }
101  vecIter++;
102  }
103  }
104 }

References listeners_.

Referenced by MemoryDialog::onClose(), SimulateDialog::onClose(), and SimulateDialog::onOK().

Member Data Documentation

◆ listeners_

ListenerContainer OSEdInformer::listeners_
private

All listeners.

Definition at line 75 of file OSEdInformer.hh.

Referenced by handleEvent(), registerListener(), and unregisterListener().


The documentation for this class was generated from the following files:
OSEdInformer::EVENT_REGISTER
@ EVENT_REGISTER
Event when register value might change.
Definition: OSEdInformer.hh:53
OSEdInformer::listeners_
ListenerContainer listeners_
All listeners.
Definition: OSEdInformer.hh:75
OSEdInformer::EVENT_MEMORY
@ EVENT_MEMORY
Event when memory may be changed.
Definition: OSEdInformer.hh:55
OSEdInformer::EVENT_RESET
@ EVENT_RESET
Event when operation is reseted.
Definition: OSEdInformer.hh:54