diff options
Diffstat (limited to 'libcmix-common')
| -rw-r--r-- | libcmix-common/receiver.hpp | 58 | ||||
| -rw-r--r-- | libcmix-common/sender.hpp | 62 | ||||
| -rw-r--r-- | libcmix-common/senderreceiver.hpp | 80 |
3 files changed, 74 insertions, 126 deletions
diff --git a/libcmix-common/receiver.hpp b/libcmix-common/receiver.hpp index efd3753..ddb2826 100644 --- a/libcmix-common/receiver.hpp +++ b/libcmix-common/receiver.hpp @@ -7,56 +7,44 @@ /*! * \file */ -struct SenderReceiver; /*! - * \brief The Receiver struct is a shim around ProtobufClient and only exposes things needed - * for receiving messages. + * \brief BaseReceiver */ -struct Receiver : private ProtobufClient<CMixProtoFunctor> +template<template <typename T> class C, typename F> +struct BaseReceiver : private C<CMixProtoFunctor> { /*! * \brief friend decleration allowing Receivers to be upgraded to SenderReceivers. */ - friend SenderReceiver; + friend F; - using ProtobufClient::ProtobufClient; - using ProtobufClient::operator=; + using C<CMixProtoFunctor>::C; + using C<CMixProtoFunctor>::operator=; - using ProtobufClient::async_receive; + using C<CMixProtoFunctor>::async_receive; - using ProtobufClient::async_connect; + using C<CMixProtoFunctor>::async_connect; - using ProtobufClient::close; + using C<CMixProtoFunctor>::close; - using ProtobufClient::on_done; + using C<CMixProtoFunctor>::on_done; - using ProtobufClient::is_open; + using C<CMixProtoFunctor>::is_open; }; -struct SSLSenderReceiver; +/*! + * \brief Forward decleration the ability to convert Receivers to SenderReceivers. + */ +template <template <typename T> class C> +struct BaseSenderReceiver; /*! - * \brief The Receiver struct is a shim around ProtobufClient and only exposes things needed - * for receiving messages. + * \brief Conveniance typedef for Receiver. */ -struct SSLReceiver : private SSLProtobufClient<CMixProtoFunctor> -{ - /*! - * \brief friend decleration allowing Receivers to be upgraded to SenderReceivers. - */ - friend SSLSenderReceiver; - - using SSLProtobufClient::SSLProtobufClient; - using SSLProtobufClient::operator=; - - using SSLProtobufClient::async_receive; - - using SSLProtobufClient::async_connect; - - using SSLProtobufClient::close; - - using SSLProtobufClient::on_done; - - using SSLProtobufClient::is_open; -}; +using Receiver = BaseReceiver<ProtobufClient, BaseSenderReceiver<ProtobufClient>>; + +/*! + * \brief Conveniance typedef for SSLReceiver. + */ +using SSLReceiver = BaseReceiver<SSLProtobufClient, BaseSenderReceiver<SSLProtobufClient>>;
\ No newline at end of file diff --git a/libcmix-common/sender.hpp b/libcmix-common/sender.hpp index c722e30..d1baabe 100644 --- a/libcmix-common/sender.hpp +++ b/libcmix-common/sender.hpp @@ -9,61 +9,43 @@ */ /*! - * \brief forward declaration for SenderReceiver to allow for the friend declaration. + * \brief BaseSender */ -struct SenderReceiver; - -/*! - * \brief The Sender struct is a shim around ProtobufClient and only exposes things needed - * for sending messages. - */ -struct Sender : private ProtobufClient<CMixProtoFunctor> +template<template <typename T> class C, typename F> +struct BaseSender : private C<CMixProtoFunctor> { /*! * The friend declaration that allows for the Sender to be upgraded to a SenderReceiver. */ - friend SenderReceiver; + friend F; - using ProtobufClient::ProtobufClient; - using ProtobufClient::operator=; + using C<CMixProtoFunctor>::C; + using C<CMixProtoFunctor>::operator=; - using ProtobufClient::async_send; + using C<CMixProtoFunctor>::async_send; - using ProtobufClient::async_connect; + using C<CMixProtoFunctor>::async_connect; - using ProtobufClient::close; + using C<CMixProtoFunctor>::close; - using ProtobufClient::on_done; + using C<CMixProtoFunctor>::on_done; - using ProtobufClient::is_open; + using C<CMixProtoFunctor>::is_open; }; /*! - * \brief forward declaration for SenderReceiver to allow for the friend declaration. + * \brief forward declaration for BaseSenderReceiver to allow for the friend declaration. */ -struct SSLSenderReceiver; +template <template <typename T> class C> +struct BaseSenderReceiver; /*! - * \brief The Sender struct is a shim around ProtobufClient and only exposes things needed - * for sending messages. + * \brief Conveniance typedef for Sender */ -struct SSLSender : private SSLProtobufClient<CMixProtoFunctor> -{ - /*! - * The friend declaration that allows for the Sender to be upgraded to a SenderReceiver. - */ - friend SSLSenderReceiver; - - using SSLProtobufClient::SSLProtobufClient; - using SSLProtobufClient::operator=; - - using SSLProtobufClient::async_send; - - using SSLProtobufClient::async_connect; - - using SSLProtobufClient::close; - - using SSLProtobufClient::on_done; - - using SSLProtobufClient::is_open; -}; +using Sender = BaseSender<ProtobufClient, BaseSenderReceiver<ProtobufClient>>; + +/*! + * \brief Conveniance typedef for SSLSender + */ + +using SSLSender = BaseSender<SSLProtobufClient, BaseSenderReceiver<SSLProtobufClient>>;
\ No newline at end of file diff --git a/libcmix-common/senderreceiver.hpp b/libcmix-common/senderreceiver.hpp index 6654809..3514c7e 100644 --- a/libcmix-common/senderreceiver.hpp +++ b/libcmix-common/senderreceiver.hpp @@ -9,76 +9,54 @@ /*! * \file */ - + /*! - * \brief The SenderReciever struct is a shim around ProtobufClient and only exposes things needed - * for Sending and Receiving messages. + * \brief BaseSenderReceiver */ -struct SenderReceiver : private ProtobufClient<CMixProtoFunctor> -{ - /*! +template<template <typename T1> class C> +struct BaseSenderReceiver : private C<CMixProtoFunctor> { +/*! * \brief SenderReceiver Explicit conversion to SenderReceiver * \param r The Receiver to upgrade */ - explicit SenderReceiver(Receiver&& r) - : ProtobufClient(std::move(r)) + explicit BaseSenderReceiver(BaseReceiver<C, BaseSenderReceiver<C>>&& r) + : C<CMixProtoFunctor>(std::move(r)) {} - /*! - * \brief SenderReceiver Explicit conversion to SenderReceiver - * \param s The Sender to upgrade - */ - explicit SenderReceiver(Sender&& s) - : ProtobufClient(std::move(s)) - {} - - using ProtobufClient::ProtobufClient; - using ProtobufClient::operator=; - - using ProtobufClient::async_receive; - - using ProtobufClient::async_send; - - using ProtobufClient::async_connect; - - using ProtobufClient::close; - - using ProtobufClient::on_done; - - using ProtobufClient::is_open; -}; - -struct SSLSenderReceiver : private SSLProtobufClient<CMixProtoFunctor> -{ - /*! - * \brief SenderReceiver Explicit conversion to SenderReceiver - * \param r The Receiver to upgrade - */ - explicit SSLSenderReceiver(SSLReceiver&& r) - : SSLProtobufClient(std::move(r)) - {} /*! * \brief SenderReceiver Explicit conversion to SenderReceiver * \param s The Sender to upgrade */ - explicit SSLSenderReceiver(SSLSender&& s) - : SSLProtobufClient(std::move(s)) + explicit BaseSenderReceiver(BaseSender<C, BaseSenderReceiver<C>> && s) + : C<CMixProtoFunctor>(std::move(s)) {} - using SSLProtobufClient::SSLProtobufClient; - using SSLProtobufClient::operator=; - using SSLProtobufClient::async_receive; + using C<CMixProtoFunctor>::C; + using C<CMixProtoFunctor>::operator=; + + using C<CMixProtoFunctor>::async_receive; - using SSLProtobufClient::async_send; + using C<CMixProtoFunctor>::async_send; - using SSLProtobufClient::async_connect; + using C<CMixProtoFunctor>::async_connect; - using SSLProtobufClient::close; + using C<CMixProtoFunctor>::close; - using SSLProtobufClient::on_done; + using C<CMixProtoFunctor>::on_done; - using SSLProtobufClient::is_open; + using C<CMixProtoFunctor>::is_open; }; +/*! + * \brief Conveniance typedef for SenderReceiver + */ +using SenderReceiver = BaseSenderReceiver<ProtobufClient>; + +/*! + * \brief Conveniance typedef for SSLSenderReceiver + */ + +using SSLSenderReceiver = BaseSenderReceiver<SSLProtobufClient>; + |
