Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.5 KiB

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