| [e2e035e] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * Channels.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Dec 1, 2011 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [9b8fa4] | 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [e2e035e] | 21 |  | 
|---|
| [9b8fa4] | 22 | #include "CodePatterns/Assert.hpp" | 
|---|
| [e2e035e] | 23 |  | 
|---|
| [9b8fa4] | 24 | #include "CodePatterns/Observer/Channels.hpp" | 
|---|
|  | 25 | #include "CodePatterns/Observer/Notification.hpp" | 
|---|
| [e2e035e] | 26 |  | 
|---|
|  | 27 |  | 
|---|
|  | 28 | Channels::Channels() | 
|---|
|  | 29 | {} | 
|---|
|  | 30 |  | 
|---|
|  | 31 | Channels::~Channels() | 
|---|
|  | 32 | { | 
|---|
|  | 33 | // free all present Notifications | 
|---|
|  | 34 | for(NotificationTypetoRefMap::iterator iter = ChannelMap.begin(); | 
|---|
|  | 35 | !ChannelMap.empty(); iter = ChannelMap.begin()) { | 
|---|
| [1c291d] | 36 | removeChannel(iter->first); | 
|---|
| [e2e035e] | 37 | } | 
|---|
|  | 38 | } | 
|---|
|  | 39 |  | 
|---|
|  | 40 | void Channels::addChannel(size_t no) | 
|---|
|  | 41 | { | 
|---|
| [454bc54] | 42 | #ifndef NDEBUG | 
|---|
| [e2e035e] | 43 | NotificationTypetoRefMap::const_iterator iter = ChannelMap.find(no); | 
|---|
|  | 44 | ASSERT(iter == ChannelMap.end(), | 
|---|
|  | 45 | "Channels::addChannel() - channel "+toString(int(no))+" is already present in ChannelMap."); | 
|---|
| [1c291d] | 46 | #endif | 
|---|
| [e2e035e] | 47 | ChannelMap.insert( std::make_pair(no, new Notification(no)) ); | 
|---|
|  | 48 | } | 
|---|
|  | 49 |  | 
|---|
|  | 50 | void Channels::removeChannel(size_t no) | 
|---|
|  | 51 | { | 
|---|
|  | 52 | NotificationTypetoRefMap::iterator iter = ChannelMap.find(no); | 
|---|
|  | 53 | ASSERT(iter != ChannelMap.end(), | 
|---|
|  | 54 | "Channels::removeChannel() - channel "+toString(int(no))+" not present in ChannelMap."); | 
|---|
|  | 55 | delete iter->second; | 
|---|
|  | 56 | ChannelMap.erase(iter); | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
| [1c291d] | 59 | void Channels::subjectKilled(Observable * const publisher) | 
|---|
|  | 60 | { | 
|---|
|  | 61 | for(NotificationTypetoRefMap::iterator iter = ChannelMap.begin(); | 
|---|
|  | 62 | iter != ChannelMap.end();++iter) { | 
|---|
|  | 63 | iter->second->subjectKilled(publisher); | 
|---|
|  | 64 | } | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
| [e2e035e] | 67 | Notification_ptr Channels::getChannel(size_t no) const | 
|---|
|  | 68 | { | 
|---|
|  | 69 | NotificationTypetoRefMap::const_iterator iter = ChannelMap.find(no); | 
|---|
|  | 70 | ASSERT(iter != ChannelMap.end(), | 
|---|
|  | 71 | "Channels::getChannel() - channel "+toString(int(no))+" not present in ChannelMap."); | 
|---|
|  | 72 | return iter->second; | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | size_t Channels::getType(Notification_ptr channel) const | 
|---|
|  | 76 | { | 
|---|
|  | 77 | return channel->getChannelNo(); | 
|---|
|  | 78 | } | 
|---|
|  | 79 |  | 
|---|