VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gdescriptor.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gdescriptor.h
19 ///
20 
21 #ifndef G_DESCRIPTOR_H
22 #define G_DESCRIPTOR_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include <iostream>
27 
28 namespace GNet
29 {
30  class Descriptor ;
31 }
32 
33 /// \class GNet::Descriptor
34 /// A class that encapsulates a network file descriptor and hides knowledge
35 /// of its o/s-spefific error value.
36 ///
38 {
39 public:
40  Descriptor() ;
41  ///< Default constructor.
42 
43  explicit Descriptor( SOCKET ) ;
44  ///< Constructor.
45 
46  bool valid() const ;
47  ///< Returns true if the descriptor is valid.
48 
49  static Descriptor invalid() ;
50  ///< Returns an invalid descriptor.
51 
52  SOCKET fd() const ;
53  ///< Returns the low-level descriptor.
54 
55  bool operator==( const Descriptor & other ) const ;
56  ///< Comparison operator.
57 
58  bool operator<( const Descriptor & other ) const ;
59  ///< Comparison operator.
60 
61 private:
62  SOCKET m_fd ;
63 } ;
64 
65 inline
66 SOCKET GNet::Descriptor::fd() const
67 {
68  return m_fd ;
69 }
70 
71 inline
72 bool GNet::Descriptor::operator==( const Descriptor & other ) const
73 {
74  return m_fd == other.m_fd ;
75 }
76 
77 inline
78 bool GNet::Descriptor::operator<( const Descriptor & other ) const
79 {
80  return m_fd < other.m_fd ;
81 }
82 
83 namespace GNet
84 {
85  inline
86  std::ostream & operator<<( std::ostream & stream , const Descriptor & d )
87  {
88  stream << d.fd() ;
89  return stream ;
90  }
91 }
92 
93 #endif
static Descriptor invalid()
Returns an invalid descriptor.
Definition: gdescriptor.cpp:30
bool operator==(const Descriptor &other) const
Comparison operator.
Definition: gdescriptor.h:72
bool operator<(const Descriptor &other) const
Comparison operator.
Definition: gdescriptor.h:78
A class that encapsulates a network file descriptor and hides knowledge of its o/s-spefific error val...
Definition: gdescriptor.h:37
SOCKET fd() const
Returns the low-level descriptor.
Definition: gdescriptor.h:66
Descriptor()
Default constructor.
bool valid() const
Returns true if the descriptor is valid.