add original source
This commit is contained in:
56
source/listing_3.12.cpp
Normal file
56
source/listing_3.12.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <mutex>
|
||||
|
||||
struct connection_info
|
||||
{};
|
||||
|
||||
struct data_packet
|
||||
{};
|
||||
|
||||
struct connection_handle
|
||||
{
|
||||
void send_data(data_packet const&)
|
||||
{}
|
||||
data_packet receive_data()
|
||||
{
|
||||
return data_packet();
|
||||
}
|
||||
};
|
||||
|
||||
struct remote_connection_manager
|
||||
{
|
||||
connection_handle open(connection_info const&)
|
||||
{
|
||||
return connection_handle();
|
||||
}
|
||||
} connection_manager;
|
||||
|
||||
|
||||
class X
|
||||
{
|
||||
private:
|
||||
connection_info connection_details;
|
||||
connection_handle connection;
|
||||
std::once_flag connection_init_flag;
|
||||
|
||||
void open_connection()
|
||||
{
|
||||
connection=connection_manager.open(connection_details);
|
||||
}
|
||||
public:
|
||||
X(connection_info const& connection_details_):
|
||||
connection_details(connection_details_)
|
||||
{}
|
||||
void send_data(data_packet const& data)
|
||||
{
|
||||
std::call_once(connection_init_flag,&X::open_connection,this);
|
||||
connection.send_data(data);
|
||||
}
|
||||
data_packet receive_data()
|
||||
{
|
||||
std::call_once(connection_init_flag,&X::open_connection,this);
|
||||
return connection.receive_data();
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{}
|
||||
Reference in New Issue
Block a user