home *** CD-ROM | disk | FTP | other *** search
/ ftp.funduc.com / 2014.08.ftp.funduc.com.tar / ftp.funduc.com / fshedcode-072212.zip / Simparr.cpp < prev    next >
Text File  |  2010-09-09  |  18KB  |  722 lines

  1. //=========================================================
  2. // File: simparr.cpp
  3.  
  4. //-------------------------------------------------------------------
  5. template<class T> SimpleArray<T>::SimpleArray()
  6. {
  7.     m_pT = NULL;
  8.     m_nSize = 0;
  9.     m_nUpperBound = ARR_EMPTY;
  10.     m_nGrowBy = 1;
  11. }
  12.  
  13. //-------------------------------------------------------------------
  14. template<class T> SimpleArray<T>::SimpleArray(int nNewSize, int nGrowBy)
  15. : m_nGrowBy(nGrowBy), m_nUpperBound(ARR_EMPTY), m_nSize(nNewSize)
  16. {
  17.     m_pT = new T[m_nSize];
  18. }
  19.  
  20. //-------------------------------------------------------------------
  21. template<class T> SimpleArray<T>::SimpleArray(T* ptArray, int upbound, int size)
  22. : m_nGrowBy(1), m_pT(ptArray), m_nUpperBound(upbound), m_nSize(size)
  23. {
  24. #ifdef _DEBUG
  25.     if(m_pT == NULL || m_nUpperBound<0 || m_nSize<=0 || m_nUpperBound >= m_nSize)
  26.     {
  27.         m_nSize = 0;
  28.         m_nUpperBound = ARR_EMPTY;
  29.     }
  30. #endif
  31. }
  32.  
  33. //-------------------------------------------------------------------
  34. template<class T> SimpleArray<T>::SimpleArray(SimpleArray& spaArg)
  35.     : m_nSize(spaArg.m_nSize), m_nUpperBound(spaArg.m_nUpperBound),
  36.     m_nGrowBy(spaArg.m_nGrowBy)
  37. {
  38.     m_pT = new T[m_nSize];
  39.     int k;
  40.     for(k = 0; k <= m_nUpperBound; k++)
  41.         m_pT[k] = spaArg.m_pT[k];
  42. }
  43.  
  44. //-------------------------------------------------------------------
  45. template<class T> SimpleArray<T>::~SimpleArray()
  46. {
  47.     if(m_pT != NULL) delete [] m_pT;
  48. }
  49.  
  50. //-------------------------------------------------------------------
  51. template<class T> int SimpleArray<T>::InsertAtGrow(int nIndex, T argT, int nCount)
  52. {
  53.     if(nIndex<0 || nCount<1)
  54.         return FALSE;
  55.     int i;
  56.     if(nIndex > m_nUpperBound)
  57.     {
  58.         for(i = 0; i < nCount; i++)
  59.             SetAtGrow(nIndex + i, argT);
  60.         return TRUE;
  61.     }
  62.     else
  63.     {
  64.         if(m_nSize < m_nUpperBound + 1 + nCount)
  65.         {
  66.             if (AddSpace(nCount) == FALSE)
  67.                 return FALSE;
  68.         }
  69.         for(i = m_nUpperBound + nCount; i > nIndex; i--)
  70.         {
  71.             m_pT[i] = m_pT[i-nCount];
  72.         }
  73.         for(i = 0; i < nCount; i++)
  74.             m_pT[nIndex + i] = argT;
  75.         m_nUpperBound += nCount;
  76.         return TRUE;
  77.     }
  78. }
  79.  
  80. //-------------------------------------------------------------------
  81. template<class T> int SimpleArray<T>::InsertAtGrow (int nIndex, T* pT, int nSrcIndex, int nCount)
  82. {
  83.     if(nIndex<0 || nCount<1)
  84.         return FALSE;
  85.     int i;
  86.     if(nIndex > m_nUpperBound)
  87.     {
  88.         for(i = 0; i < nCount; i++)
  89.         {
  90.             if (SetAtGrowRef(nIndex + i, pT[nSrcIndex+i]) == FALSE)
  91.                 return FALSE;
  92.         }
  93.         return TRUE;
  94.     }
  95.     else
  96.     {
  97.         if(m_nSize < m_nUpperBound + 1 + nCount)
  98.         {
  99.             if (AddSpace(nCount) == FALSE)
  100.                 return FALSE;
  101.         }
  102.         for(i = m_nUpperBound + nCount; i > nIndex; i--)
  103.         {
  104.             m_pT[i] = m_pT[i-nCount];
  105.         }
  106.         for(i = 0; i < nCount; i++)
  107.             m_pT[nIndex + i] = pT[nSrcIndex+i];
  108.         m_nUpperBound += nCount;
  109.         return TRUE;
  110.     }
  111. }
  112.  
  113. //-------------------------------------------------------------------
  114. template<class T> void SimpleArray<T>::InsertAtGrowRef(int nIndex, T& argT, int nCount)
  115. {
  116.     if(nIndex<0 || nCount<1) return;
  117.     int i;
  118.     if(nIndex > m_nUpperBound)
  119.     {
  120.         for(i = 0; i < nCount; i++)
  121.             SetAtGrowRef(nIndex + i, argT);
  122.         return;
  123.     }
  124.     else
  125.     {
  126.         if(m_nSize < m_nUpperBound + 1 + nCount)
  127.             AddSpace(nCount);
  128.         for(i = m_nUpperBound + nCount; i > nIndex; i--)
  129.         {
  130.             m_pT[i] = m_pT[i-nCount];
  131.         }
  132.         for(i = 0; i < nCount; i++)
  133.             m_pT[nIndex + i] = argT;
  134.         m_nUpperBound += nCount;
  135.     }
  136. }
  137.  
  138. //-------------------------------------------------------------------
  139. template<class T> int SimpleArray<T>::InsertAt( int nIndex, T argT, int nCount )
  140. {
  141.     // Valid index?
  142.     if( nIndex < 0 || nIndex > m_nUpperBound )
  143.         return FALSE;
  144.  
  145.     int i;
  146.     // Is there enough space after m_nUpperBound for inserting?
  147.     if( ( m_nSize - 1 ) - m_nUpperBound >= nCount )
  148.     {
  149.         // Yes, no need to allocate more memory.
  150.         // Push up the elements at the current position.
  151.         for( i = m_nUpperBound + nCount; i >= nIndex + nCount; i-- )
  152.             m_pT[ i ] = m_pT[ i - nCount ];
  153.         // Copy in the new data.
  154.         for( i = 0; i < nCount; i++ )
  155.             m_pT[ nIndex + i ] = argT;
  156.         // Adjust m_nUpperBound to new size.
  157.         m_nUpperBound += nCount;
  158.     }
  159.     else
  160.     {
  161.         // No, need to allocate more memory.
  162.         for (i = m_nSize - 1; i >= nIndex + nCount; i--)
  163.             m_pT[i] = m_pT[i - nCount];
  164.         if (m_nSize - nIndex < nCount)
  165.             nCount = m_nSize - nIndex;
  166.         for (i = 0; i < nCount; i++)
  167.             m_pT[nIndex + i] = argT;
  168.         m_nUpperBound = m_nSize - 1;        
  169.     }
  170.     return TRUE;
  171. }
  172.  
  173. //-------------------------------------------------------------------
  174. template<class T> void SimpleArray<T>::InsertAtRef(int nIndex, T& argT, int nCount)
  175. {
  176.     if(nIndex < 0 || nIndex > m_nUpperBound)
  177.         return;
  178.     int i;
  179.     if ((m_nSize - 1) - m_nUpperBound >= nCount) 
  180.     {
  181.         for(i = m_nUpperBound + nCount; i >= nIndex + nCount; i--)
  182.             m_pT[i] = m_pT[i - nCount];
  183.         for(i = 0; i < nCount; i++)
  184.             m_pT[nIndex + i] = argT;
  185.         m_nUpperBound += nCount;
  186.     }
  187.     else
  188.     {
  189.         for (i = m_nSize - 1; i >= nIndex + nCount; i--)
  190.             m_pT[i] = m_pT[i - nCount];
  191.         if (m_nSize - nIndex < nCount)
  192.             nCount = m_nSize - nIndex;
  193.         for (i = 0; i < nCount; i++)
  194.             m_pT[nIndex + i] = argT;
  195.         m_nUpperBound = m_nSize - 1;        
  196.     }
  197. }
  198.  
  199. //-------------------------------------------------------------------
  200. template<class T> int SimpleArray<T>::RemoveAt(int nIndex, int nCount)
  201. {
  202.     if(nIndex < 0 || nIndex > m_nUpperBound || nCount < 1) return FALSE;
  203.     if(nCount > m_nUpperBound - nIndex)
  204.     {
  205.         m_nUpperBound = nIndex - 1;
  206.         return TRUE;
  207.     }
  208.     int i;
  209.     for(i = nIndex; i <= m_nUpperBound - nCount; i++)
  210.     {
  211.         m_pT[i] = m_pT[i + nCount];
  212.     }
  213.     m_nUpperBound -= nCount;
  214.     return TRUE;
  215. }
  216.  
  217. //-------------------------------------------------------------------
  218. template<class T> void SimpleArray<T>::SetAtGrow(int nIndex, T argT)
  219. {
  220.     if(nIndex < 0) return;
  221.     if(nIndex > m_nSize - 1)
  222.         AddSpace(nIndex - m_nSize + 1);
  223.     m_pT[nIndex] = argT;
  224.     if(nIndex > m_nUpperBound) m_nUpperBound = nIndex;
  225. }
  226.  
  227. //-------------------------------------------------------------------
  228. template<class T> int SimpleArray<T>::SetAtGrowRef(int nIndex, T& argT)
  229. {
  230.     if(nIndex < 0)
  231.         return FALSE;
  232.     if(nIndex > m_nSize - 1)
  233.     {
  234.         if (AddSpace(nIndex - m_nSize + 1) == FALSE)
  235.             return FALSE;
  236.     }
  237.     m_pT[nIndex] = argT;
  238.     if(nIndex > m_nUpperBound)
  239.         m_nUpperBound = nIndex;
  240.     return TRUE;
  241. }
  242.  
  243. //-------------------------------------------------------------------
  244. template<class T> void SimpleArray<T>::SetAt(int nIndex, T argT)
  245. {
  246.     if(nIndex >= 0 && nIndex < m_nSize)
  247.     {
  248.         m_pT[nIndex] = argT;
  249.         if(nIndex > m_nUpperBound)
  250.             m_nUpperBound = nIndex;
  251.     }
  252.     else
  253.         return;
  254. }
  255.  
  256. //-------------------------------------------------------------------
  257. template<class T> void SimpleArray<T>::SetAtRef(int nIndex, T& argT)
  258. {
  259.     if(nIndex >= 0 && nIndex < m_nSize)
  260.     {
  261.         m_pT[nIndex] = argT;
  262.         if(nIndex > m_nUpperBound)
  263.             m_nUpperBound = nIndex;
  264.     }
  265.     else
  266.         return;
  267. }
  268.  
  269. //-------------------------------------------------------------------
  270. template<class T> T SimpleArray<T>::GetAt(int nIndex)
  271. {
  272.     return m_pT[nIndex];
  273. }
  274.  
  275. //-------------------------------------------------------------------
  276. template<class T> int SimpleArray<T>::AddSpace(int nExtend)
  277. {
  278.     int newsize = m_nSize + (((nExtend-1) / m_nGrowBy) + 1) * m_nGrowBy;
  279.     T* pT = new T[newsize];
  280.     if (pT != NULL)
  281.     {
  282.         int i;
  283.         for(i = 0; i < m_nSize; i++)
  284.             pT[i] = m_pT[i];
  285.         if(m_pT != NULL)
  286.             delete [] m_pT;
  287.         m_pT = pT;
  288.         m_nSize = newsize;
  289.         return TRUE;
  290.     }
  291.     else
  292.         return FALSE;
  293. }
  294.  
  295. //-------------------------------------------------------------------
  296. template<class T> int SimpleArray<T>::GetGrowBy()
  297. {
  298.     return m_nGrowBy;
  299. }
  300.  
  301. //-------------------------------------------------------------------
  302. template<class T> int SimpleArray<T>::GetSize()
  303. {
  304.     return m_nSize;
  305. }
  306.  
  307. //-------------------------------------------------------------------
  308. template<class T> int SimpleArray<T>::GetUpperBound()
  309. {
  310.     return m_nUpperBound;
  311. }
  312.  
  313. //-------------------------------------------------------------------
  314. template<class T> int SimpleArray<T>::GetLength()
  315. {
  316.     return m_nUpperBound+1;
  317. }
  318.  
  319. //-------------------------------------------------------------------
  320. template<class T> int SimpleArray<T>::SetSize(int nNewSize, int nGrowBy )
  321. {
  322.     if(nNewSize < 0)
  323.         return FALSE;
  324.     if (nNewSize == m_nSize)
  325.         return TRUE;
  326.     if( nNewSize == 0 )
  327.     {
  328.         ClearAll();
  329.         return TRUE;
  330.     }
  331.  
  332.     T* pT = new T[nNewSize];
  333.     if (pT == NULL)
  334.         return FALSE;
  335.     int i;
  336.     if(m_nUpperBound < nNewSize)
  337.     {
  338.         for(i = 0; i <= m_nUpperBound; i++)
  339.             pT[i] = m_pT[i];
  340.     }
  341.     else
  342.     {
  343.         for(i = 0; i < nNewSize; i++)
  344.             pT[i] = m_pT[i];
  345.         m_nUpperBound = nNewSize - 1;
  346.     }
  347.  
  348.     if(m_pT != NULL)
  349.         delete [] m_pT;
  350.     m_pT = pT;
  351.     m_nSize = nNewSize;
  352.     if(nGrowBy > 0)
  353.         m_nGrowBy = nGrowBy;
  354.     return TRUE;
  355. }
  356.  
  357. //-------------------------------------------------------------------
  358. template<class T> void SimpleArray<T>::SetGrowBy(int nGrowBy)
  359. {
  360.     if(nGrowBy > 0) m_nGrowBy = nGrowBy;
  361. }
  362.  
  363. //-------------------------------------------------------------------
  364. template<class T> void SimpleArray<T>::ClearAll()
  365. {
  366.     if(m_pT != NULL)
  367.         delete [] m_pT;
  368.     m_pT = NULL;
  369.     m_nSize = 0;
  370.     m_nUpperBound = ARR_EMPTY;
  371. }
  372.  
  373. //-------------------------------------------------------------------
  374. template<class T> int SimpleArray<T>::blContainsRef(T& argT)
  375. {
  376.     int i;
  377.     for(i = 0; i <= m_nUpperBound; i++)
  378.         if(argT == m_pT[i])
  379.             return TRUE;
  380.     return FALSE;
  381. }
  382.  
  383. //-------------------------------------------------------------------
  384. template<class T> int SimpleArray<T>::blContains(T argT)
  385. {
  386.     int i;
  387.     for(i = 0; i <= m_nUpperBound; i++)
  388.         if(argT == m_pT[i])
  389.             return TRUE;
  390.     return FALSE;
  391. }
  392.  
  393. //-------------------------------------------------------------------
  394. template<class T> int SimpleArray<T>::nContainsAt(T argT)
  395. {
  396.     int i;
  397.     for(i = 0; i <= m_nUpperBound; i++)
  398.         if(argT == m_pT[i])
  399.             return i;
  400.     return ARR_EMPTY;
  401. }
  402.  
  403. //-------------------------------------------------------------------
  404. // Make a copy of the other SimpleArray.
  405. template<class T> SimpleArray<T>& SimpleArray<T>::operator=( SimpleArray<T>& spa )
  406. {
  407.     // Can't assign to itself: "sa1 = sa1;" not allowed.
  408.     if( &spa != this )
  409.     {
  410.         // If this array is not empty then delete it.
  411.         ClearAll();
  412.         // Allocate memory.
  413.         m_pT = new T[ m_nSize ];
  414.         // Copy the valid elements.
  415.         if( m_pT != NULL )
  416.         {
  417.             // This array now is just large enough to contain the valid elements of spa.
  418.             m_nUpperBound = spa.m_nUpperBound;
  419.             m_nSize = m_nUpperBound + 1;
  420.             // GrowBy rate is also copied.
  421.             m_nGrowBy = spa.m_nGrowBy;
  422.             int k;
  423.             for(k = 0; k <= m_nUpperBound; k++)
  424.                 m_pT[k] = spa.m_pT[k];
  425.         }
  426.         // If no memory could be allocated, then this array remains empty.
  427.     }
  428.     return *this;
  429. }
  430.  
  431. //-------------------------------------------------------------------
  432. template<class T> void SimpleArray<T>::AppendRef(T& argT)
  433. {
  434.     SetAt(m_nUpperBound+1, argT);
  435. }
  436.  
  437. //-------------------------------------------------------------------
  438. template<class T> void SimpleArray<T>::Append(T argT)
  439. {
  440.     SetAtGrow(m_nUpperBound+1, argT);
  441. }
  442.  
  443. //-------------------------------------------------------------------
  444. template<class T> T& SimpleArray<T>::GetRefAt(int nIndex)
  445. {
  446.     return m_pT[nIndex];
  447. }
  448.  
  449. //-------------------------------------------------------------------
  450. template<class T> int SimpleArray<T>::blCompare(SimpleArray<T>& spa)
  451. {
  452.     if(m_nUpperBound != spa.GetUpperBound() ) return FALSE;
  453.     int k;
  454.     for(k = 0; k <= m_nUpperBound; k++)
  455.     {
  456.         if(m_pT[k] != spa[k]) return FALSE;
  457.     }
  458.     return TRUE;
  459. }
  460.  
  461. //-------------------------------------------------------------------
  462. template<class T> int SimpleArray<T>::operator==(SimpleArray<T>& spa)
  463. {
  464.     return blCompare(spa);
  465. }
  466.  
  467. //-------------------------------------------------------------------
  468. template<class T> int SimpleArray<T>::operator!=(SimpleArray<T>& spa)
  469. {
  470.     return !blCompare(spa);
  471. }
  472.  
  473. //-------------------------------------------------------------------
  474. template<class T> int SimpleArray<T>::blIsEmpty()
  475. {
  476.     return (GetUpperBound() < 0) ? TRUE : FALSE;
  477. }
  478.  
  479. //-------------------------------------------------------------------
  480. template<class T> void SimpleArray<T>::Exchange(int nIndex1, int nIndex2)
  481. {
  482.     T temp(GetRefAt(nIndex2));
  483.     GetRefAt(nIndex2) = GetRefAt(nIndex1);
  484.     GetRefAt(nIndex1) = temp;
  485. }
  486.  
  487. //-------------------------------------------------------------------
  488. template<class T> int SimpleArray<T>::Adopt(T* ptArray, int upbound, int size)
  489. {
  490. #ifdef _DEBUG
  491.     if(ptArray == NULL || upbound<0 || size<=0 || upbound >= size)
  492.         return FALSE;
  493. #endif
  494.     if(m_pT!=NULL)
  495.         delete [] m_pT;
  496.     m_pT = ptArray;
  497.     m_nSize = size;
  498.     m_nUpperBound = upbound;
  499.     return TRUE;
  500. }
  501.  
  502. //-------------------------------------------------------------------
  503. template<class T> void SimpleArray<T>::SetUpperBound(int upbnd)
  504. {
  505.     if(upbnd < m_nSize)
  506.         m_nUpperBound = upbnd;
  507. }
  508.  
  509. //-------------------------------------------------------------------
  510. template<class T> int SimpleArray<T>::AppendArray( T* pSrc, int srclen )
  511. {
  512.     if( srclen <= 0 )
  513.         return FALSE;
  514.  
  515.     if( m_nUpperBound + 1 + srclen > m_nSize )
  516.     {
  517.         // Not enough space, so get some.
  518.         if( !AddSpace( srclen ) )
  519.             return FALSE;
  520.     }
  521.     // Enough space to append without growing. Copy the data.
  522.     int i;
  523.     for( i=0; i<srclen; i++ )
  524.     {
  525.         m_pT[ m_nUpperBound + 1 + i ] = pSrc[i];
  526.     }
  527.     m_nUpperBound += srclen;
  528.     return TRUE;
  529. }
  530.  
  531. //-------------------------------------------------------------------
  532. template<class T> int SimpleArray<T>::ExpandToSize()
  533. {
  534.     m_nUpperBound = m_nSize - 1;
  535.     return TRUE;
  536. }
  537.  
  538. //-------------------------------------------------------------------
  539. template<class T> int SimpleArray<T>::CopyFrom( int index, T* pSrc, int srclen )
  540. {
  541.     if( m_nSize - index >= srclen )
  542.     {
  543.         // Enough space to copy into.
  544.         int i;
  545.         for( i = 0; i < srclen; i++ )
  546.             m_pT[ index + i ] = pSrc[ i ];
  547.         if( index + srclen - 1 > m_nUpperBound )
  548.             m_nUpperBound = index + srclen - 1;
  549.         return TRUE;
  550.     }
  551.     else
  552.         return FALSE;
  553. }
  554.  
  555. //-------------------------------------------------------------------
  556. int SimpleString::AppendString( char* ps )
  557. {
  558.     if( m_nUpperBound == -1 )
  559.         return SetToString( ps );
  560.     else
  561.     {
  562.         InsertAtGrow( m_nUpperBound, ps, 0, strlen( ps ) );
  563.     }
  564.     return TRUE;
  565. }
  566.  
  567. //-------------------------------------------------------------------
  568. int SimpleString::SetToString( char* ps )
  569. {
  570.     Clear();
  571.     return AppendString( ps );
  572. }
  573.  
  574. //-------------------------------------------------------------------
  575. char* SimpleString::operator=( char* ps )
  576. {
  577.     SetToString( ps );
  578.     return ps;
  579. }
  580.  
  581. //-------------------------------------------------------------------
  582. SimpleString& SimpleString::operator=( SimpleString str )
  583. {
  584.     SetToString( &str[0] );
  585.     return *this;
  586. }
  587.  
  588. //-------------------------------------------------------------------
  589. char* SimpleString::operator+=( char* ps )
  590. {
  591.     if( m_nUpperBound == -1 )
  592.         SetToString( ps );
  593.     else
  594.     {
  595.         InsertAtGrow( m_nUpperBound, ps, 0, strlen( ps ) );
  596.     }
  597.     return ps;
  598. }
  599.  
  600. //-------------------------------------------------------------------
  601. int SimpleString::StrLen()
  602. {
  603.     if( m_pT != NULL )
  604.         return strlen( m_pT );
  605.     else
  606.         return 0;
  607. }
  608.  
  609. //-------------------------------------------------------------------
  610. SimpleString::SimpleString()
  611. {
  612.     // Create a string containing only a zero-byte.
  613.     m_nGrowBy = 64;
  614.     Clear();
  615. }
  616.  
  617. //-------------------------------------------------------------------
  618. SimpleString::SimpleString( char* ps )
  619. {
  620.     // Create a SimpleString from a normal char array-string.
  621.     m_nGrowBy = 64;
  622.     Clear();
  623.     SetToString( ps );
  624. }
  625.  
  626. //-------------------------------------------------------------------
  627. void SimpleString::Clear()
  628. {
  629.     ClearAll();
  630.     Append( '\0' );
  631. }
  632.  
  633. //-------------------------------------------------------------------
  634. SimpleString SimpleString::operator+( SimpleString& str1 )
  635. {
  636.     SimpleString t1;
  637.     t1.SetToString( m_pT );
  638.     t1 += str1;
  639.     return SimpleString( &t1[0] );
  640. }
  641.  
  642. //-------------------------------------------------------------------
  643. int SimpleString::IsEmpty()
  644. {
  645.     return !StrLen();
  646. }
  647.  
  648. //-------------------------------------------------------------------
  649. SimpleString operator+( SimpleString ps1, char* ps2 )
  650. {
  651.     SimpleString s1;
  652.     s1 += ps1;
  653.     s1 += ps2;
  654.     return SimpleString(s1);
  655. }
  656.  
  657. //-------------------------------------------------------------------
  658. SimpleString operator+( char* ps1, SimpleString ps2 )
  659. {
  660.     SimpleString s1;
  661.     s1 += ps1;
  662.     s1 += ps2;
  663.     return SimpleString(s1);
  664. }
  665.  
  666. //-------------------------------------------------------------------
  667. template<class T> int SimpleArray<T>::Replace( int ToReplaceIndex, int ToReplaceLength, T* pReplaceWith, int ReplaceWithLength )
  668. {
  669.     if( m_pT != NULL && ToReplaceLength > 0 )
  670.     {
  671.         // Number of elements from start to end of array large enough for request?
  672.         if( m_nUpperBound - ToReplaceIndex + 1 >= ToReplaceLength )
  673.         {
  674.             if( ToReplaceLength < ReplaceWithLength )
  675.             {
  676.                 int i;
  677.                 T dummy;
  678.  
  679.                 // Next line might cause problems if used with non-pure-binary
  680.                 // objects.
  681.                 dummy = 0;
  682.  
  683.                 InsertAtGrow( ToReplaceIndex, dummy, ReplaceWithLength - ToReplaceLength );
  684.                 for( i = 0; i < ReplaceWithLength; i++ )
  685.                 {
  686.                     m_pT[ ToReplaceIndex + i ] = pReplaceWith[ i ];
  687.                 }
  688.  
  689.                 return TRUE;
  690.             }
  691.             else if( ToReplaceLength == ReplaceWithLength )
  692.             {
  693.                 int i;
  694.                 for( i = 0; i < ReplaceWithLength; i++ )
  695.                 {
  696.                     m_pT[ ToReplaceIndex + i ] = pReplaceWith[ i ];
  697.                 }
  698.                 return TRUE;
  699.             }
  700.             else // if( ToReplaceLength > ReplaceWithLength )
  701.             {
  702.                 int i;
  703.                 for( i = 0; i < ReplaceWithLength; i++ )
  704.                 {
  705.                     m_pT[ ToReplaceIndex + i ] = pReplaceWith[ i ];
  706.                 }
  707.  
  708.                 RemoveAt( ToReplaceIndex + ReplaceWithLength, ToReplaceLength - ReplaceWithLength );
  709.                 return TRUE;
  710.             }
  711.         }
  712.         else
  713.         {
  714.             return FALSE;
  715.         }
  716.     }
  717.     else
  718.     {
  719.         return FALSE;
  720.     }
  721. }
  722.