home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / VAPP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  3.2 KB  |  81 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - vapp.cpp
  3.  * C++ VECTOR APPLY
  4.  * This is called internally by the compiler to copy arrays of classes
  5.  * having assignment operators or reference constructors
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C++ Run Time Library - Version 1.0                 |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1990 by Borland International              |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #include <stdarg.h>
  19. #include <stddef.h>
  20.  
  21. typedef void (near * appNNC)(void near*, void near*);
  22. typedef void (near * appNFC)(void far*, void far*);
  23. typedef void pascal (near * appNNP)(void near*, void near*);
  24. typedef void pascal (near * appNFP)(void far*, void far*);
  25. typedef void (far * appFNC)(void near*, void near*);
  26. typedef void (far * appFFC)(void far*, void far*);
  27. typedef void pascal (far * appFNP)(void near*, void near*);
  28. typedef void pascal (far * appFFP)(void far*, void far*);
  29.  
  30. extern "C"
  31. void  _vector_apply_(char far* dest,    // address of destination array
  32.              char far* src,    // address of source array
  33.              size_t size,    // size of each object
  34.              int count,        // number of objects
  35.              int mode,
  36.              ...
  37.             )
  38.  
  39. /* This routine is used to copy an array of class type.
  40.  
  41.    Since the routine used for the class may be of either memory model, and
  42.    take arguments of any memory model, we are forced to pass a mode
  43.    parameter to tell us how to cast it.  Since we must pass a near pointer
  44.    for near functions and a far call for far functions, we can't even know
  45.    the argument type until runtime, so we have to use varargs to get at it.
  46.    We do assume that both source and destination have the same distance
  47.    modifier, and the compiler enforces that.
  48.  
  49.    The interpretation of the mode parameter is:
  50.     far function        0x01
  51.     pascal call        0x02
  52.     far pointer        0x04
  53. */
  54. {
  55.     va_list ap;        /* for access to parameters */
  56.     appNNC np;        /* Near pointer version */
  57.     appFNC fp;        /* Far pointer version */
  58.  
  59.     va_start(ap, mode);
  60.  
  61.     if (mode & 1)
  62.     fp = va_arg(ap, appFNC);
  63.     else
  64.     np = va_arg(ap, appNNC);
  65.  
  66.     do {
  67.     switch (mode) {
  68.       case 0: np((void near *) dest, (void near *) src); break;
  69.       case 1: fp((void near *) dest, (void near *) src); break;
  70.       case 2: (*(appNNP) np)((void near *)dest, (void near *)src); break;
  71.       case 3: (*(appFNP) fp)((void near *)dest, (void near *)src); break;
  72.       case 4: (*(appNFC) np)((void far  *)dest, (void far  *)src); break;
  73.       case 5: (*(appFFC) fp)((void far  *)dest, (void far  *)src); break;
  74.       case 6: (*(appNFP) np)((void far  *)dest, (void far  *)src); break;
  75.       default:(*(appFFP) fp)((void far  *)dest, (void far  *)src); break;
  76.     }
  77.     dest += size;
  78.     src += size;
  79.     } while (--count > 0);
  80. }
  81.