1/* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
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:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
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
19 * THE SOFTWARE.
20 */
21
22#include "model/EventInfo.h"
23
24#include "model/PortInfo.h"
25#include "model/TransitionInfo.h"
26
27namespace DSENT
28{
29    EventInfo::EventInfo(const String& event_name_, const Map<PortInfo*>* port_infos_)
30        : m_event_name_(event_name_)
31    {
32        m_trans_info_map_ = new Map<TransitionInfo>;
33
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)
39        {
40            const String& port_name = it->first;
41            m_trans_info_map_->set(port_name, TransitionInfo());
42        }
43    }
44
45    EventInfo::~EventInfo()
46    {
47        delete m_trans_info_map_;
48    }
49
50    const String& EventInfo::getEventName() const
51    {
52        return m_event_name_;
53    }
54
55    void EventInfo::setTransitionInfo(const String& port_name_, const TransitionInfo& trans_info_)
56    {
57        ASSERT(m_trans_info_map_->keyExist(port_name_), "[Error] " + getEventName() +
58                " -> Port (" + port_name_ + ") does not exist!");
59
60        m_trans_info_map_->set(port_name_, trans_info_);
61        return;
62    }
63
64    void EventInfo::setStaticTransitionInfo(const String& port_name_)
65    {
66        ASSERT(m_trans_info_map_->keyExist(port_name_), "[Error] " + getEventName() +
67                " -> Port (" + port_name_ + ") does not exist!");
68
69        m_trans_info_map_->set(port_name_, TransitionInfo(0.5, 0.0, 0.5));
70        return;
71    }
72
73    void EventInfo::setRandomTransitionInfos()
74    {
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)
79        {
80            TransitionInfo& trans_info = it->second;
81            trans_info = TransitionInfo();
82        }
83        return;
84    }
85
86    void EventInfo::setStaticTransitionInfos()
87    {
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)
92        {
93            TransitionInfo& trans_info = it->second;
94            trans_info = TransitionInfo(0.5, 0.0, 0.5);
95        }
96        return;
97    }
98
99    const TransitionInfo& EventInfo::getTransitionInfo(const String& port_name_) const
100    {
101        ASSERT(m_trans_info_map_->keyExist(port_name_), "[Error] " + getEventName() +
102                " -> Port (" + port_name_ + ") does not exist!");
103
104        return m_trans_info_map_->get(port_name_);
105    }
106} // namespace DSENT
107
108