1 /*!
2 	@file
3 	@author		Albert Semenov
4 	@date		08/2008
5 */
6 #ifndef CONNECTION_RECEIVER_H_
7 #define CONNECTION_RECEIVER_H_
8 
9 #include "IAnimationNode.h"
10 #include "IAnimationGraph.h"
11 
12 namespace animation
13 {
14 
15 	class ConnectionReceiver
16 	{
17 	public:
ConnectionReceiver()18 		ConnectionReceiver()
19 		{
20 		}
21 
~ConnectionReceiver()22 		~ConnectionReceiver()
23 		{
24 		}
25 
addConnection(const std::string & _eventout,IAnimationNode * _node,const std::string & _eventin)26 		void addConnection(const std::string& _eventout, IAnimationNode* _node, const std::string& _eventin)
27 		{
28 			mConnections.push_back(PairOut(_eventout, PairIn(_node, _eventin)));
29 		}
30 
removeConnection(const std::string & _eventout,IAnimationNode * _node,const std::string & _eventin)31 		void removeConnection(const std::string& _eventout, IAnimationNode* _node, const std::string& _eventin)
32 		{
33 			for (VectorPairOut::iterator item = mConnections.begin(); item != mConnections.end(); ++item)
34 			{
35 				if (_eventout == item->first
36 					&& _node == item->second.first
37 					&& _eventin == item->second.second)
38 				{
39 					mConnections.erase(item);
40 					return;
41 				}
42 			}
43 			assert(!"connection not found");
44 		}
45 
46 		void forceEvent(const std::string& _name, float _value = 0)
47 		{
48 			for (VectorPairOut::iterator item = mConnections.begin(); item != mConnections.end(); ++item)
49 			{
50 				if (_name == item->first)
51 					item->second.first->setEvent(item->second.second, _value);
52 			}
53 		}
54 
55 	private:
56 		typedef std::pair<IAnimationNode*, std::string> PairIn;
57 		typedef std::pair<std::string, PairIn> PairOut;
58 		typedef std::vector<PairOut> VectorPairOut;
59 		VectorPairOut mConnections;
60 
61 	};
62 
63 } // namespace animation
64 
65 #endif // CONNECTION_RECEIVER_H_
66