Skip to content

Commit

Permalink
Improve socket operator= with vector and array support.
Browse files Browse the repository at this point in the history
  • Loading branch information
kouchy committed Jun 8, 2021
1 parent 87215f5 commit c68f71c
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 218 deletions.
12 changes: 12 additions & 0 deletions include/Module/Socket.hpp
Expand Up @@ -68,6 +68,18 @@ class Socket : public tools::Interface_reset

inline void operator()(Socket &s_out, const int priority = -1);

template <typename T>
inline void operator=(const T *array);

template <typename T>
inline void operator=(T *array);

template <typename T, class A = std::allocator<T>>
inline void operator=(const std::vector<T,A> &vector);

template <typename T, class A = std::allocator<T>>
inline void operator=(std::vector<T,A> &vector);

inline void operator=(Socket &s);

inline void operator=(Task &t);
Expand Down
80 changes: 80 additions & 0 deletions include/Module/Socket.hxx
Expand Up @@ -236,6 +236,86 @@ void Socket
bind(s_out, priority);
}

template <typename T>
void Socket
::operator=(const T *array)
{
if (this->get_type() == socket_t::SIN)
this->bind(array);
else
{
std::stringstream message;
message << "Current socket have to be an input socket ("
<< "'datatype'" << " = " << type_to_string[this->datatype] << ", "
<< "'name'" << " = " << get_name() << ", "
<< "'task.name'" << " = " << task.get_name() << ", "
<< "'type'" << " = " << (get_type() == socket_t::SIN ? "SIN" : "SOUT") /*<< ", "*/
// << "'task.module.name'" << " = " << task.get_module_name()
<< ").";
throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
}
}

template <typename T>
void Socket
::operator=(T *array)
{
if (this->get_type() == socket_t::SIN)
this->bind(array);
else
{
std::stringstream message;
message << "Current socket have to be an input socket ("
<< "'datatype'" << " = " << type_to_string[this->datatype] << ", "
<< "'name'" << " = " << get_name() << ", "
<< "'task.name'" << " = " << task.get_name() << ", "
<< "'type'" << " = " << (get_type() == socket_t::SIN ? "SIN" : "SOUT") /*<< ", "*/
// << "'task.module.name'" << " = " << task.get_module_name()
<< ").";
throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
}
}

template <typename T, class A>
void Socket
::operator=(const std::vector<T,A> &vector)
{
if (this->get_type() == socket_t::SIN)
this->bind(vector);
else
{
std::stringstream message;
message << "Current socket have to be an input socket ("
<< "'datatype'" << " = " << type_to_string[this->datatype] << ", "
<< "'name'" << " = " << get_name() << ", "
<< "'task.name'" << " = " << task.get_name() << ", "
<< "'type'" << " = " << (get_type() == socket_t::SIN ? "SIN" : "SOUT") /*<< ", "*/
// << "'task.module.name'" << " = " << task.get_module_name()
<< ").";
throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
}
}

template <typename T, class A>
void Socket
::operator=(std::vector<T,A> &vector)
{
if (this->get_type() == socket_t::SIN)
this->bind(vector);
else
{
std::stringstream message;
message << "Current socket have to be an input socket ("
<< "'datatype'" << " = " << type_to_string[this->datatype] << ", "
<< "'name'" << " = " << get_name() << ", "
<< "'task.name'" << " = " << task.get_name() << ", "
<< "'type'" << " = " << (get_type() == socket_t::SIN ? "SIN" : "SOUT") /*<< ", "*/
// << "'task.module.name'" << " = " << task.get_module_name()
<< ").";
throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
}
}

void Socket
::operator=(Socket &s)
{
Expand Down

0 comments on commit c68f71c

Please sign in to comment.