Realistic 3D camera system
3D camera system components
stream_protocol.hpp
Go to the documentation of this file.
1 //
2 // generic/stream_protocol.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_GENERIC_STREAM_PROTOCOL_HPP
12 #define ASIO_GENERIC_STREAM_PROTOCOL_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #include <typeinfo>
26 
28 
29 namespace asio {
30 namespace generic {
31 
33 
51 {
52 public:
54  stream_protocol(int address_family, int socket_protocol)
55  : family_(address_family),
56  protocol_(socket_protocol)
57  {
58  }
59 
61 
64  template <typename Protocol>
65  stream_protocol(const Protocol& source_protocol)
66  : family_(source_protocol.family()),
67  protocol_(source_protocol.protocol())
68  {
69  if (source_protocol.type() != type())
70  {
71  std::bad_cast ex;
73  }
74  }
75 
77  int type() const
78  {
79  return ASIO_OS_DEF(SOCK_STREAM);
80  }
81 
83  int protocol() const
84  {
85  return protocol_;
86  }
87 
89  int family() const
90  {
91  return family_;
92  }
93 
95  friend bool operator==(const stream_protocol& p1, const stream_protocol& p2)
96  {
97  return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
98  }
99 
101  friend bool operator!=(const stream_protocol& p1, const stream_protocol& p2)
102  {
103  return !(p1 == p2);
104  }
105 
108 
111 
112 #if !defined(ASIO_NO_IOSTREAM)
115 #endif // !defined(ASIO_NO_IOSTREAM)
116 
117 private:
118  int family_;
119  int protocol_;
120 };
121 
122 } // namespace generic
123 } // namespace asio
124 
126 
127 #endif // ASIO_GENERIC_STREAM_PROTOCOL_HPP
friend bool operator!=(const stream_protocol &p1, const stream_protocol &p2)
Compare two protocols for inequality.
Iostream interface for a socket.
#define ASIO_OS_DEF(c)
Provides stream-oriented socket functionality.
basic_socket_iostream< stream_protocol > iostream
The generic socket iostream type.
int type() const
Obtain an identifier for the type of the protocol.
stream_protocol(const Protocol &source_protocol)
Construct a generic protocol object from a specific protocol.
friend bool operator==(const stream_protocol &p1, const stream_protocol &p2)
Compare two protocols for equality.
stream_protocol(int address_family, int socket_protocol)
Construct a protocol object for a specific address family and protocol.
int family() const
Obtain an identifier for the protocol family.
basic_stream_socket< stream_protocol > socket
The generic socket type.
Encapsulates the flags needed for a generic stream-oriented socket.
int protocol() const
Obtain an identifier for the protocol.
void throw_exception(const Exception &e)
Describes an endpoint for any socket type.
basic_endpoint< stream_protocol > endpoint
The type of an endpoint.