Debian Codegraph @

src/event_routing_map.cc

raw
1 /*
2 * This file is part of MUSIC.
3 * Copyright (C) 2008, 2009 INCF
4 *
5 * MUSIC is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * MUSIC is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 //#define MUSIC_DEBUG
20 //#include "music/music-config.hh"
21
22 #include "music/event_router.hh"
23 #include "music/event_routing_map.hh"
24
25 namespace MUSIC {
26
27 void
28 OutputRoutingMap::insertRoutingInterval (EventRouter *router, IndexInterval i, FIBO *b)
29 {
30 OutputRoutingData data_ (i, b);
31 router->insertRoutingData (i, data_);
32 }
33
34 OutputRoutingMap::~OutputRoutingMap()
35 {
36 delete intervals;
37 }
38
39 void
40 OutputRoutingMap::insert (IndexInterval i, FIBO* data)
41 {
42 EventRoutingMap<FIBO*>::insert (i, data);
43 intervals->push_back (dataMap[data].back ());
44 }
45
46 void
47 OutputRoutingMap::fillRouter (EventRouter *router)
48 {
49 std::vector<IndexInterval> new_intervals = rebuildIntervals (*intervals);
50 //std::vector<IndexInterval*> new_intervals = *intervals;
51 std::map<FIBO*, std::vector<IndexInterval *> >::iterator pos;
52 for (pos = dataMap.begin (); pos != dataMap.end (); ++pos)
53 {
54 sort (pos->second.begin (), pos->second.end (), comp_obj);
55
56 std::vector<IndexInterval*>::iterator i = pos->second.begin ();
57
58 if (router->needFewPoints ())
59 {
60 // insert intervals without trying to close gaps
61 while (i != pos->second.end ())
62 insertRoutingInterval (router, **i++, pos->first);
63 continue;
64 }
65
66 std::vector<IndexInterval>::iterator mapped = new_intervals.begin ();
67 while (i != pos->second.end ())
68 {
69 IndexInterval current = **i++;
70 while (i != pos->second.end ()
71 && (*i)->local () == current.local ())
72 {
73 // Define the gap between current and next interval
74 int gapBegin = current.end ();
75 int gapEnd = (*i)->begin ();
76
77 // Skip mapped intervals which end before gap
78 while (mapped != new_intervals.end ()
79 && (*mapped).end () <= gapBegin){
80
81 ++mapped;
82 }
83 // Check that gap does not overlap with any mapped interval
84 if (mapped != new_intervals.end () && (*mapped).begin () < gapEnd)
85 break;
86 // Join intervals by closing over gap
87 current.setEnd ((*i)->end ());
88 ++i;
89 }
90 insertRoutingInterval (router, current, pos->first);
91 }
92 }
93 }
94
95
96 void
97 InputRoutingMap::insertRoutingInterval (EventRouter *router,
98 IndexInterval i,
99 EventHandlerPtr *h)
100 {
101 if (h->getType () == Index::GLOBAL)
102 {
103 InputRoutingData<EventHandlerGlobalIndex> data_ (i, h);
104 router->insertRoutingData (i, data_);
105 }
106 else
107 {
108 InputRoutingData<EventHandlerLocalIndex> data_ (i, h);
109 router->insertRoutingData (i, data_);
110 }
111 }
112
113 void InputRoutingMap::fillRouter (EventRouter *router)
114 {
115 std::map<EventHandlerPtr*, std::vector<IndexInterval *> >::iterator pos;
116 for (pos = dataMap.begin (); pos != dataMap.end (); ++pos)
117 {
118 std::vector<IndexInterval > new_intervals = rebuildIntervals (((*pos).second));
119 std::vector<IndexInterval >::iterator i = new_intervals.begin ();
120 while (i != new_intervals.end ())
121 insertRoutingInterval (router, *i++, (*pos).first);
122 }
123 }
124 }