Ptr.h
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:3k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. /* $Id: Ptr.h,v 1.1.1.1 2005/11/11 21:32:03 faxguy Exp $ */
  2. /*
  3.  * Copyright (c) 1990-1996 Sam Leffler
  4.  * Copyright (c) 1991-1996 Silicon Graphics, Inc.
  5.  * HylaFAX is a trademark of Silicon Graphics
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software and 
  8.  * its documentation for any purpose is hereby granted without fee, provided
  9.  * that (i) the above copyright notices and this permission notice appear in
  10.  * all copies of the software and related documentation, and (ii) the names of
  11.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  12.  * publicity relating to the software without the specific, prior written
  13.  * permission of Sam Leffler and Silicon Graphics.
  14.  * 
  15.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18.  * 
  19.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  20.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  21.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  23.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  24.  * OF THIS SOFTWARE.
  25.  */
  26. #ifndef _Ptr_
  27. #define _Ptr_
  28. #include "Obj.h"
  29. /******************************
  30.   What the declaration of a fxPtr class looks like to the user:
  31. class fxPtr<T> : public fxPtr<> {
  32.     fxPtr<T>();
  33.     fxPtr<T>(<T>* obj);
  34.     fxPtr<T>(const fxPtr<T>& other);
  35.     ~fxPtr<T>();
  36.     fxPtr<T>& operator=(const fxPtr<T>& other);
  37.     fxPtr<T>& operator=(<T>* obj);
  38.     operator <T>*();
  39.     <T>* operator->();
  40. };
  41. ******************************/
  42. #define fxDECLARE_Ptr(TYPE)
  43. class fxCAT(TYPE,Ptr) {/*XXX*/
  44. protected:
  45.     void destroy() { if (p) p->dec(); }
  46.     TYPE* p;
  47. public:  
  48.     fxCAT(TYPE,Ptr)() { p = 0; }
  49.     fxCAT(TYPE,Ptr)(TYPE *tp) { p = tp ? (tp->inc(),tp) : 0; }
  50.     fxCAT(TYPE,Ptr)(const fxCAT(TYPE,Ptr)& other)
  51. { p = other.p ? (other.p->inc(),other.p) : 0; }
  52.     ~fxCAT(TYPE,Ptr)() { destroy(); }
  53.     fxCAT(TYPE,Ptr)& operator=(const fxCAT(TYPE,Ptr)& other) {
  54. if (p != other.p) {
  55.     destroy(); p = other.p ? (other.p->inc(),other.p) : 0;
  56. }
  57. return *this;
  58.     }
  59.     fxCAT(TYPE,Ptr)& operator=(TYPE* tp) {
  60. if (p != tp) {
  61.     destroy(); p = tp ? (tp->inc(),tp) : 0;
  62. }
  63. return *this;
  64.     }
  65.     int compare(const fxCAT(TYPE,Ptr) *other) const
  66. { return int((char *)p - (char *)other->p); }
  67.     operator TYPE*() { return p; }
  68.     operator const TYPE*() const { return p; }
  69.     TYPE* operator ->() { return p; }
  70.     const TYPE* operator ->() const { return p; }
  71. }
  72. __enddef__
  73. #endif /* _Ptr_ */