View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

module_impl.h
Go to the documentation of this file.
1#ifndef MODULE_IMPL_H
2#define MODULE_IMPL_H
3
6#include <cassert>
7
8namespace vistle {
9
10template<class Type>
11typename Type::const_ptr PortTask::accept(const Port *port)
12{
13 auto it = m_input.find(port);
14 if (it == m_input.end())
15 return nullptr;
16 auto obj = it->second;
17 if (!obj) {
18 std::stringstream str;
19 str << "did not receive valid object at " << port->getName() << std::endl;
20 m_module->sendWarning(str.str());
21 return nullptr;
22 }
23 assert(obj->check());
24 auto ret = Type::as(obj);
25 if (ret)
26 m_input.erase(it);
27 return ret;
28}
29template<class Type>
30typename Type::const_ptr PortTask::accept(const std::string &port)
31{
32 auto it = m_portsByString.find(port);
33 if (it == m_portsByString.end())
34 return nullptr;
35 return accept<Type>(it->second);
36}
37
38template<class Type>
39typename Type::const_ptr PortTask::expect(const Port *port)
40{
41 auto it = m_input.find(port);
42 assert(it != m_input.end());
43 if (it == m_input.end()) {
44 if (m_module->schedulingPolicy() == message::SchedulingPolicy::Single) {
45 std::stringstream str;
46 str << "no object available at " << port->getName() << ", but " << Type::typeName() << " is required"
47 << std::endl;
48 m_module->sendError(str.str());
49 }
50 return nullptr;
51 }
52 auto obj = it->second;
53 m_input.erase(it);
54 if (!obj) {
55 std::stringstream str;
56 str << "did not receive valid object at " << port->getName() << std::endl;
57 m_module->sendWarning(str.str());
58 return nullptr;
59 }
60 assert(obj->check());
61 return Type::as(obj);
62}
63template<class Type>
64typename Type::const_ptr PortTask::expect(const std::string &port)
65{
66 auto it = m_portsByString.find(port);
67 assert(it != m_portsByString.end());
68 return expect<Type>(it->second);
69}
70
71template<class Type>
72typename Type::const_ptr Module::accept(Port *port)
73{
75 if (port->objects().empty()) {
76 return nullptr;
77 }
78 obj = port->objects().front();
79 if (!obj) {
80 port->objects().pop_front();
81 std::stringstream str;
82 str << "did not receive valid object at " << port->getName() << std::endl;
83 sendWarning(str.str());
84 return nullptr;
85 }
86 assert(obj->check());
87 typename Type::const_ptr ret = Type::as(obj);
88 if (ret)
89 port->objects().pop_front();
90 return ret;
91}
92template<class Type>
93typename Type::const_ptr Module::accept(const std::string &port)
94{
95 Port *p = findInputPort(port);
96 assert(p);
97 return accept<Type>(p);
98}
99
100template<class Type>
101typename Type::const_ptr Module::expect(Port *port)
102{
103 if (!port) {
104 std::stringstream str;
105 str << "invalid port" << std::endl;
106 sendError(str.str());
107 return nullptr;
108 }
109 if (port->objects().empty()) {
110 if (schedulingPolicy() == message::SchedulingPolicy::Single) {
111 std::stringstream str;
112 str << "no object available at " << port->getName() << ", but " << Type::typeName() << " is required"
113 << std::endl;
114 sendError(str.str());
115 }
116 return nullptr;
117 }
118 Object::const_ptr obj = port->objects().front();
119 typename Type::const_ptr ret = Type::as(obj);
120 port->objects().pop_front();
121 if (!obj) {
122 std::stringstream str;
123 str << "did not receive valid object at " << port->getName() << ", but " << Type::typeName() << " is required"
124 << std::endl;
125 sendError(str.str());
126 return ret;
127 }
128 assert(obj->check());
129 if (!ret) {
130 std::stringstream str;
131 str << "received " << Object::toString(obj->getType()) << " at " << port->getName() << ", but "
132 << Type::typeName() << " is required" << std::endl;
133 sendError(str.str());
134 }
135 return ret;
136}
137template<class Type>
138typename Type::const_ptr Module::expect(const std::string &port)
139{
140 Port *p = findInputPort(port);
141 assert(p);
142 return expect<Type>(p);
143}
144
145
146} // namespace vistle
147#endif
Type::const_ptr expect(Port *port)
Definition: module_impl.h:101
Type::const_ptr accept(Port *port)
Definition: module_impl.h:72
void sendWarning(const char *fmt,...) const
send warning message to UI - printf style
Definition: module.cpp:2108
int schedulingPolicy() const
Definition: module.cpp:988
void sendError(const char *fmt,...) const
send error message to UI - printf style
Definition: module.cpp:2124
std::shared_ptr< const Object > const_ptr
Definition: object.h:68
static const char * toString(Type v)
Definition: object.cpp:80
Module * m_module
Definition: module.h:104
Type::const_ptr accept(const Port *port)
Definition: module_impl.h:11
std::map< const Port *, Object::const_ptr > m_input
Definition: module.h:105
std::map< std::string, Port * > m_portsByString
Definition: module.h:107
Type::const_ptr expect(const Port *port)
Definition: module_impl.h:39
Definition: port.h:29
const std::string & getName() const
Definition: port.cpp:25
ObjectList & objects()
Definition: port.cpp:40
Definition: allobjects.cpp:30