home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / xcontact / lib / OkTStructArray.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.1 KB  |  162 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. ///////////////////////////////////////////////////////////////////////////
  18. // OkTStructArray.c++
  19. ///////////////////////////////////////////////////////////////////////////
  20. #include "OkTStructArray.h"
  21.  
  22. template <class Type>
  23. OkTStructArray<Type>::OkTStructArray() :
  24.   OkArray( sizeof( Type ) )
  25. {
  26.   if (data) createElements(data,num);
  27. }
  28.  
  29. template <class Type>
  30. OkTStructArray<Type>::OkTStructArray( OkTStructArray<Type>& a ) :
  31.   OkArray( a.elementsize )
  32. {
  33.   maxi = a.maxi; num = a.num; data = a.raw_copy(); 
  34. }
  35.  
  36. template <class Type>
  37. OkTStructArray<Type>::OkTStructArray( u_int size ) :
  38.   OkArray( sizeof(Type), size )
  39. {
  40.   createElements(data,num); 
  41. }
  42.  
  43. // Protected constructor.
  44. template <class Type>
  45. OkTStructArray<Type>::OkTStructArray(u_int esize, u_int num, void * data) :
  46.   OkArray(esize,num,data) 
  47. {
  48.   // Do nothing.
  49. }
  50.  
  51.  
  52. template <class Type>
  53. OkTStructArray<Type>::~OkTStructArray()
  54. {
  55.   destroy();
  56. }
  57.  
  58.  
  59. template <class Type> OkTStructArray<Type>
  60. OkTStructArray<Type>::cut(u_int start, u_int len)                            
  61. {
  62.   return OkTStructArray<Type>( sizeof(Type), len*sizeof( Type ), 
  63.              raw_cut(start,len) );
  64. }
  65.  
  66. template <class Type> OkTStructArray<Type>
  67. OkTStructArray<Type>::extract(u_int start, u_int len)                            
  68. {
  69.   return OkTStructArray<Type>( sizeof(Type), len*sizeof( Type ), 
  70.              raw_extract(start,len) );
  71. }
  72.  
  73. template <class Type> OkTStructArray<Type>
  74. OkTStructArray<Type>::head(u_int len)                            
  75. {
  76.   return OkTStructArray<Type>( sizeof(Type), len*sizeof( Type ), raw_head(len) );
  77. }
  78.  
  79. template <class Type> OkTStructArray<Type>
  80. OkTStructArray<Type>::tail(u_int len)                            
  81. {
  82.   return OkTStructArray<Type>( sizeof(Type), len*sizeof( Type ), raw_tail(len) );
  83. }
  84.  
  85.  
  86. template <class Type> void 
  87. OkTStructArray<Type>::operator=(OkTStructArray<Type>&a) 
  88. {                
  89.     maxi = a.maxi; num = a.num; if (data) delete (void*)data;    
  90.     data = a.raw_copy(); 
  91. }
  92.  
  93.  
  94. template <class Type> Type&
  95. OkTStructArray<Type>::operator[](u_int index)            
  96.   assert(index>=0 && index*sizeof( Type ) < num);            
  97.   return *(Type *)((char*)((void*)data) + index * sizeof( Type ));
  98.  
  99. template <class Type> void 
  100. OkTStructArray<Type>::append(Type & item) 
  101.   OkArray::append(&item); 
  102. }    
  103.  
  104. template <class Type> void 
  105. OkTStructArray<Type>::append(OkTStructArray<Type> & a) 
  106. {
  107.   OkArray::append(a); 
  108. }        
  109.  
  110. template <class Type> void
  111. OkTStructArray<Type>::remove(u_int start, u_int length)            
  112.   OkArray::remove(start,length); 
  113. }                
  114.  
  115. template <class Type> void
  116. OkTStructArray<Type>::removeAll()                                                
  117.   OkArray::remove(0, OkArray::length()); 
  118. }            
  119.  
  120. template <class Type> void 
  121. OkTStructArray<Type>::insert(OkTStructArray<Type> & a, u_int p)                
  122.   OkArray::insert(a,p);
  123. }                    
  124.  
  125. template <class Type> void 
  126. OkTStructArray<Type>::insert(Type & item, u_int p)                
  127.   OkArray::insert(&item,p);
  128. }                
  129.  
  130. template <class Type> int
  131. OkTStructArray<Type>::find(Type& x, u_int start) 
  132. {            
  133.   return OkArray::find(&x,start);                
  134. }                                
  135.  
  136.  
  137. template <class Type> int 
  138. OkTStructArray<Type>::compareElements(void *o1, void *o2)    
  139. {                                    
  140.   return compareElements( *(Type *)o1, *(Type *)o2 );
  141. }
  142.  
  143. template <class Type> int 
  144. OkTStructArray<Type>::compareElements(Type o1, Type o2)    
  145. {                                    
  146.   return OkArray::compareElements( &o1, &o2 );
  147. }                                    
  148.  
  149. template <class Type> void 
  150. OkTStructArray<Type>::destroyElements(void *start , u_int nbytes )
  151. {                                    
  152.   OkArray::destroyElements( start, nbytes );
  153. }                                    
  154.  
  155.