|
|
1.1 ! root 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: * ! 37: * Please note that these are inline overloaded operators, and do not have ! 38: * any form of runtime polymorphism (i.e. nothing is 'virtual'). ! 39: */ ! 40: ! 41: ///////////////////////////////////////////////////////////////////////////// ! 42: // Special implementations for CStrings ! 43: // it is faster to bit-wise copy a CString than to call an official ! 44: // constructor - since an empty CString can be bit-wise copied ! 45: ! 46: extern const CString NEAR afxEmptyString; ! 47: ! 48: static inline void ConstructElement(CString* pNewData) ! 49: { ! 50: memcpy(pNewData, &afxEmptyString, sizeof(CString)); ! 51: } ! 52: ! 53: static inline void DestructElement(CString* pOldData) ! 54: { ! 55: pOldData->Empty(); ! 56: } ! 57: ! 58: /////////////////////////////////////////////////////////////////////////////
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.