00001 // ***************************************************************************** 00002 // ***************************************************************************** 00003 // oaCommonPlugInBase.h 00004 // 00005 // This file contains implementations for the plug-in base interface classes. 00006 // This implementation may be used by the interface user or implementation. 00007 // These objects are used to pass information through the interface. 00008 // 00009 // The following classes are supported: 00010 // 00011 // NString 00012 // This class is a string that implement the IString interface, but 00013 // contains no reference count. It's intended to be used as a class member 00014 // to allow an inernal string to be passed back as an IString, without 00015 // worrying about a "release" call causing a crash in the "delete" code. 00016 // 00017 // StringImp 00018 // This is a class that can be used by plug-ins to implement the IString 00019 // interface - which is used to pass strings through interfaces when the 00020 // lifetime of the string needs to be managed past the lifetime of the 00021 // function call. 00022 // 00023 // ***************************************************************************** 00024 // Except as specified in the OpenAccess terms of use of Cadence or Silicon 00025 // Integration Initiative, this material may not be copied, modified, 00026 // re-published, uploaded, executed, or distributed in any way, in any medium, 00027 // in whole or in part, without prior written permission from Cadence. 00028 // 00029 // Copyright 2002-2005 Cadence Design Systems, Inc. 00030 // All Rights Reserved. 00031 // 00032 // $Author: icftcm $ 00033 // $Revision: #1 $ 00034 // $Date: 2010/08/09 $ 00035 // $State: Exp $ 00036 // ***************************************************************************** 00037 // ***************************************************************************** 00038 00039 00040 00041 #if !defined(oaCommonPlugInBase_P) 00042 #define oaCommonPlugInBase_P 00043 00044 00045 00046 // ***************************************************************************** 00047 // Nested includes 00048 // ***************************************************************************** 00049 #include "oaCommonIBase.h" 00050 #include <string> 00051 00052 00053 00054 // ***************************************************************************** 00055 // Declare and define types in the oaCommon namespace 00056 // ***************************************************************************** 00057 BEGIN_OA_COMMON_NAMESPACE 00058 00059 00060 00061 // ***************************************************************************** 00062 // PlugInBase 00063 // ***************************************************************************** 00064 template<class I = IBase> 00065 class PlugInBase : public I { 00066 public: 00067 typedef I Type; 00068 00069 PlugInBase(unsigned long refIn = 0); 00070 virtual inline ~PlugInBase(); 00071 00072 virtual long queryInterface(const Guid &id, 00073 void **iPtr); 00074 virtual unsigned long addRef(); 00075 virtual unsigned long release(); 00076 00077 protected: 00078 unsigned long ref; 00079 }; 00080 00081 00082 00083 // ***************************************************************************** 00084 // NString 00085 // ***************************************************************************** 00086 class OA_COMMON_DLL_API NString { 00087 public: 00088 NString(const char *in = NULL); 00089 NString(const NString &str); 00090 ~NString(); 00091 00092 operator const char*() const; 00093 NString &operator=(const char *str); 00094 NString &operator=(const NString &str); 00095 00096 oa::oaUInt4 length() const; 00097 00098 protected: 00099 struct StrBuff { 00100 oa::oaUInt2 refCount; 00101 oa::oaUInt2 length; 00102 char buffer[1]; 00103 }; 00104 00105 StrBuff *value; 00106 00107 private: 00108 void clear(); 00109 00110 static StrBuff *dup(const char *str); 00111 static StrBuff *dup(StrBuff *str); 00112 }; 00113 00114 00115 00116 // ***************************************************************************** 00117 // StringImp 00118 // ***************************************************************************** 00119 class OA_COMMON_DLL_API StringImp : public IString, public NString { 00120 public: 00121 StringImp(const char *in); 00122 StringImp(const NString &str); 00123 00124 virtual unsigned long addRef(); 00125 virtual unsigned long release(); 00126 virtual long queryInterface(const Guid &id, 00127 void **iPtr); 00128 virtual inline const char *str(); 00129 00130 private: 00131 unsigned long refCount; 00132 }; 00133 00134 00135 00136 // ***************************************************************************** 00137 // StaticString 00138 // ***************************************************************************** 00139 class OA_COMMON_DLL_API StaticString : public PlugInBase<IString> { 00140 public: 00141 StaticString(const char *in); 00142 00143 virtual inline const char *str(); 00144 00145 private: 00146 const char *val; 00147 }; 00148 00149 00150 00151 // ***************************************************************************** 00152 // StlIString 00153 // ***************************************************************************** 00154 class StlIString : public PlugInBase<IString> { 00155 public: 00156 StlIString(const std::string &str); 00157 00158 virtual inline const char *str(); 00159 00160 private: 00161 std::string val; 00162 }; 00163 00164 00165 00166 // ***************************************************************************** 00167 // ExceptionBase 00168 // ***************************************************************************** 00169 class ExceptionBase : public IException { 00170 public: 00171 ExceptionBase(oa::oaUInt4 idIn, 00172 const char *msgIn); 00173 00174 virtual inline oa::oaUInt4 getMsgId() const; 00175 virtual inline const char *getMsg() const; 00176 00177 private: 00178 oa::oaUInt4 id; 00179 NString msg; 00180 }; 00181 00182 00183 00184 // ***************************************************************************** 00185 // ArrayIter 00186 // ***************************************************************************** 00187 template<class I, class T> 00188 class ArrayIter : public PlugInBase<I> { 00189 public: 00190 ArrayIter(oa::oaInt4 initialCap = 0); 00191 virtual ~ArrayIter(); 00192 00193 virtual bool next(typename I::Type &objOut); 00194 virtual void reset(); 00195 00196 void add(const T &elem); 00197 00198 private: 00199 void addReference(IBase *obj); 00200 void addReference(...); 00201 00202 T *array; 00203 oa::oaInt4 size; 00204 oa::oaInt4 capacity; 00205 oa::oaInt4 current; 00206 }; 00207 00208 00209 00210 // ***************************************************************************** 00211 // IDTester 00212 // ***************************************************************************** 00213 template<class I> 00214 class IDTester { 00215 public: 00216 static bool test(const Guid &id); 00217 }; 00218 00219 template<> 00220 class IDTester<IBase> { 00221 public: 00222 static bool test(const Guid &id); 00223 }; 00224 00225 00226 00227 END_OA_COMMON_NAMESPACE 00228 00229 #endif
Copyright © 2002 - 2010 Cadence Design Systems, Inc.
All Rights Reserved.