PixelLightAPI  .
SocketAddress.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SocketAddress.h                                *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_NETWORK_SOCKETADDRESS_H__
00024 #define __PLCORE_NETWORK_SOCKETADDRESS_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Socket address class encapsulating an IP/internet address
00046 */
00047 class SocketAddress {
00048 
00049 
00050     //[-------------------------------------------------------]
00051     //[ Friends                                               ]
00052     //[-------------------------------------------------------]
00053     friend class Socket;
00054 
00055 
00056     //[-------------------------------------------------------]
00057     //[ Public functions                                      ]
00058     //[-------------------------------------------------------]
00059     public:
00060         /**
00061         *  @brief
00062         *    Constructor
00063         */
00064         PLCORE_API SocketAddress();
00065 
00066         /**
00067         *  @brief
00068         *    Constructor
00069         *
00070         *  @param[in] nPort
00071         *    Number of the port to use
00072         */
00073         PLCORE_API SocketAddress(uint32 nPort);
00074 
00075         /**
00076         *  @brief
00077         *    Copy constructor
00078         *
00079         *  @param[in] cSource
00080         *    Socket address to copy from
00081         */
00082         PLCORE_API SocketAddress(const SocketAddress &cSource);
00083 
00084         /**
00085         *  @brief
00086         *    Constructor
00087         *
00088         *  @param[in] sAddress
00089         *    Host address
00090         *  @param[in] nPort
00091         *    Number of the port to use
00092         */
00093         PLCORE_API SocketAddress(const String &sAddress, uint32 nPort);
00094 
00095         /**
00096         *  @brief
00097         *    Destructor
00098         */
00099         PLCORE_API ~SocketAddress();
00100 
00101         /**
00102         *  @brief
00103         *    Returns the host address
00104         *
00105         *  @return
00106         *    The host address
00107         */
00108         PLCORE_API String GetHost() const;
00109 
00110         /**
00111         *  @brief
00112         *    Sets the host address
00113         *
00114         *  @param[in] sAddress
00115         *    New host address (if empty, set to any host address)
00116         */
00117         PLCORE_API void SetHost(const String &sAddress);
00118 
00119         /**
00120         *  @brief
00121         *    Sets the host address by using the name of the host
00122         *
00123         *  @param[in] sHostName
00124         *    Name of the host
00125         *
00126         *  @return
00127         *    'true' if all went fine, else 'false'
00128         */
00129         PLCORE_API bool SetHostByName(const String &sHostName);
00130 
00131         /**
00132         *  @brief
00133         *    Returns the host port number
00134         *
00135         *  @return
00136         *    The host port number
00137         */
00138         PLCORE_API uint32 GetPort() const;
00139 
00140         /**
00141         *  @brief
00142         *    Sets the host port number
00143         *
00144         *  @param[in] nPort
00145         *    Number of the port to use
00146         *
00147         *  @return
00148         *    'true' if all went fine, else 'false'
00149         */
00150         PLCORE_API bool SetPort(uint32 nPort);
00151 
00152         /**
00153         *  @brief
00154         *    Copy operator
00155         *
00156         *  @param[in] cSource
00157         *    Socket address to copy from
00158         *
00159         *  @return
00160         *    Reference to this socket address
00161         */
00162         PLCORE_API SocketAddress &operator =(const SocketAddress &cSource);
00163 
00164         /**
00165         *  @brief
00166         *    Compare operator
00167         *
00168         *  @param[in] cSource
00169         *    Socket address to compare with
00170         *
00171         *  @return
00172         *    'true' if both socket addresses are equal, else 'false'
00173         */
00174         PLCORE_API bool operator ==(const SocketAddress &cSource) const;
00175 
00176         /**
00177         *  @brief
00178         *    Compare operator
00179         *
00180         *  @param[in] cSource
00181         *    Socket address to compare with
00182         *
00183         *  @return
00184         *    'true' if both socket addresses are not equal, else 'false'
00185         */
00186         PLCORE_API bool operator !=(const SocketAddress &cSource) const;
00187 
00188 
00189     //[-------------------------------------------------------]
00190     //[ Private data                                          ]
00191     //[-------------------------------------------------------]
00192     private:
00193         struct sockaddr_in *m_pSockAddress; /**< Socket address (always valid!) */
00194 
00195 
00196 };
00197 
00198 
00199 //[-------------------------------------------------------]
00200 //[ Namespace                                             ]
00201 //[-------------------------------------------------------]
00202 } // PLCore
00203 
00204 
00205 #endif // __PLCORE_NETWORK_SOCKETADDRESS_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:00
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported