Added overloads of bsp_connect() and bsp_listen() that can pass

optional arguments to the worker function.
This commit is contained in:
Davis King 2012-10-06 13:54:34 -04:00
parent a17ec67643
commit 91481a4411

View File

@ -246,6 +246,8 @@ namespace dlib
const unsigned long _node_id; const unsigned long _node_id;
array<scoped_ptr<thread_function> > threads; array<scoped_ptr<thread_function> > threads;
// -----------------------------------
template < template <
typename funct_type typename funct_type
> >
@ -254,6 +256,44 @@ namespace dlib
const std::vector<std::pair<std::string,unsigned short> >& hosts const std::vector<std::pair<std::string,unsigned short> >& hosts
); );
template <
typename funct_type,
typename ARG1
>
friend void bsp_connect (
funct_type& funct,
ARG1 arg1,
const std::vector<std::pair<std::string,unsigned short> >& hosts
);
template <
typename funct_type,
typename ARG1,
typename ARG2
>
friend void bsp_connect (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
const std::vector<std::pair<std::string,unsigned short> >& hosts
);
template <
typename funct_type,
typename ARG1,
typename ARG2,
typename ARG3
>
friend void bsp_connect (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
ARG3 arg3,
const std::vector<std::pair<std::string,unsigned short> >& hosts
);
// -----------------------------------
template < template <
typename funct_type typename funct_type
> >
@ -262,8 +302,48 @@ namespace dlib
unsigned short listening_port unsigned short listening_port
); );
template <
typename funct_type,
typename ARG1
>
friend void bsp_listen (
funct_type& funct,
ARG1 arg1,
unsigned short listening_port
);
template <
typename funct_type,
typename ARG1,
typename ARG2
>
friend void bsp_listen (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
unsigned short listening_port
);
template <
typename funct_type,
typename ARG1,
typename ARG2,
typename ARG3
>
friend void bsp_listen (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
ARG3 arg3,
unsigned short listening_port
);
// -----------------------------------
}; };
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
@ -277,15 +357,83 @@ namespace dlib
impl::map_id_to_con cons; impl::map_id_to_con cons;
const unsigned long node_id = 0; const unsigned long node_id = 0;
connect_all(cons, hosts, node_id); connect_all(cons, hosts, node_id);
send_out_connection_orders(cons, hosts); send_out_connection_orders(cons, hosts);
bsp obj(node_id, cons); bsp obj(node_id, cons);
funct(obj); funct(obj);
obj.check_for_errors(); obj.check_for_errors();
} }
// ----------------------------------------------------------------------------------------
template <
typename funct_type,
typename ARG1
>
void bsp_connect (
funct_type& funct,
ARG1 arg1,
const std::vector<std::pair<std::string,unsigned short> >& hosts
)
{
impl::map_id_to_con cons;
const unsigned long node_id = 0;
connect_all(cons, hosts, node_id);
send_out_connection_orders(cons, hosts);
bsp obj(node_id, cons);
funct(obj,arg1);
obj.check_for_errors();
}
// ----------------------------------------------------------------------------------------
template <
typename funct_type,
typename ARG1,
typename ARG2
>
void bsp_connect (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
const std::vector<std::pair<std::string,unsigned short> >& hosts
)
{
impl::map_id_to_con cons;
const unsigned long node_id = 0;
connect_all(cons, hosts, node_id);
send_out_connection_orders(cons, hosts);
bsp obj(node_id, cons);
funct(obj,arg1,arg2);
obj.check_for_errors();
}
// ----------------------------------------------------------------------------------------
template <
typename funct_type,
typename ARG1,
typename ARG2,
typename ARG3
>
void bsp_connect (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
ARG3 arg3,
const std::vector<std::pair<std::string,unsigned short> >& hosts
)
{
impl::map_id_to_con cons;
const unsigned long node_id = 0;
connect_all(cons, hosts, node_id);
send_out_connection_orders(cons, hosts);
bsp obj(node_id, cons);
funct(obj,arg1,arg2,arg3);
obj.check_for_errors();
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
@ -299,13 +447,79 @@ namespace dlib
impl::map_id_to_con cons; impl::map_id_to_con cons;
unsigned long node_id; unsigned long node_id;
listen_and_connect_all(node_id, cons, listening_port); listen_and_connect_all(node_id, cons, listening_port);
bsp obj(node_id, cons); bsp obj(node_id, cons);
funct(obj); funct(obj);
obj.check_for_errors(); obj.check_for_errors();
} }
// ----------------------------------------------------------------------------------------
template <
typename funct_type,
typename ARG1
>
void bsp_listen (
funct_type& funct,
ARG1 arg1,
unsigned short listening_port
)
{
impl::map_id_to_con cons;
unsigned long node_id;
listen_and_connect_all(node_id, cons, listening_port);
bsp obj(node_id, cons);
funct(obj,arg1);
obj.check_for_errors();
}
// ----------------------------------------------------------------------------------------
template <
typename funct_type,
typename ARG1,
typename ARG2
>
void bsp_listen (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
unsigned short listening_port
)
{
impl::map_id_to_con cons;
unsigned long node_id;
listen_and_connect_all(node_id, cons, listening_port);
bsp obj(node_id, cons);
funct(obj,arg1,arg2);
obj.check_for_errors();
}
// ----------------------------------------------------------------------------------------
template <
typename funct_type,
typename ARG1,
typename ARG2,
typename ARG3
>
void bsp_listen (
funct_type& funct,
ARG1 arg1,
ARG2 arg2,
ARG3 arg3,
unsigned short listening_port
)
{
impl::map_id_to_con cons;
unsigned long node_id;
listen_and_connect_all(node_id, cons, listening_port);
bsp obj(node_id, cons);
funct(obj,arg1,arg2,arg3);
obj.check_for_errors();
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }