[BACK]Return to ServerHostRef.h CVS log [TXT][DIR] Up to [Development] / fam / fam

Annotation of fam/fam/ServerHostRef.h, Revision 1.1.1.1

1.1       trev        1: //  Copyright (C) 1999 Silicon Graphics, Inc.  All Rights Reserved.
                      2: //
                      3: //  This program is free software; you can redistribute it and/or modify it
                      4: //  under the terms of version 2 of the GNU General Public License as
                      5: //  published by the Free Software Foundation.
                      6: //
                      7: //  This program is distributed in the hope that it would be useful, but
                      8: //  WITHOUT ANY WARRANTY; without even the implied warranty of
                      9: //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Further, any
                     10: //  license provided herein, whether implied or otherwise, is limited to
                     11: //  this program in accordance with the express provisions of the GNU
                     12: //  General Public License.  Patent licenses, if any, provided herein do not
                     13: //  apply to combinations of this program with other product or programs, or
                     14: //  any other product whatsoever.  This program is distributed without any
                     15: //  warranty that the program is delivered free of the rightful claim of any
                     16: //  third person by way of infringement or the like.  See the GNU General
                     17: //  Public License for more details.
                     18: //
                     19: //  You should have received a copy of the GNU General Public License along
                     20: //  with this program; if not, write the Free Software Foundation, Inc., 59
                     21: //  Temple Place - Suite 330, Boston MA 02111-1307, USA.
                     22:
                     23: #ifndef ServerHostRef_included
                     24: #define ServerHostRef_included
                     25:
                     26: #include "ServerHost.h"
                     27: #include "StringTable.h"
                     28:
                     29: //  ServerHostRef is a reference-counted pointer to a ServerHost.
                     30: //
                     31: //  A ServerHostRef is created by specifying the name of a
                     32: //  host.  The pointed-to ServerHost will be shared with other
                     33: //  Refs to the same host, even under different names.
                     34:
                     35: class ServerHostRef {
                     36:
                     37: public:
                     38:
                     39:     ServerHostRef()			: p(0) { count++; }
                     40:     ServerHostRef(const char *name)	: p(find(name))
                     41: 					{ p->refcount++; count++; }
                     42:     ServerHostRef(const ServerHostRef& that)
                     43: 					: p(that.p)
                     44: 					{ if (p) p->refcount++; count++; }
                     45:     ServerHostRef& operator = (const ServerHostRef&);
                     46:     ~ServerHostRef();
                     47:
                     48:     ServerHost *operator -> ()		{ assert(p); return p; }
                     49:     const ServerHost *operator -> () const { assert(p); return p; }
                     50:
                     51: private:
                     52:
                     53:     // Instance Variable
                     54:
                     55:     ServerHost *p;
                     56:
                     57:     //  Class Variables
                     58:
                     59:     static unsigned count;		// number of handles extant
                     60:     static StringTable<ServerHost *> *hosts_by_name;
                     61:
                     62:     //  Private Instance Methods
                     63:
                     64:     ServerHostRef(ServerHost& that)	: p(&that) { p->refcount++; count++; }
                     65:
                     66:     //  Private Class Methods
                     67:
                     68:     static ServerHost *find(const char *name);
                     69:
                     70: };
                     71:
                     72: #endif /* !ServerHost_included */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>