Realistic 3D camera system
3D camera system components
datagram_protocol.hpp
Go to the documentation of this file.
1 //
2 // generic/datagram_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_DATAGRAM_PROTOCOL_HPP
12 #define ASIO_GENERIC_DATAGRAM_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>
25 
27 
28 namespace asio {
29 namespace generic {
30 
32 
50 {
51 public:
53  datagram_protocol(int address_family, int socket_protocol)
54  : family_(address_family),
55  protocol_(socket_protocol)
56  {
57  }
58 
60 
63  template <typename Protocol>
64  datagram_protocol(const Protocol& source_protocol)
65  : family_(source_protocol.family()),
66  protocol_(source_protocol.protocol())
67  {
68  if (source_protocol.type() != type())
69  {
70  std::bad_cast ex;
72  }
73  }
74 
76  int type() const
77  {
78  return ASIO_OS_DEF(SOCK_DGRAM);
79  }
80 
82  int protocol() const
83  {
84  return protocol_;
85  }
86 
88  int family() const
89  {
90  return family_;
91  }
92 
94  friend bool operator==(const datagram_protocol& p1,
95  const datagram_protocol& p2)
96  {
97  return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
98  }
99 
101  friend bool operator!=(const datagram_protocol& p1,
102  const datagram_protocol& p2)
103  {
104  return !(p1 == p2);
105  }
106 
109 
112 
113 private:
114  int family_;
115  int protocol_;
116 };
117 
118 } // namespace generic
119 } // namespace asio
120 
122 
123 #endif // ASIO_GENERIC_DATAGRAM_PROTOCOL_HPP
Encapsulates the flags needed for a generic datagram-oriented socket.
friend bool operator!=(const datagram_protocol &p1, const datagram_protocol &p2)
Compare two protocols for inequality.
#define ASIO_OS_DEF(c)
datagram_protocol(int address_family, int socket_protocol)
Construct a protocol object for a specific address family and protocol.
Provides datagram-oriented socket functionality.
friend bool operator==(const datagram_protocol &p1, const datagram_protocol &p2)
Compare two protocols for equality.
datagram_protocol(const Protocol &source_protocol)
Construct a generic protocol object from a specific protocol.
basic_endpoint< datagram_protocol > endpoint
The type of an endpoint.
int type() const
Obtain an identifier for the type of the protocol.
int family() const
Obtain an identifier for the protocol family.
int protocol() const
Obtain an identifier for the protocol.
basic_datagram_socket< datagram_protocol > socket
The generic socket type.
void throw_exception(const Exception &e)
Describes an endpoint for any socket type.