home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK10 / MFC / SRC / ELEMENTS.H$ / elements
Encoding:
Text File  |  1992-02-10  |  2.4 KB  |  59 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11. // Collection implementation helpers
  12.  
  13. /*
  14. * The short story:
  15. *   this file contains inline functions that make up the building blocks
  16. *   for implementing the string versions of standard parameterized
  17. *   collection shapes
  18. *
  19. * The long story:
  20. *   Because the implementation of collection classes moves objects around
  21. *   in various ways, it is very inefficient to use only generic C++ constructs.
  22. *   For example, in order to grow an array of FOO objects by one element,
  23. *   you would be forced to allocate a new array of appropriate size, calling
  24. *   the FOO constructor on every element.  Then copy the original array, element
  25. *   by element using a possibly overloaded assignment operator.  Finally destroy
  26. *   the original array element by element.
  27. *   For built-in data types (WORD, DWORD, pointer types), this is complete
  28. *   overkill.  For non-trivial classes (eg: CString in particular) this is
  29. *   a terrible implementation.
  30. *   
  31. *   The bottom line: we have to have special routines for doing construction
  32. *   and destruction of arrays of special elements - in particular CStrings.
  33. *   The standard templates are parameterized on 'HAS_CREATE' which is
  34. *   non-zero if the collection implementation requires a special
  35. *   construct and destruct function.
  36. *   Please note that these are inline overloaded operators, and do not have
  37. *   any form of runtime polymorphism (i.e. nothing is 'virtual').
  38. */
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Special implementations for CStrings
  42. // it is faster to bit-wise copy a CString than to call an official
  43. //   constructor - since an empty CString can be bit-wise copied
  44.  
  45. extern const CString NEAR afxEmptyString;
  46.  
  47. static inline void ConstructElement(CString* pNewData)
  48. {
  49.     memcpy(pNewData, &afxEmptyString, sizeof(CString));
  50. }
  51.  
  52. static inline void DestructElement(CString* pOldData)
  53. {
  54.     pOldData->Empty();
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58.