1 /* Copyright (c) 2012 Massachusetts Institute of Technology
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 #include "model/EventInfo.h"
24 #include "model/PortInfo.h"
25 #include "model/TransitionInfo.h"
29 EventInfo::EventInfo(const String
& event_name_
, const Map
<PortInfo
*>* port_infos_
)
30 : m_event_name_(event_name_
)
32 m_trans_info_map_
= new Map
<TransitionInfo
>;
34 // Get the name of each input port and add a transition info for it
35 Map
<PortInfo
*>::ConstIterator it_begin
= port_infos_
->begin();
36 Map
<PortInfo
*>::ConstIterator it_end
= port_infos_
->end();
37 Map
<PortInfo
*>::ConstIterator it
;
38 for(it
= it_begin
; it
!= it_end
; ++it
)
40 const String
& port_name
= it
->first
;
41 m_trans_info_map_
->set(port_name
, TransitionInfo());
45 EventInfo::~EventInfo()
47 delete m_trans_info_map_
;
50 const String
& EventInfo::getEventName() const
55 void EventInfo::setTransitionInfo(const String
& port_name_
, const TransitionInfo
& trans_info_
)
57 ASSERT(m_trans_info_map_
->keyExist(port_name_
), "[Error] " + getEventName() +
58 " -> Port (" + port_name_
+ ") does not exist!");
60 m_trans_info_map_
->set(port_name_
, trans_info_
);
64 void EventInfo::setStaticTransitionInfo(const String
& port_name_
)
66 ASSERT(m_trans_info_map_
->keyExist(port_name_
), "[Error] " + getEventName() +
67 " -> Port (" + port_name_
+ ") does not exist!");
69 m_trans_info_map_
->set(port_name_
, TransitionInfo(0.5, 0.0, 0.5));
73 void EventInfo::setRandomTransitionInfos()
75 Map
<TransitionInfo
>::Iterator it_begin
= m_trans_info_map_
->begin();
76 Map
<TransitionInfo
>::Iterator it_end
= m_trans_info_map_
->end();
77 Map
<TransitionInfo
>::Iterator it
;
78 for(it
= it_begin
; it
!= it_end
; ++it
)
80 TransitionInfo
& trans_info
= it
->second
;
81 trans_info
= TransitionInfo();
86 void EventInfo::setStaticTransitionInfos()
88 Map
<TransitionInfo
>::Iterator it_begin
= m_trans_info_map_
->begin();
89 Map
<TransitionInfo
>::Iterator it_end
= m_trans_info_map_
->end();
90 Map
<TransitionInfo
>::Iterator it
;
91 for(it
= it_begin
; it
!= it_end
; ++it
)
93 TransitionInfo
& trans_info
= it
->second
;
94 trans_info
= TransitionInfo(0.5, 0.0, 0.5);
99 const TransitionInfo
& EventInfo::getTransitionInfo(const String
& port_name_
) const
101 ASSERT(m_trans_info_map_
->keyExist(port_name_
), "[Error] " + getEventName() +
102 " -> Port (" + port_name_
+ ") does not exist!");
104 return m_trans_info_map_
->get(port_name_
);