oaCommonSPtr.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // *****************************************************************************
00003 // oaCommonSPtr.h
00004 //
00005 // This file contains the definitions of the SPtr smart pointer class, the SQPtr
00006 // smart query pointer class and the SRef smart reference class.
00007 //
00008 // SPtr
00009 //      This class is a smart pointer class. It has behavior that is similar to
00010 //      a raw C++ pointer and it manages the reference count of the actual C++
00011 //      pointer. It also has many useful utility functions.
00012 //
00013 // SQPtr
00014 //      This class is an extension of the SPtr smart pointer. The Q stands for 
00015 //      Query Interface, and the smart pointer is responsible for querying for 
00016 //      the proper interface if an interface that isn't of type 'T' is passed 
00017 //      in. This interface must derive from IBase for the query to take place, 
00018 //      otherwise a compile time error will occur.
00019 //
00020 // SRef
00021 //      This class is a smart reference that can be used as a return value to
00022 //      pass referenced interfaces. If used, have your interface function return
00023 //      an SRef<I> by value, where I is the interface you're returning.
00024 //
00025 // *****************************************************************************
00026 // Except as specified in the OpenAccess terms of use of Cadence or Silicon
00027 // Integration Initiative, this material may not be copied, modified,
00028 // re-published, uploaded, executed, or distributed in any way, in any medium,
00029 // in whole or in part, without prior written permission from Cadence.
00030 //
00031 //                Copyright 2002-2005 Cadence Design Systems, Inc.
00032 //                           All Rights Reserved.
00033 //
00034 //  $Author: icftcm $
00035 //  $Revision: #1 $
00036 //  $Date: 2010/08/09 $
00037 //  $State: Exp $
00038 // *****************************************************************************
00039 // *****************************************************************************
00040 
00041 
00042 
00043 #if !defined(oaCommonSPtr_P)
00044 #define oaCommonSPtr_P
00045 
00046 
00047 
00048 // *****************************************************************************
00049 // Nested includes
00050 // *****************************************************************************
00051 #include "oaCommonPlugInBase.h"
00052 
00053 
00054 
00055 // *****************************************************************************
00056 // Declare and define types in the oaCommon namespace
00057 // *****************************************************************************
00058 BEGIN_OA_COMMON_NAMESPACE
00059 
00060 
00061 
00062 // *****************************************************************************
00063 // Forward declarations
00064 // *****************************************************************************
00065 template<class T>
00066 class SRef;
00067 class NString;
00068 
00069 
00070 // *****************************************************************************
00071 // SPtr
00072 // *****************************************************************************
00073 template<class T>
00074 class SPtr {
00075 public:
00076                             SPtr();
00077                             SPtr(T *in);
00078                             SPtr(const char *classID,
00079                                  bool       factory = false);
00080     explicit                SPtr(const SRef<T> &in);
00081                             SPtr(const SPtr<T> &in);
00082 
00083                             ~SPtr();
00084 
00085     void                    release();
00086     void                    createInstance(const char   *classID,
00087                                            IBase        *reserved = NULL);
00088 
00089                             operator T*&() const;
00090     T                       &operator*() const;
00091     T                       *operator->() const;
00092 
00093     T                       *operator=(T *in);
00094     T                       *operator=(const SPtr<T> &in);
00095     T                       *operator=(const SRef<T> &in);
00096     bool                    operator<(const SPtr<T> &in) const;
00097     template<class U>
00098              bool           operator==(const SPtr<U> &in) const;
00099     template<class U>
00100              bool           operator!=(const SPtr<U> &in) const;
00101 
00102     T                       *detach();
00103     T                       *getRef();
00104     T                       *ptr() const;
00105 
00106 protected:
00107     void                    addRef();
00108 
00109     mutable T               *obj;
00110 };
00111 
00112 
00113 
00114 // *****************************************************************************
00115 // SQPtr
00116 // *****************************************************************************
00117 template<class T>
00118 class SQPtr : public SPtr<T> {
00119 public:
00120                             SQPtr();
00121                             SQPtr(T *in);
00122                             SQPtr(const char    *clsid,
00123                                   bool          factory = false);
00124 
00125     explicit                SQPtr(const SPtr<T> &in);
00126     explicit                SQPtr(const SQPtr<T> &in);
00127     explicit                SQPtr(const SRef<T> &in);
00128 
00129     template<class U>
00130              explicit       SQPtr(SPtr<U>   in,
00131                                   bool      successRequired = true);
00132 
00133     template<class U>
00134         explicit            SQPtr(U     *in,
00135                                   bool  successRequired = true);
00136 
00137     template<class U>
00138              explicit       SQPtr(const SRef<U> &in,
00139                                   bool          successRequired = true);
00140 
00141     T                       *operator=(const SQPtr<T> &in);
00142     T                       *operator=(IBase *in);
00143     T                       *operator=(T *in);
00144     T                       *operator=(const SPtr<T> &in);
00145     T                       *operator=(const SRef<T> &in);
00146 };
00147 
00148 
00149 
00150 // *****************************************************************************
00151 // SRef<T>
00152 // *****************************************************************************
00153 template<class T>
00154 class SRef {
00155 public:
00156                             SRef(T *in);
00157                             SRef(const SPtr<T> &in);
00158                             SRef(const SRef<T> &in);
00159                             ~SRef();
00160 
00161     T                       *detach() const;
00162 
00163     T                       *operator=(T *in);
00164                             operator T*();
00165     bool                    operator!() const;
00166 
00167     T                       *operator->() const;
00168 
00169     bool                    operator==(const SRef<T> &other) const;
00170     bool                    operator==(const SPtr<T> &other) const;
00171     bool                    operator!=(const SRef<T> &other) const;
00172     bool                    operator!=(const SPtr<T> &other) const;
00173 
00174 private:
00175     mutable T               *obj;
00176     SRef<T>                 &operator=(const SRef<T> &in);
00177 };
00178 
00179 
00180 
00181 // *****************************************************************************
00182 // SRef<IString>
00183 // *****************************************************************************
00184 template<>
00185 class SRef<IString> {
00186 public:
00187                             SRef(IString *in);
00188                             SRef(const SPtr<IString> &in);
00189                             SRef(const SRef<IString> &in);
00190                             SRef(const NString &in);
00191                             ~SRef();
00192 
00193     IString                 *detach() const;
00194 
00195     IString                 *operator=(IString *in);
00196                             operator IString*();
00197     bool                    operator!() const;
00198 
00199     IString                 *operator->() const;
00200 
00201     bool                    operator==(const SRef<IString> &other) const;
00202     bool                    operator==(const SPtr<IString> &other) const;
00203     bool                    operator!=(const SRef<IString> &other) const;
00204     bool                    operator!=(const SPtr<IString> &other) const;
00205 
00206                             operator const char*() const;
00207 
00208 private:
00209     mutable IString         *obj;
00210     SRef<IString>           &operator=(const SRef<IString> &in);
00211 };
00212 
00213 
00214 
00215 END_OA_COMMON_NAMESPACE
00216 
00217 #endif

Return to top of page