EventInfo.cc revision 10447:a465576671d4
1#include "model/EventInfo.h"
2
3#include "model/PortInfo.h"
4#include "model/TransitionInfo.h"
5
6namespace DSENT
7{
8    EventInfo::EventInfo(const String& event_name_, const Map<PortInfo*>* port_infos_)
9        : m_event_name_(event_name_)
10    {
11        m_trans_info_map_ = new Map<TransitionInfo>;
12
13        // Get the name of each input port and add a transition info for it
14        Map<PortInfo*>::ConstIterator it_begin = port_infos_->begin();
15        Map<PortInfo*>::ConstIterator it_end = port_infos_->end();
16        Map<PortInfo*>::ConstIterator it;
17        for(it = it_begin; it != it_end; ++it)
18        {
19            const String& port_name = it->first;
20            m_trans_info_map_->set(port_name, TransitionInfo());
21        }
22    }
23
24    EventInfo::~EventInfo()
25    {
26        delete m_trans_info_map_;
27    }
28
29    const String& EventInfo::getEventName() const
30    {
31        return m_event_name_;
32    }
33
34    void EventInfo::setTransitionInfo(const String& port_name_, const TransitionInfo& trans_info_)
35    {
36        ASSERT(m_trans_info_map_->keyExist(port_name_), "[Error] " + getEventName() +
37                " -> Port (" + port_name_ + ") does not exist!");
38
39        m_trans_info_map_->set(port_name_, trans_info_);
40        return;
41    }
42
43    void EventInfo::setStaticTransitionInfo(const String& port_name_)
44    {
45        ASSERT(m_trans_info_map_->keyExist(port_name_), "[Error] " + getEventName() +
46                " -> Port (" + port_name_ + ") does not exist!");
47
48        m_trans_info_map_->set(port_name_, TransitionInfo(0.5, 0.0, 0.5));
49        return;
50    }
51
52    void EventInfo::setRandomTransitionInfos()
53    {
54        Map<TransitionInfo>::Iterator it_begin = m_trans_info_map_->begin();
55        Map<TransitionInfo>::Iterator it_end = m_trans_info_map_->end();
56        Map<TransitionInfo>::Iterator it;
57        for(it = it_begin; it != it_end; ++it)
58        {
59            TransitionInfo& trans_info = it->second;
60            trans_info = TransitionInfo();
61        }
62        return;
63    }
64
65    void EventInfo::setStaticTransitionInfos()
66    {
67        Map<TransitionInfo>::Iterator it_begin = m_trans_info_map_->begin();
68        Map<TransitionInfo>::Iterator it_end = m_trans_info_map_->end();
69        Map<TransitionInfo>::Iterator it;
70        for(it = it_begin; it != it_end; ++it)
71        {
72            TransitionInfo& trans_info = it->second;
73            trans_info = TransitionInfo(0.5, 0.0, 0.5);
74        }
75        return;
76    }
77
78    const TransitionInfo& EventInfo::getTransitionInfo(const String& port_name_) const
79    {
80        ASSERT(m_trans_info_map_->keyExist(port_name_), "[Error] " + getEventName() +
81                " -> Port (" + port_name_ + ") does not exist!");
82
83        return m_trans_info_map_->get(port_name_);
84    }
85} // namespace DSENT
86
87