• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

GSmartPointer.h

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: GSmartPointer.h,v 1.11 2003/11/07 22:08:21 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifndef _GSMARTPOINTER_H_
00058 #define _GSMARTPOINTER_H_
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065 
00093 
00094 #if defined(_MSC_VER)
00095 // Language lawyer say MSVC6 is wrong on that one. 
00096 // Cf section 5.4.7 in november 1997 draft.
00097 #pragma warning( disable : 4243 )
00098 #endif
00099 
00100 #include "DjVuGlobal.h"
00101 
00102 #ifdef HAVE_NAMESPACES
00103 namespace DJVU {
00104 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00105 }
00106 #endif
00107 #endif
00108 
00109 
00110 
00111 /* What is this innovation ? 
00112    What does it do that a GArray does not do ? */
00113 
00114 class GPBufferBase
00115 {
00116 public:
00117   GPBufferBase(void *&,const size_t n,const size_t t);
00118   void swap(GPBufferBase &p);
00119   void resize(const size_t n,const size_t t);
00120   void replace(void *nptr,const size_t n);
00121   void set(const size_t t,const char c);
00122   ~GPBufferBase();
00123   operator int(void) const { return ptr ? num : 0; }
00124 private:
00125   void *&ptr;
00126   size_t num;
00127 };
00128 
00129 template<class TYPE>
00130 class GPBuffer : public GPBufferBase
00131 {
00132 public:
00133   GPBuffer(TYPE *&xptr,const size_t n=0) : GPBufferBase((void *&)xptr,n,sizeof(TYPE)) {}
00134   inline void resize(const size_t n) {GPBufferBase::resize(n,sizeof(TYPE));}
00135   inline void clear(void) {GPBufferBase::set(sizeof(TYPE),0);}
00136   inline void set(const char c) {GPBufferBase::set(sizeof(TYPE),c);}
00137   inline operator int(void) const {return GPBufferBase::operator int();}
00138 };
00139 
00145 class GPEnabled
00146 {
00147 public:
00149   GPEnabled();
00151   GPEnabled(const GPEnabled & obj);
00153   virtual ~GPEnabled();
00155   GPEnabled & operator=(const GPEnabled & obj);
00158   int get_count(void) const;
00159 protected:
00161   volatile int count;
00162 private:
00163   friend class GPBase;
00164   void unref();
00165   void ref();
00166   void destroy();
00167 };
00168 
00169 
00170 
00178 class GPBase
00179 {
00180 public:
00182   GPBase();
00186   GPBase(const GPBase &sptr);
00190   GPBase(GPEnabled *nptr);
00192   ~GPBase();
00194   GPEnabled* get() const;
00198   GPBase& assign(const GPBase &sptr);
00203   GPBase& assign(GPEnabled *nptr);
00205   GPBase & operator=(const GPBase & obj);
00207   int operator==(const GPBase & g2) const;
00208 protected:
00210   GPEnabled *ptr;
00211 };
00212 
00213 
00269 template <class TYPE>
00270 class GP : protected GPBase
00271 {
00272 public:
00274   GP();
00277   GP(const GP<TYPE> &sptr);
00283   GP(TYPE *nptr);
00288   operator TYPE* () const;
00294   GP<TYPE>& operator= (TYPE *nptr);
00297   GP<TYPE>& operator= (const GP<TYPE> &sptr);
00302   TYPE* operator->() const;
00306   TYPE& operator*() const;
00312   int operator== (TYPE *nptr) const;
00318   int operator!= (TYPE *nptr) const;
00327   int operator! () const;
00328 };
00329 
00331 
00332 // INLINE FOR GPENABLED
00333 
00334 inline
00335 GPEnabled::GPEnabled()
00336   : count(0)
00337 {
00338 }
00339 
00340 inline
00341 GPEnabled::GPEnabled(const GPEnabled & obj) 
00342   : count(0) 
00343 {
00344 
00345 }
00346 
00347 inline int
00348 GPEnabled::get_count(void) const
00349 {
00350    return count;
00351 }
00352 
00353 inline GPEnabled & 
00354 GPEnabled::operator=(const GPEnabled & obj)
00355 { 
00356   /* The copy operator should do nothing because the count should not be
00357      changed.  Subclasses of GPEnabled will call this version of the copy
00358      operator as part of the default 'memberwise copy' strategy. */
00359   return *this; 
00360 }
00361 
00362 // INLINE FOR GPBASE
00363 
00364 inline
00365 GPBase::GPBase()
00366   : ptr(0)
00367 {
00368 }
00369 
00370 inline
00371 GPBase::GPBase(GPEnabled *nptr)
00372   : ptr(0)
00373 {
00374   assign(nptr);
00375 }
00376 
00377 inline
00378 GPBase::GPBase(const GPBase &sptr)
00379 {
00380   if (sptr.ptr)
00381     sptr.ptr->ref();
00382   ptr = sptr.ptr;
00383 }
00384 
00385 inline
00386 GPBase::~GPBase()
00387 {
00388   GPEnabled *old = ptr;
00389   ptr = 0;
00390   if (old)
00391     old->unref();
00392 }
00393 
00394 inline GPEnabled* 
00395 GPBase::get() const
00396 {
00397   return ptr;
00398 }
00399 
00400 inline GPBase &
00401 GPBase::operator=(const GPBase & obj)
00402 {
00403   return assign(obj);
00404 }
00405 
00406 inline int 
00407 GPBase::operator==(const GPBase & g2) const
00408 {
00409   return ptr == g2.ptr;
00410 }
00411 
00412 
00413 
00414 
00415 // INLINE FOR GP<TYPE>
00416 
00417 template <class TYPE> inline
00418 GP<TYPE>::GP()
00419 {
00420 }
00421 
00422 template <class TYPE> inline
00423 GP<TYPE>::GP(TYPE *nptr)
00424 : GPBase((GPEnabled*)nptr)
00425 {
00426 }
00427 
00428 template <class TYPE> inline
00429 GP<TYPE>::GP(const GP<TYPE> &sptr)
00430 : GPBase((const GPBase&) sptr)
00431 {
00432 }
00433 
00434 template <class TYPE> inline
00435 GP<TYPE>::operator TYPE* () const
00436 {
00437   return (TYPE*) ptr;
00438 }
00439 
00440 template <class TYPE> inline TYPE*
00441 GP<TYPE>::operator->() const
00442 {
00443   return (TYPE*) ptr;
00444 }
00445 
00446 template <class TYPE> inline TYPE&
00447 GP<TYPE>::operator*() const
00448 {
00449   return *(TYPE*) ptr;
00450 }
00451 
00452 template <class TYPE> inline GP<TYPE>& 
00453 GP<TYPE>::operator= (TYPE *nptr)
00454 {
00455   return (GP<TYPE>&)( assign(nptr) );
00456 }
00457 
00458 template <class TYPE> inline GP<TYPE>& 
00459 GP<TYPE>::operator= (const GP<TYPE> &sptr)
00460 {
00461   return (GP<TYPE>&)( assign((const GPBase&)sptr) );
00462 }
00463 
00464 template <class TYPE> inline int
00465 GP<TYPE>::operator== (TYPE *nptr) const
00466 {
00467   return ( (TYPE*)ptr == nptr );
00468 }
00469 
00470 template <class TYPE> inline int
00471 GP<TYPE>::operator!= (TYPE *nptr) const
00472 {
00473   return ( (TYPE*)ptr != nptr );
00474 }
00475 
00476 template <class TYPE> inline int
00477 GP<TYPE>::operator! () const
00478 {
00479   return !ptr;
00480 }
00481 
00482 
00483 #ifdef HAVE_NAMESPACES
00484 }
00485 # ifndef NOT_USING_DJVU_NAMESPACE
00486 using namespace DJVU;
00487 # endif
00488 #endif
00489 #endif

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal