home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / VAPPV.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  7.2 KB  |  175 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - vappv.cpp
  3.  * C++ VECTOR APPLY for virtual base classes
  4.  * This is called internally by the compiler to copy
  5.  * arrays of classes having assignment operators or ref constructors
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1990, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdarg.h>
  18. #include <stddef.h>
  19. #include <stdlib.h>
  20. #include <_vector.h>
  21.  
  22. extern "C"
  23. void  _vector_applyv_(void far * dest,  // address of destination array
  24.                       void far * src,   // address of source array
  25.                       size_t size,      // size of each object
  26.                       unsigned count,   // number of objects
  27.                       unsigned mode,    // type of function to call
  28.                       ...
  29.                      )
  30.  
  31. /* This routine is used to copy an array of class type.
  32.  
  33.    Since the routine used for the class may be of either memory model, and
  34.    take arguments of any memory model, we are forced to pass a mode
  35.    parameter to tell us how to cast it.  Since we must pass a near pointer
  36.    for near functions and a far call for far functions, we can't even know
  37.    the argument type until runtime, so we have to use varargs to get at it.
  38.    We do assume that both source and destination have the same distance
  39.    modifier, and the compiler enforces that.
  40.  
  41.    The interpretation of the mode parameter is:
  42.        far function    0x01     VFARCALL
  43.        pascal call     0x02     VPASCAL
  44.        far pointer     0x04     VFARPTR
  45.        fastcall        0x20     VFASTCALL
  46.        fastthis        0x80     VFASTTHIS
  47.        this last       0x100    VTHISLAST
  48. */
  49. {
  50.     va_list ap;         /* for access to parameters */
  51.     appvNNC np;         /* Near pointer version */
  52.     appvFNC fp;         /* Far pointer version */
  53.  
  54.     va_start(ap, mode);
  55.  
  56.     if (mode & 1)
  57.         fp = va_arg(ap, appvFNC);
  58.     else
  59.         np = va_arg(ap, appvNNC);
  60.  
  61.     if (mode & VFASTTHIS)   // this-last has no effect with fast-this
  62.         mode &= ~(VTHISLAST);
  63.  
  64.     do
  65.         {
  66.         switch (mode)
  67.             {
  68.             case 0:
  69.                 (*(appvNNC) np)((void near *)dest, 0, (void near *)src); break;
  70.             case (VFARCALL):
  71.                 (*(appvFNC) fp)((void near *)dest, 0, (void near *)src); break;
  72.             case (VPASCAL):
  73.                 (*(appvNNP) np)((void near *)dest, 0, (void near *)src); break;
  74.             case (VPASCAL | VTHISLAST):
  75.                 (*(appvNNPL) np)(0, (void near *)src, (void near *)dest); break;
  76.             case (VFARCALL | VPASCAL):
  77.                 (*(appvFNP) fp)((void near *)dest, 0, (void near *)src); break;
  78.             case (VFARCALL | VPASCAL | VTHISLAST):
  79.                 (*(appvFNPL) fp)(0, (void near *)src, (void near *)dest); break;
  80.             case (VFASTCALL):
  81.                 (*(appvNNF) np)((void near *)dest, 0, (void near *)src); break;
  82.             case (VFASTCALL | VTHISLAST):
  83.                 (*(appvNNFL) np)(0, (void near *)src, (void near *)dest); break;
  84.             case (VFARCALL | VFASTCALL):
  85.                 (*(appvFNF) fp)((void near *)dest, 0, (void near *)src); break;
  86.             case (VFARCALL | VFASTCALL | VTHISLAST):
  87.                 (*(appvFNFL) fp)(0, (void near *)src, (void near *)dest); break;
  88.             case (VFARPTR):
  89.                 (*(appvNFC) np)((void far  *)dest, 0, (void far  *)src); break;
  90.             case (VFARCALL | VFARPTR):
  91.                 (*(appvFFC) fp)((void far  *)dest, 0, (void far  *)src); break;
  92.             case (VFARPTR | VPASCAL):
  93.                 (*(appvNFP) np)((void far  *)dest, 0, (void far  *)src); break;
  94.             case (VFARPTR | VPASCAL | VTHISLAST):
  95.                 (*(appvNFPL) np)(0, (void far  *)src, (void far  *)dest); break;
  96.             case (VFARCALL | VFARPTR | VPASCAL):
  97.                 (*(appvFFP) fp)((void far  *)dest, 0, (void far  *)src); break;
  98.             case (VFARCALL | VFARPTR | VPASCAL | VTHISLAST):
  99.                 (*(appvFFPL) fp)(0, (void far  *)src, (void far  *)dest); break;
  100.             case (VFARPTR | VFASTCALL):
  101.                 (*(appvNFF) np)((void far  *)dest, 0, (void far  *)src); break;
  102.             case (VFARPTR | VFASTCALL | VTHISLAST):
  103.                 (*(appvNFFL) np)(0, (void far  *)src, (void far  *)dest); break;
  104.             case (VFARCALL | VFARPTR | VFASTCALL):
  105.                 (*(appvFFF) fp)((void far  *)dest, 0, (void far  *)src); break;
  106.             case (VFARCALL | VFARPTR | VFASTCALL | VTHISLAST):
  107.                 (*(appvFFFL) fp)(0, (void far  *)src, (void far *)dest); break;
  108.             case (0 | VFASTTHIS):
  109.                 LOAD_NEAR_THIS(dest);
  110.                 (*(appvNNCT) np)(0, (void near *)src);
  111.                 END_NEAR_THIS();
  112.                 break;
  113.             case (VFARCALL | VFASTTHIS):
  114.                 LOAD_NEAR_THIS(dest);
  115.                 (*(appvFNCT) fp)(0, (void near *)src);
  116.                 END_NEAR_THIS();
  117.                 break;
  118.             case (VPASCAL | VFASTTHIS):
  119.                 LOAD_NEAR_THIS(dest);
  120.                 (*(appvNNPT) np)(0, (void near *)src);
  121.                 END_NEAR_THIS();
  122.                 break;
  123.             case (VFARCALL | VPASCAL | VFASTTHIS):
  124.                 LOAD_NEAR_THIS(dest);
  125.                 (*(appvFNPT) fp)(0, (void near *)src);
  126.                 END_NEAR_THIS();
  127.                 break;
  128.             case (VFASTCALL | VFASTTHIS):
  129.                 LOAD_NEAR_THIS(dest);
  130.                 (*(appvNNFT) np)(0, (void near *)src);
  131.                 END_NEAR_THIS();
  132.                 break;
  133.             case (VFARCALL | VFASTCALL | VFASTTHIS):
  134.                 LOAD_NEAR_THIS(dest);
  135.                 (*(appvFNFT) fp)(0, (void near *)src);
  136.                 END_NEAR_THIS();
  137.                 break;
  138.             case (VFARPTR | VFASTTHIS):
  139.                 LOAD_FAR_THIS(dest);
  140.                 (*(appvNFCT) np)(0, (void far  *)src);
  141.                 END_FAR_THIS();
  142.                 break;
  143.             case (VFARCALL | VFARPTR | VFASTTHIS):
  144.                 LOAD_FAR_THIS(dest);
  145.                 (*(appvFFCT) fp)(0, (void far  *)src);
  146.                 END_FAR_THIS();
  147.                 break;
  148.             case (VFARPTR | VPASCAL | VFASTTHIS):
  149.                 LOAD_FAR_THIS(dest);
  150.                 (*(appvNFPT) np)(0, (void far  *)src);
  151.                 END_FAR_THIS();
  152.                 break;
  153.             case (VFARCALL | VFARPTR | VPASCAL | VFASTTHIS):
  154.                 LOAD_FAR_THIS(dest);
  155.                 (*(appvFFPT) fp)(0, (void far  *)src);
  156.                 END_FAR_THIS();
  157.                 break;
  158.             case (VFARPTR | VFASTCALL | VFASTTHIS):
  159.                 LOAD_FAR_THIS(dest);
  160.                 (*(appvNFFT) np)(0, (void far  *)src);
  161.                 END_FAR_THIS();
  162.                 break;
  163.             case (VFARCALL | VFARPTR | VFASTCALL | VFASTTHIS):
  164.                 LOAD_FAR_THIS(dest);
  165.                 (*(appvFFFT) fp)(0, (void far  *)src);
  166.                 END_FAR_THIS();
  167.                 break;
  168.             default:
  169.                 abort(); break;
  170.             }
  171.         (char far *) dest += size;
  172.         (char far *) src += size;
  173.         } while (--count > 0);
  174. }
  175.