libBsdSockets
C++ Wrapper classes to the BSD Socket API
Address.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2013, Komodo Does Inc
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 Neither the name of the Komodo Does Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 
13 */
14 
15 #ifndef ADDRESS_H
16 #define ADDRESS_H
17 
18 #ifndef ADDRESS_INFO_H
19 #include "AddressInfo.h"
20 #endif // ADDRESS_INFO_H
21 
22 namespace BsdSockets {
23 
24  /*
25  * Forward Declarations
26  */
27  class LowLevelAddress;
28 
29  /** \class Address
30  *
31  * \brief Base class for all addresses.
32  *
33  * Provides common information for all types of addresses and a pure-virtual
34  * method to access the LowLevelAddress.
35  */
36  class Address {
37  public:
38  typedef std::shared_ptr<Address> Ptr;
39 
40  /** Virtual destructor to support derived classes */
41  virtual ~Address();
42 
43  protected:
44  /** Create from parameters
45  *
46  * @param theSocketDomain the SocketDomain for the Address
47  * @param theSocketType the SocketType for the Address
48  * @param theProtocol the low-level protocol for the address
49  */
50  Address(SocketDomain theSocketDomain, SocketType theSocketType, int theProtocol);
51 
52  /** Copy from another Address
53  *
54  * @param rhs the Address to copy
55  */
56  Address(const Address& rhs);
57 
58  private:
59  Address(Address&& rhs) = delete;
60  Address& operator=(const Address& rhs) = delete;
61  Address& operator=(Address&& rhs) = delete;
62 
63  public:
64  /** @return the SocketDomain of the Address */
66 
67  /** @return the SocketType of the Address */
68  SocketType getSocketType() const;
69 
70  /** @return the low-level protocol of the Address */
71  int getProtocol() const;
72 
73  public:
74  /** @return a LowLevelAddress suitable for create() */
75  virtual std::shared_ptr<LowLevelAddress> makeTempLowLevelAddress() const = 0;
76 
77  /** Create a new Address from a LowLevelAddress using this Address as a template.
78  *
79  * @param lowLevelAddress data to create from
80  *
81  * @return Address created
82  */
83  virtual Address::Ptr create(std::shared_ptr<LowLevelAddress> lowLevelAddress) const = 0;
84 
85  /** Method for derived classes to provide access to the LowLevelAddress information */
86  virtual const LowLevelAddress& getLowLevelAddress() const = 0;
87 
88  private:
89  /** The SocketDomain of the Address */
90  const SocketDomain socketDomain;
91 
92  /** The SocketType of the Address */
93  const SocketType socketType;
94 
95  /** The low-level protocol of the Address */
96  const int protocol;
97  };
98 
99 } // namespace BsdSockets
100 
101 #endif // ADDRESS_H
Base class for all addresses.
Definition: Address.h:36
virtual std::shared_ptr< LowLevelAddress > makeTempLowLevelAddress() const =0
virtual ~Address()
Definition: Address.cpp:22
int getProtocol() const
Definition: Address.cpp:43
virtual Address::Ptr create(std::shared_ptr< LowLevelAddress > lowLevelAddress) const =0
std::shared_ptr< Address > Ptr
Definition: Address.h:38
SocketDomain getSocketDomain() const
Definition: Address.cpp:35
virtual const LowLevelAddress & getLowLevelAddress() const =0
SocketType getSocketType() const
Definition: Address.cpp:39
Address(SocketDomain theSocketDomain, SocketType theSocketType, int theProtocol)
Definition: Address.cpp:25
Interface for the low-level address implementation.
Namespace of the BsdSockets library.
Definition: Address.cpp:20