home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iiseqtab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  7.8 KB  |  221 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. #include <new.h>
  19.  
  20. #pragma info (nocls, nocnd, nocns, nocnv, noext, nognr, novft)
  21. #pragma pack (4)
  22.  
  23. // -------------------
  24. // ISequenceAsTableOps
  25. // -------------------
  26.  
  27. // public members
  28.  
  29. template <class Element, class ElementOps, class Implementation>
  30. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  31. ISequenceAsTableOps (INumber numberOfElements)
  32. : Inherited (__isDTSClass (Element)),
  33.   ivElementOps (),
  34.   ivImpl (*this, numberOfElements)
  35. {
  36. }
  37.  
  38. template <class Element, class ElementOps, class Implementation>
  39. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  40. ISequenceAsTableOps (INumber numberOfElements, void* opsArg)
  41. : Inherited (__isDTSClass (Element)),
  42.   ivElementOps (opsArg),
  43.   ivImpl (*this, numberOfElements)
  44. {
  45. }
  46.  
  47. template <class Element, class ElementOps, class Implementation>
  48. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  49. ISequenceAsTableOps
  50.   (ISequenceAsTableOps <Element, ElementOps,
  51.                         Implementation> const& collection)
  52. : Inherited (__isDTSClass (Element)),
  53.   ivElementOps (collection.ivElementOps),
  54.   ivImpl (*this, collection.ivImpl)
  55. {
  56. }
  57.  
  58. template <class Element, class ElementOps, class Implementation>
  59. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  60. ~ISequenceAsTableOps ()
  61. {
  62. }
  63.  
  64. template <class Element, class ElementOps, class Implementation>
  65. void
  66. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  67. Assign (void* element1, void const* element2) const
  68. { ivElementOps.Assign (*(Element*)element1,
  69.                        *(Element const*)element2);
  70. }
  71.  
  72. template <class Element, class ElementOps, class Implementation>
  73. void
  74. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  75. BlockLeft (INumber target, INumber count)
  76. { INumber i = target;
  77.   new (TableOf (ivImpl).NodeAtIndex (i))
  78.     Node (((Node const*) TableOf (ivImpl).
  79.                            NodeAtIndex (i + 1))->ivElement);
  80.   for (i++, count--; count > 0; i++, count--) {
  81.      ivElementOps.Assign
  82.        (((Node*) TableOf (ivImpl).NodeAtIndex (i))->ivElement,
  83.         ((Node const*) TableOf (ivImpl).
  84.                          NodeAtIndex (i + 1))->ivElement);
  85.   }
  86.   ((Node*) TableOf (ivImpl).NodeAtIndex (i))->~Node ();
  87. }
  88.  
  89. template <class Element, class ElementOps, class Implementation>
  90. void
  91. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  92. BlockRight (INumber target, INumber count)
  93. { INumber i = target + count - 1;
  94.   new (TableOf (ivImpl).NodeAtIndex (i))
  95.     Node (((Node const*) TableOf (ivImpl).
  96.                            NodeAtIndex (i - 1))->ivElement);
  97.   for (i--, count--; count > 0; i--, count--) {
  98.      ivElementOps.Assign
  99.        (((Node*) TableOf (ivImpl).NodeAtIndex (i))->ivElement,
  100.         ((Node const*) TableOf (ivImpl).
  101.                          NodeAtIndex (i - 1))->ivElement);
  102.   }
  103.   ((Node*) TableOf (ivImpl).NodeAtIndex (i))->~Node ();
  104. }
  105.  
  106. template <class Element, class ElementOps, class Implementation>
  107. IACollectionImpl*
  108. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  109. Clone () const
  110. { return (Implementation*) *new Self (*this);
  111. }
  112.  
  113. template <class Element, class ElementOps, class Implementation>
  114. void
  115. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  116. CopyFrom (ITableImpl const& from)
  117. { INumber toIndex = TableOf (ivImpl).ivLast;
  118.   INumber fromIndex = from.ivFirst;
  119.   for (INumber i = 0; i < from.ivNumberOfElements; i++) {
  120.     TableOf (ivImpl).IncMod (toIndex);
  121.     new (TableOf (ivImpl).NodeAtIndex (toIndex))
  122.       Node (((Node const*) from.NodeAtIndex (fromIndex))->ivElement);
  123.     from.IncMod (fromIndex);
  124.   }
  125.   TableOf (ivImpl).ivNumberOfElements += from.ivNumberOfElements;
  126.   TableOf (ivImpl).ivLast = toIndex;
  127.  
  128. }
  129.  
  130. template <class Element, class ElementOps, class Implementation>
  131. void
  132. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  133. ConstructNode (void* node, void const* element) const
  134. { new (node) Node (*(Element const*)element);
  135. }
  136.  
  137. template <class Element, class ElementOps, class Implementation>
  138. void*
  139. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  140. CreateNodes (INumber n, size_t& size)
  141. { size = sizeof (Node);
  142.   void* node = ivElementOps.Allocate ((size_t) (size * n)
  143. #if defined (__DEBUG_ALLOC__)
  144.                                       , __FILE__, __LINE__
  145. #endif
  146.                                      );
  147.   return IACollectionImpl::CheckPointer (node);
  148. }
  149.  
  150. template <class Element, class ElementOps, class Implementation>
  151. void
  152. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  153. DeleteNodes (void* nodes)
  154. { ivElementOps.Deallocate (nodes
  155. #if defined (__DEBUG_ALLOC__)
  156.                            , __FILE__, __LINE__
  157. #endif
  158.                           );
  159. }
  160.  
  161. template <class Element, class ElementOps, class Implementation>
  162. void
  163. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  164. DestroyNodes (void* node, INumber count) const
  165. { while (count--)
  166.     ((Node*)node) [count].~Node ();
  167. }
  168.  
  169. template <class Element, class ElementOps, class Implementation>
  170. void*
  171. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  172. StreamIn (TStream& fromWhere) const
  173. { Element* element = ivElementOps.GetStreamable ();
  174.   ivElementOps.StreamIn (*element, fromWhere);
  175.   return (void*) element;
  176. }
  177.  
  178. template <class Element, class ElementOps, class Implementation>
  179. void
  180. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  181. StreamOut (void const* element, TStream& toWhere) const
  182. { ivElementOps.StreamOut (*(Element const*)element, toWhere);
  183. }
  184.  
  185. template <class Element, class ElementOps, class Implementation>
  186. void
  187. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  188. Swap (INumber index1, INumber index2) const
  189. { Element e =
  190.     ((Node*) TableOf (ivImpl).NodeAtIndex (index1))->ivElement;
  191.   ivElementOps.Assign
  192.     (((Node*) TableOf (ivImpl).NodeAtIndex (index1))->ivElement,
  193.      ((Node const*) TableOf (ivImpl).NodeAtIndex (index2))->ivElement);
  194.   ivElementOps.Assign
  195.     (((Node*) TableOf (ivImpl).NodeAtIndex (index2))->ivElement, e);
  196. }
  197.  
  198. template <class Element, class ElementOps, class Implementation>
  199. TStream&
  200. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  201. operator<<= (TStream& fromWhere)
  202. { return (ivElementOps <<= fromWhere);
  203. }
  204.  
  205. template <class Element, class ElementOps, class Implementation>
  206. TStream&
  207. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  208. operator>>= (TStream& toWhere) const
  209. { return (ivElementOps >>= toWhere);
  210. }
  211.  
  212. template <class Element, class ElementOps, class Implementation>
  213. ISequenceAsTableOps <Element, ElementOps, Implementation>::
  214. operator Implementation* ()
  215. { ivImpl.CheckPointer (this);
  216.   return &ivImpl;
  217. }
  218.  
  219. #pragma info (restore)
  220. #pragma pack ()
  221.