Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

SocketAddress.h

00001 #ifndef _EHNET_SocketAddress_H_  // -*-c++-*-
00002 
00003 #ifdef __GNUG__
00004 #pragma interface
00005 #endif
00006 
00007 /*
00008  * Copyright 1991-2002 Eric M. Hopper <hopper@omnifarious.org>
00009  * 
00010  *     This program is free software; you can redistribute it and/or modify it
00011  *     under the terms of the GNU Lesser General Public License as published
00012  *     by the Free Software Foundation; either version 2 of the License, or
00013  *     (at your option) any later version.
00014  * 
00015  *     This program is distributed in the hope that it will be useful, but
00016  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *     Lesser General Public License for more details.
00019  * 
00020  *     You should have received a copy of the GNU Lesser General Public
00021  *     License along with this program; if not, write to the Free Software
00022  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  */
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/EHnet++/EHnet++/SocketAddress.h,v 1.9 2002/11/25 05:40:05 hopper Exp $ */
00026 
00027  // For a log, see ../ChangeLog
00028  //
00029  // Revision 1.4  1996/02/20 01:06:33  hopper
00030  // Added inline definition for ostream &operator << for SocketAddresses.
00031  //
00032  // Revision 1.3  1996/02/12 03:01:55  hopper
00033  // Added links to my ClassIdent system.
00034  //
00035  // Revision 1.2  1996/02/12 00:32:57  hopper
00036  // Fixed to use the new C++ standard library string class instead of all the
00037  // 'NetString' silliness.
00038  //
00039  // Revision 1.1.1.1  1995/07/23 17:45:30  hopper
00040  // Imported sources
00041  //
00042  // Revision 0.1.0.4  1994/08/12  17:07:26  hopper
00043  // Changed to use NetString class. The NetString class handles all library
00044  // dependencies.
00045  //
00046  // Revision 0.1.0.3  1994/06/16  03:00:06  hopper
00047  // Added #pragma interface for GNU stuff.
00048  //
00049  // Revision 0.1.0.2  1994/05/08  18:35:08  hopper
00050  // Changed to work better with Rogue Wave classes.
00051  //
00052  // Revision 0.1.0.1  1994/05/08  18:10:25  hopper
00053  // Head of WinterFire branch. Changed all instances of String with
00054  // RWCString.
00055  //
00056  // Revision 0.1  1994/05/03  03:25:21  hopper
00057  // Initial revision
00058  //
00059 
00060  // $Revision: 1.9 $
00061 
00062 #include <string>
00063 #include <iosfwd>  // ostream
00064 #include <LCore/Protocol.h>
00065 #include <EHnet++/NET_ClassIdent.h>
00066 
00067 #define _EHNET_SocketAddress_H_
00068 
00069 struct sockaddr;
00070 
00071 namespace strmod {
00072 namespace ehnet {
00073 
00074 /** \class SocketAddress SocketAddress.h EHnet++/SocketAddress.h
00075  * C++ class wrapper for struct ::sockaddr from sys/socket.h
00076  *
00077  * This is a C++ wrapper for the sockaddr structure that the connect, and bind
00078  * system calls take.  It includes a virtual 'Copy' method to clone copies when
00079  * you don't know the actual type of the address.
00080  */
00081 class SocketAddress : virtual public lcore::Protocol
00082 {
00083  public:
00084    static const NET_ClassIdent identifier;
00085 
00086    //! An abstract SocketAddress really doesn't have any parameters
00087    SocketAddress()                                      { }
00088    //! No member variables, nothing to do
00089    virtual ~SocketAddress()                             { }
00090 
00091    virtual int AreYouA(const lcore::ClassIdent &cid) const {
00092       return((identifier == cid) || lcore::Protocol::AreYouA(cid));
00093    }
00094 
00095    //! Send a textual representation of the address to the given ostream.
00096    virtual void PrintOn(::std::ostream &);
00097 
00098    //! Get the sockaddr struct  this object is wrapping.
00099    virtual ::sockaddr *SockAddr() = 0;
00100    /** Clone this address, no matter it's actual type
00101     *
00102     * This is a non-virtual for compilers that don't support <A HREF="http://cpptips.hyperformix.com/Covariance.html">contravariance</A>
00103     * in the return types of virtual functions.
00104    */
00105    SocketAddress *Copy() const                          { return(MakeCopy()); }
00106    //! How long is this address in memory?
00107    virtual int AddressSize() const = 0;
00108    //! Fetch a string representation of the SocketAddress
00109    virtual ::std::string AsString() = 0;
00110 
00111  protected:
00112    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00113 
00114    //! Clone this address, no matter it's actual type
00115    virtual SocketAddress *MakeCopy() const = 0;
00116 };
00117 
00118 //-----------------------------inline functions--------------------------------
00119 
00120 inline ::std::ostream &operator <<(::std::ostream &os, SocketAddress &sa)
00121 {
00122    sa.PrintOn(os);
00123    return(os);
00124 }
00125 
00126 } // namespace ehnet
00127 } // namespace strmod
00128 
00129 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1