home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iptr.inl < prev    next >
Encoding:
Text File  |  1996-02-22  |  6.8 KB  |  339 lines

  1. /**********************************************************************
  2. *                                                                     *
  3. *  IBM(R) VisualAge(TM) for C++ for Windows(R), Version 3.5           *
  4. *                                                                     *
  5. *  PID: 5622-880                                                      *
  6. *  - Licensed Material - Program-Property of IBM                      *
  7. *  (C) Copyright IBM Corp. 1991, 1995 - All Right Reserved.           *
  8. *                                                                     *
  9. *  US Government Users Restricted Rights - Use, duplication or        *
  10. *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  *
  11. *                                                                     *
  12. *  VisualAge, and IBM are trademarks or registered trademarks of      *
  13. *  International Business Machines Corporation.                       *
  14. *  Windows is a registered trademark of Microsoft Corporation.        *
  15. *                                                                     *
  16. **********************************************************************/
  17.  
  18. // ------------
  19. // IElemPointer
  20. // ------------
  21.  
  22. // public members
  23.  
  24. template <class Element>
  25. inline
  26. IElemPointer <Element>::
  27. IElemPointer ()
  28. : ivPtr (0)
  29. {
  30. }
  31.  
  32. template <class Element>
  33. inline
  34. IElemPointer <Element>::
  35. IElemPointer (Element* ptr, IExplicitInit)
  36. : ivPtr (ptr)
  37. {
  38. }
  39.  
  40. template <class Element>
  41. inline Element&
  42. IElemPointer <Element>::
  43. operator* () const
  44. { return *ivPtr;
  45. }
  46.  
  47. template <class Element>
  48. inline Element*
  49. IElemPointer <Element>::
  50. operator-> () const
  51. { return ivPtr;
  52. }
  53.  
  54. template <class Element>
  55. inline
  56. IElemPointer <Element>::
  57. operator Element* () const
  58. { return ivPtr;
  59. }
  60.  
  61. template <class Element>
  62. inline Element&
  63. elementForOps (IElemPointer <Element>& ptr)
  64. { return *ptr.ivPtr;
  65. }
  66.  
  67. template <class Element>
  68. inline Element const&
  69. elementForOps (IElemPointer <Element> const& ptr)
  70. { return *ptr.ivPtr;
  71. }
  72.  
  73. // -----------
  74. // IMngPointer
  75. // -----------
  76.  
  77. // public members
  78.  
  79. template <class Element>
  80. inline
  81. IMngPointer <Element>::
  82. IMngPointer ()
  83. : ivPtrRc (0)
  84. {
  85. }
  86.  
  87. template <class Element>
  88. inline
  89. IMngPointer <Element>::
  90. IMngPointer (Element *ptr, IExplicitInit)
  91. : ivPtrRc (new PtrRc (ptr))
  92. {
  93. }
  94.  
  95. template <class Element>
  96. inline
  97. IMngPointer <Element>::
  98. IMngPointer (IMngPointer <Element> const& ptr)
  99. { ivPtrRc = ptr.ivPtrRc;
  100.   if (ivPtrRc != 0) ivPtrRc->ivRc++;
  101. }
  102.  
  103. template <class Element>
  104. inline
  105. IMngPointer <Element>::
  106. ~IMngPointer ()
  107. { if (ivPtrRc != 0 && --ivPtrRc->ivRc == 0) delete ivPtrRc;
  108. }
  109.  
  110. template <class Element>
  111. inline IMngPointer <Element>&
  112. IMngPointer <Element>::
  113. operator= (IMngPointer <Element> const& ptr)
  114. { if (this != &ptr) {
  115.     if (ivPtrRc && --ivPtrRc->ivRc == 0) delete ivPtrRc;
  116.     ivPtrRc = ptr.ivPtrRc;
  117.     if (ivPtrRc != 0) ivPtrRc->ivRc++;
  118.   }
  119.   return *this;
  120. }
  121.  
  122. template <class Element>
  123. inline Element&
  124. IMngPointer <Element>::
  125. operator* () const
  126. { return *ivPtrRc->ivPtr;
  127. }
  128.  
  129. template <class Element>
  130. inline Element*
  131. IMngPointer <Element>::
  132. operator-> () const
  133. { return ivPtrRc->ivPtr;
  134. }
  135.  
  136. template <class Element>
  137. inline
  138. IMngPointer <Element>::
  139. operator Element* () const
  140. { if (ivPtrRc == 0) return 0;
  141.   else return ivPtrRc->ivPtr;
  142. }
  143.  
  144. // ---------------
  145. // IMngElemPointer
  146. // ---------------
  147.  
  148. // public members
  149.  
  150. template <class Element>
  151. inline
  152. IMngElemPointer <Element>::
  153. IMngElemPointer (Element *ptr, IExplicitInit)
  154. : IMngPointer <Element> (ptr, IINIT)
  155. {
  156. }
  157.  
  158. template <class Element>
  159. inline
  160. IMngElemPointer <Element>::
  161. IMngElemPointer ()
  162. {
  163. }
  164.  
  165. #if defined (ICLCC_COMPAT_PTR)
  166. template <class Element>
  167. inline
  168. IMngElemPointer <Element>::
  169. IMngElemPointer (Element const& e)
  170. : IMngPointer <Element> (new Element (e), IINIT)
  171. {
  172. }
  173.  
  174. template <class Element>
  175. inline
  176. IMngElemPointer <Element>::
  177. IMngElemPointer (Element *ptr)
  178. : IMngPointer <Element> (ptr, IINIT)
  179. {
  180. }
  181. #endif
  182.  
  183. template <class Element>
  184. inline Element&
  185. IMngElemPointer <Element>::
  186. operator* () const
  187. { return IMngPointer <Element>::operator* ();
  188. }
  189.  
  190. template <class Element>
  191. inline Element*
  192. IMngElemPointer <Element>::
  193. operator-> () const
  194. { return IMngPointer <Element>::operator-> ();
  195. }
  196.  
  197. template <class Element>
  198. inline
  199. IMngElemPointer <Element>::
  200. operator Element* () const
  201. { return (IMngPointer <Element> const&)*this;
  202. }
  203.  
  204. template <class Element>
  205. inline Element&
  206. elementForOps (IMngElemPointer <Element>& ptr)
  207. { return *(Element*)ptr;
  208. }
  209.  
  210. template <class Element>
  211. inline Element const&
  212. elementForOps (IMngElemPointer <Element> const& ptr)
  213. { return *(Element*)ptr;
  214. }
  215.  
  216. // ------------
  217. // IAutoPointer
  218. // ------------
  219.  
  220. // public members
  221.  
  222. template <class Element>
  223. inline
  224. IAutoPointer <Element>::
  225. IAutoPointer (Element* ptr, IExplicitInit)
  226. : ivPtr (ptr)
  227. {
  228. }
  229.  
  230. template <class Element>
  231. inline
  232. IAutoPointer <Element>::
  233. IAutoPointer ()
  234. : ivPtr (0)
  235. {
  236. }
  237.  
  238. template <class Element>
  239. inline
  240. IAutoPointer <Element>::
  241. IAutoPointer (IAutoPointer <Element> const& ptr)
  242. { ivPtr = ptr.ivPtr;
  243.   ((IAutoPointer <Element>&)ptr).ivPtr = 0;
  244. }
  245.  
  246. template <class Element>
  247. inline
  248. IAutoPointer <Element>::
  249. ~IAutoPointer ()
  250. { delete ivPtr;
  251. }
  252.  
  253. template <class Element>
  254. inline void
  255. IAutoPointer <Element>::
  256. operator= (IAutoPointer <Element> const& ptr)
  257. { if (this != &ptr) {
  258.     delete ivPtr;
  259.     ivPtr = ptr.ivPtr;
  260.     ((IAutoPointer <Element>&) ptr).ivPtr = 0;
  261.   }
  262. }
  263.  
  264. template <class Element>
  265. inline
  266. IAutoPointer <Element>::
  267. operator Element* () const
  268. { return ivPtr;
  269. }
  270.  
  271. template <class Element>
  272. inline Element&
  273. IAutoPointer <Element>::
  274. operator * () const
  275. { return *ivPtr;
  276. }
  277.  
  278. template <class Element>
  279. inline Element*
  280. IAutoPointer <Element>::
  281. operator-> () const
  282. { return ivPtr;
  283. }
  284.  
  285.  
  286. // ----------------
  287. // IAutoElemPointer
  288. // ----------------
  289.  
  290. // public members
  291.  
  292. template <class Element>
  293. inline
  294. IAutoElemPointer <Element>::
  295. IAutoElemPointer ()
  296. {
  297. }
  298.  
  299. template <class Element>
  300. inline
  301. IAutoElemPointer <Element>::
  302. IAutoElemPointer (Element *ptr, IExplicitInit)
  303. : IAutoPointer <Element> (ptr, IINIT)
  304. {
  305. }
  306.  
  307. template <class Element>
  308. inline Element&
  309. IAutoElemPointer <Element>::
  310. operator* () const
  311. { return IAutoPointer <Element>::operator* ();
  312. }
  313.  
  314. template <class Element>
  315. inline Element*
  316. IAutoElemPointer <Element>::
  317. operator-> () const
  318. { return IAutoPointer <Element>::operator->();
  319. }
  320.  
  321. template <class Element>
  322. inline
  323. IAutoElemPointer <Element>::
  324. operator Element* () const
  325. { return IAutoPointer <Element>::operator Element* ();
  326. }
  327.  
  328. template <class Element>
  329. inline Element&
  330. elementForOps (IAutoElemPointer <Element>& ptr)
  331. { return *(Element*)ptr;
  332. }
  333.  
  334. template <class Element>
  335. inline Element const&
  336. elementForOps (IAutoElemPointer <Element> const& ptr)
  337. { return *(Element*)ptr;
  338. }
  339.