home *** CD-ROM | disk | FTP | other *** search
/ Total C++ 2 / TOTALCTWO.iso / borland / srcbdto.pak / MISC.H < prev    next >
Text File  |  1997-05-06  |  34KB  |  476 lines

  1. //-----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // misc.h
  6. // Miscellaneous defines
  7. //-----------------------------------------------------------------------------
  8.  
  9. #if !defined(MISC_H)
  10. #define MISC_H
  11.  
  12. inline VARIANT_BOOL MakeVariantBool( bool b )
  13. {
  14.     return b ? ((VARIANT_BOOL) -1) : ((VARIANT_BOOL) 0);
  15. }
  16.  
  17. inline bool MakeBool( VARIANT_BOOL v )
  18. {
  19.     return v ? true : false;
  20. }
  21.  
  22. //-----------------------------------------------------------------------------
  23.  
  24. #define BDTOOUTER( name, ptr )                                                \
  25.   (pThisBDTOClass(((char*)ptr) - int( &pThisBDTOClass(0)->name )))
  26.  
  27. #define ARRAYOUTER( name, ptr )                                               \
  28.   (pThisArrayClass(((char*)ptr) - int( &pThisArrayClass(0)->name )))
  29.  
  30. // macros for read only properties which return a simple type
  31.  
  32. #define DEFINE_BDTO_PROP_RO( cls, type, name )                                \
  33.   cls::prop##name::operator type()                                            \
  34.   {                                                                           \
  35.     type v;                                                                   \
  36.     BDTOOUTER( name, this )->Get##name( v );                                  \
  37.     return v;                                                                 \
  38.   }
  39.                                                     
  40.  
  41. // macros for read write properties which return a simple type
  42.  
  43. #define DEFINE_BDTO_PROP_RW( cls, type, name )                                \
  44.   cls::prop##name::operator type()                                            \
  45.   {                                                                           \
  46.     static type v;                                                            \
  47.     BDTOOUTER( name, this )->Get##name( v );                                  \
  48.     return v;                                                                 \
  49.   }                                                                           \
  50.   type cls::prop##name::operator=( type v )                                   \
  51.   {                                                                           \
  52.     BDTOOUTER( name, this )->Set##name( v );                                  \
  53.     return v;                                                                 \
  54.   }                                                                           \
  55.   cls::prop##name& cls::prop##name::operator=( const cls::prop##name& other ) \
  56.   {                                                                           \
  57.     type v;                                                                   \
  58.     BDTOOUTER( name, &other )->Get##name( v );                                \
  59.     BDTOOUTER( name, this )->Set##name( v );                                  \
  60.     return *this;                                                             \
  61.   }
  62.  
  63.  
  64. // macros for read only properties which return an object
  65.  
  66. #define DEFINE_BDTO_OBJECTPROP_RO( cls, type, name )                          \
  67.   cls::prop##name::prop##name()                                               \
  68.   {                                                                           \
  69.     p##name = NULL;                                                           \
  70.   }                                                                           \
  71.   cls::prop##name::~prop##name()                                              \
  72.   {                                                                           \
  73.     if (p##name)                                                              \
  74.       delete p##name;                                                         \
  75.   }                                                                           \
  76.   cls::prop##name::operator type*()                                           \
  77.   {                                                                           \
  78.     if (! p##name)                                                            \
  79.       p##name = new type;                                                     \
  80.     if (p##name)                                                              \
  81.       BDTOOUTER( name, this )->Get##name( *p##name );                         \
  82.     return p##name;                                                           \
  83.   }                                                                           \
  84.   cls::prop##name::operator const type&()                                     \
  85.   {                                                                           \
  86.     return *(cls::prop##name::operator type*());                              \
  87.   }                                                                           \
  88.   type* cls::prop##name::operator->()                                         \
  89.   {                                                                           \
  90.     return cls::prop##name::operator type*();                                 \
  91.   }                                                                           \
  92.   const type& cls::prop##name::operator*()                                    \
  93.   {                                                                           \
  94.     return *(cls::prop##name::operator type*());                              \
  95.   }
  96.  
  97. #define DEFINE_BDTO_OBJECTPROP_RO_FAST( cls, type, pittype, name )            \
  98.   cls::prop##name::prop##name()                                               \
  99.   {                                                                           \
  100.     p##name = NULL;                                                           \
  101.   }                                                                           \
  102.   cls::prop##name::~prop##name()                                              \
  103.   {                                                                           \
  104.     if (p##name)                                                              \
  105.       delete p##name;                                                         \
  106.   }                                                                           \
  107.   cls::prop##name::operator type*()                                           \
  108.   {                                                                           \
  109.     if (! p##name)                                                            \
  110.       p##name = new type( pittype(0) );                                       \
  111.     if (p##name)                                                              \
  112.       BDTOOUTER( name, this )->Get##name( *p##name );                         \
  113.     return p##name;                                                           \
  114.   }                                                                           \
  115.   cls::prop##name::operator const type&()                                     \
  116.   {                                                                           \
  117.     return *(cls::prop##name::operator type*());                              \
  118.   }                                                                           \
  119.   type* cls::prop##name::operator->()                                         \
  120.   {                                                                           \
  121.     return cls::prop##name::operator type*();                                 \
  122.   }                                                                           \
  123.   const type& cls::prop##name::operator*()                                    \
  124.   {                                                                           \
  125.     return *(cls::prop##name::operator type*());                              \
  126.   }
  127.  
  128.  
  129. // macros for read write properties which return an object
  130.  
  131. #define DEFINE_BDTO_OBJECTPROP_RW( cls, type, name )                          \
  132.   cls::prop##name::prop##name()                                               \
  133.   {                                                                           \
  134.     p##name = NULL;                                                           \
  135.   }                                                                           \
  136.   cls::prop##name::~prop##name()                                              \
  137.   {                                                                           \
  138.     if (p##name)                                                              \
  139.       delete p##name;                                                         \
  140.   }                                                                           \
  141.   cls::prop##name::operator type*()                                           \
  142.   {                                                                           \
  143.     if (! p##name)                                                            \
  144.       p##name = new type;                                                     \
  145.     if (p##name)                                                              \
  146.       BDTOOUTER( name, this )->Get##name( *p##name );                         \
  147.     return p##name;                                                           \
  148.   }                                                                           \
  149.   cls::prop##name::operator const type&()                                     \
  150.   {                                                                           \
  151.     return *(cls::prop##name::operator type*());                              \
  152.   }                                                                           \
  153.   type* cls::prop##name::operator->()                                         \
  154.   {                                                                           \
  155.     return cls::prop##name::operator type*();                                 \
  156.   }                                                                           \
  157.   const type& cls::prop##name::operator*()                                    \
  158.   {                                                                           \
  159.     return *(cls::prop##name::operator type*());                              \
  160.   }                                                                           \
  161.   type* cls::prop##name::operator=( type* v )                                 \
  162.   {                                                                           \
  163.     if (v)                                                                    \
  164.       BDTOOUTER( name, this )->Set##name( *v );                               \
  165.     return cls::prop##name::operator type*();                                 \
  166.   }                                                                           \
  167.   type& cls::prop##name::operator=( const type& v )                           \
  168.   {                                                                           \
  169.     BDTOOUTER( name, this )->Set##name( v );                                  \
  170.     return *(cls::prop##name::operator type*());                              \
  171.   }                                                                           \
  172.   cls::prop##name& cls::prop##name::operator=( const cls::prop##name& other ) \
  173.   {                                                                           \
  174.     type v;                                                                   \
  175.     BDTOOUTER( name, &other )->Get##name( v );                                \
  176.     BDTOOUTER( name, this )->Set##name( v );                                  \
  177.     return *this;                                                             \
  178.   }
  179.  
  180. #define DEFINE_BDTO_OBJECTPROP_RW_FAST( cls, type, pittype, name )            \
  181.   cls::prop##name::prop##name()                                               \
  182.   {                                                                           \
  183.     p##name = NULL;                                                           \
  184.   }                                                                           \
  185.   cls::prop##name::~prop##name()                                              \
  186.   {                                                                           \
  187.     if (p##name)                                                              \
  188.       delete p##name;                                                         \
  189.   }                                                                           \
  190.   cls::prop##name::operator type*()                                           \
  191.   {                                                                           \
  192.     if (! p##name)                                                            \
  193.       p##name = new type( pittype(0) );                                       \
  194.     if (p##name)                                                              \
  195.       BDTOOUTER( name, this )->Get##name( *p##name );                         \
  196.     return p##name;                                                           \
  197.   }                                                                           \
  198.   cls::prop##name::operator const type&()                                     \
  199.   {                                                                           \
  200.     return *(cls::prop##name::operator type*());                              \
  201.   }                                                                           \
  202.   type* cls::prop##name::operator->()                                         \
  203.   {                                                                           \
  204.     return cls::prop##name::operator type*();                                 \
  205.   }                                                                           \
  206.   const type& cls::prop##name::operator*()                                    \
  207.   {                                                                           \
  208.     return *(cls::prop##name::operator type*());                              \
  209.   }                                                                           \
  210.   type* cls::prop##name::operator=( type* v )                                 \
  211.   {                                                                           \
  212.     if (v)                                                                    \
  213.       BDTOOUTER( name, this )->Set##name( *v );                               \
  214.     return cls::prop##name::operator type*();                                 \
  215.   }                                                                           \
  216.   type& cls::prop##name::operator=( const type& v )                           \
  217.   {                                                                           \
  218.     BDTOOUTER( name, this )->Set##name( v );                                  \
  219.     return *(cls::prop##name::operator type*());                              \
  220.   }                                                                           \
  221.   cls::prop##name& cls::prop##name::operator=( const cls::prop##name& other ) \
  222.   {                                                                           \
  223.     type v( pittype(0) );                                                     \
  224.     BDTOOUTER( name, &other )->Get##name( v );                                \
  225.     BDTOOUTER( name, this )->Set##name( v );                                  \
  226.     return *this;                                                             \
  227.   }
  228.  
  229.  
  230. // macros for read write array properties which return a simple type
  231.  
  232. #define DEFINE_BDTO_ARRAYPROP_RW( cls, type, name, itype )                    \
  233.   cls::prop##name::setter##name& cls::prop##name::operator[]( itype i )       \
  234.   {                                                                           \
  235.     name.index = i;                                                           \
  236.     return name;                                                              \
  237.   }                                                                           \
  238.   cls::prop##name::setter##name::operator type()                              \
  239.   {                                                                           \
  240.     static type v;                                                            \
  241.     ARRAYOUTER( name, this )->CallGet##name( index, v );                      \
  242.     return v;                                                                 \
  243.   }                                                                           \
  244.   type cls::prop##name::setter##name::operator=( type v )                     \
  245.   {                                                                           \
  246.     ARRAYOUTER( name, this )->CallSet##name( index, v );                      \
  247.     return v;                                                                 \
  248.   }                                                                           \
  249.   cls::prop##name::setter##name& cls::prop##name::setter##name::operator=( const cls::prop##name::setter##name& other )\
  250.   {                                                                           \
  251.     type v;                                                                   \
  252.     ARRAYOUTER( name, &other )->CallGet##name( other.index, v );              \
  253.     ARRAYOUTER( name, this )->CallSet##name( index, v );                      \
  254.     return *this;                                                             \
  255.   }                                                                           \
  256.   void cls::prop##name::CallGet##name( itype i, type& v )                     \
  257.   {                                                                           \
  258.     BDTOOUTER( name, this )->Get##name( i, v );                               \
  259.   }                                                                           \
  260.   void cls::prop##name::CallSet##name( itype i, type v )                      \
  261.   {                                                                           \
  262.     BDTOOUTER( name, this )->Set##name( i, v );                               \
  263.   }
  264.  
  265.  
  266. // macros for read only array properties which return an object
  267.  
  268. #define DEFINE_BDTO_ARRAYOBJECTPROP_RO( cls, type, name, itype )              \
  269.   cls::prop##name::prop##name()                                               \
  270.   {                                                                           \
  271.     p##name = NULL;                                                           \
  272.   }                                                                           \
  273.   cls::prop##name::~prop##name()                                              \
  274.   {                                                                           \
  275.     if (p##name)                                                              \
  276.       delete p##name;                                                         \
  277.   }                                                                           \
  278.   type* cls::prop##name::operator[]( itype i )                                \
  279.   {                                                                           \
  280.     if (! p##name)                                                            \
  281.       p##name = new type;                                                     \
  282.     if (p##name)                                                              \
  283.       BDTOOUTER( name, this )->Get##name( i, *p##name );                      \
  284.     return p##name;                                                           \
  285.   }
  286.  
  287. #define DEFINE_BDTO_ARRAYOBJECTPROP_RO_FAST( cls, type, pittype, name, itype )\
  288.   cls::prop##name::prop##name()                                               \
  289.   {                                                                           \
  290.     p##name = NULL;                                                           \
  291.   }                                                                           \
  292.   cls::prop##name::~prop##name()                                              \
  293.   {                                                                           \
  294.     if (p##name)                                                              \
  295.       delete p##name;                                                         \
  296.   }                                                                           \
  297.   type* cls::prop##name::operator[]( itype i )                                \
  298.   {                                                                           \
  299.     if (! p##name)                                                            \
  300.       p##name = new type( pittype(0) );                                       \
  301.     if (p##name)                                                              \
  302.       BDTOOUTER( name, this )->Get##name( i, *p##name );                      \
  303.     return p##name;                                                           \
  304.   }
  305.  
  306.  
  307. // macros for read write array properties which return an object
  308.  
  309. #define DEFINE_BDTO_ARRAYOBJECTPROP_RW( cls, type, name, itype )              \
  310.   cls::prop##name::prop##name()                                               \
  311.   {                                                                           \
  312.     p##name = NULL;                                                           \
  313.   }                                                                           \
  314.   cls::prop##name::~prop##name()                                              \
  315.   {                                                                           \
  316.     if (p##name)                                                              \
  317.       delete p##name;                                                         \
  318.   }                                                                           \
  319.   cls::prop##name::setter##name& cls::prop##name::operator[]( itype i )       \
  320.   {                                                                           \
  321.     name.index = i;                                                           \
  322.     return name;                                                              \
  323.   }                                                                           \
  324.   cls::prop##name::setter##name::operator type*()                             \
  325.   {                                                                           \
  326.     return ARRAYOUTER( name, this )->CallGet##name( index );                  \
  327.   }                                                                           \
  328.   cls::prop##name::setter##name::operator const type&()                       \
  329.   {                                                                           \
  330.     return *(cls::prop##name::setter##name::operator type*());                \
  331.   }                                                                           \
  332.   type* cls::prop##name::setter##name::operator->()                           \
  333.   {                                                                           \
  334.     return cls::prop##name::setter##name::operator type*();                   \
  335.   }                                                                           \
  336.   const type& cls::prop##name::setter##name::operator*()                      \
  337.   {                                                                           \
  338.     return *(cls::prop##name::setter##name::operator type*());                \
  339.   }                                                                           \
  340.   type* cls::prop##name::setter##name::operator=( type* v )                   \
  341.   {                                                                           \
  342.     if (v)                                                                    \
  343.       ARRAYOUTER( name, this )->CallSet##name( index, *v );                   \
  344.     return cls::prop##name::setter##name::operator type*();                   \
  345.   }                                                                           \
  346.   type& cls::prop##name::setter##name::operator=( const type& v )                   \
  347.   {                                                                           \
  348.     ARRAYOUTER( name, this )->CallSet##name( index, v );                      \
  349.     return *(cls::prop##name::setter##name::operator type*());                \
  350.   }                                                                           \
  351.   cls::prop##name::setter##name& cls::prop##name::setter##name::operator=( const cls::prop##name::setter##name& other )\
  352.   {                                                                           \
  353.     type* v;                                                                  \
  354.     v = ARRAYOUTER( name, &other )->CallGet##name( other.index );             \
  355.     ARRAYOUTER( name, this )->CallSet##name( index, *v );                     \
  356.     return *this;                                                             \
  357.   }                                                                           \
  358.   type* cls::prop##name::CallGet##name( itype i )                             \
  359.   {                                                                           \
  360.     if (! p##name)                                                            \
  361.       p##name = new type;                                                     \
  362.     if (p##name)                                                              \
  363.       BDTOOUTER( name, this )->Get##name( i, *p##name );                      \
  364.     return p##name;                                                           \
  365.   }                                                                           \
  366.   void cls::prop##name::CallSet##name( itype i, const type& v )                     \
  367.   {                                                                           \
  368.     BDTOOUTER( name, this )->Set##name( i, v );                               \
  369.   }
  370.  
  371. #define DEFINE_BDTO_ARRAYOBJECTPROP_RW_FAST( cls, type, pittype, name, itype )\
  372.   cls::prop##name::prop##name()                                               \
  373.   {                                                                           \
  374.     p##name = NULL;                                                           \
  375.   }                                                                           \
  376.   cls::prop##name::~prop##name()                                              \
  377.   {                                                                           \
  378.     if (p##name)                                                              \
  379.       delete p##name;                                                         \
  380.   }                                                                           \
  381.   cls::prop##name::setter##name& cls::prop##name::operator[]( itype i )       \
  382.   {                                                                           \
  383.     name.index = i;                                                           \
  384.     return name;                                                              \
  385.   }                                                                           \
  386.   cls::prop##name::setter##name::operator type*()                             \
  387.   {                                                                           \
  388.     return ARRAYOUTER( name, this )->CallGet##name( index );                  \
  389.   }                                                                           \
  390.   cls::prop##name::setter##name::operator const type&()                       \
  391.   {                                                                           \
  392.     return *(cls::prop##name::setter##name::operator type*());                \
  393.   }                                                                           \
  394.   type* cls::prop##name::setter##name::operator->()                           \
  395.   {                                                                           \
  396.     return cls::prop##name::setter##name::operator type*();                   \
  397.   }                                                                           \
  398.   const type& cls::prop##name::setter##name::operator*()                      \
  399.   {                                                                           \
  400.     return *(cls::prop##name::setter##name::operator type*());                \
  401.   }                                                                           \
  402.   type* cls::prop##name::setter##name::operator=( type* v )                   \
  403.   {                                                                           \
  404.     if (v)                                                                    \
  405.       ARRAYOUTER( name, this )->CallSet##name( index, *v );                   \
  406.     return cls::prop##name::setter##name::operator type*();                   \
  407.   }                                                                           \
  408.   type& cls::prop##name::setter##name::operator=( const type& v )             \
  409.   {                                                                           \
  410.     ARRAYOUTER( name, this )->CallSet##name( index, v );                      \
  411.     return *(cls::prop##name::setter##name::operator type*());                \
  412.   }                                                                           \
  413.   cls::prop##name::setter##name& cls::prop##name::setter##name::operator=( const cls::prop##name::setter##name& other )\
  414.   {                                                                           \
  415.     type* v;                                                                  \
  416.     v = ARRAYOUTER( name, &other )->CallGet##name( other.index );             \
  417.     ARRAYOUTER( name, this )->CallSet##name( index, *v );                     \
  418.     return *this;                                                             \
  419.   }                                                                           \
  420.   type* cls::prop##name::CallGet##name( itype i )                             \
  421.   {                                                                           \
  422.     if (! p##name)                                                            \
  423.       p##name = new type( pittype(0) );                                       \
  424.     if (p##name)                                                              \
  425.       BDTOOUTER( name, this )->Get##name( i, *p##name );                      \
  426.     return p##name;                                                           \
  427.   }                                                                           \
  428.   void cls::prop##name::CallSet##name( itype i, const type& v )                     \
  429.   {                                                                           \
  430.     BDTOOUTER( name, this )->Set##name( i, v );                               \
  431.   }
  432.  
  433.  
  434. // macros for methods which return an object
  435.  
  436. #define DEFINE_BDTO_OBJECTMETHOD1( cls, rettype, pittype, name, atype )       \
  437.   cls::obj##name::obj##name()                                                 \
  438.   {                                                                           \
  439.     p##name = NULL;                                                           \
  440.   }                                                                           \
  441.   cls::obj##name::~obj##name()                                                \
  442.   {                                                                           \
  443.     if (p##name)                                                              \
  444.       delete p##name;                                                         \
  445.   }                                                                           \
  446.   rettype* cls::obj##name::operator()( atype a )                              \
  447.   {                                                                           \
  448.     if (! p##name)                                                            \
  449.       p##name = new rettype( pittype(0) );                                    \
  450.     if (p##name)                                                              \
  451.       BDTOOUTER( name, this )->Call##name( a, *p##name );                     \
  452.     return p##name;                                                           \
  453.   }
  454.  
  455. #define DEFINE_BDTO_OBJECTMETHOD3( cls, rettype, pittype, name, atype, btype, ctype )\
  456.   cls::obj##name::obj##name()                                                 \
  457.   {                                                                           \
  458.     p##name = NULL;                                                           \
  459.   }                                                                           \
  460.   cls::obj##name::~obj##name()                                                \
  461.   {                                                                           \
  462.     if (p##name)                                                              \
  463.       delete p##name;                                                         \
  464.   }                                                                           \
  465.   rettype* cls::obj##name::operator()( atype a, btype b, ctype c )            \
  466.   {                                                                           \
  467.     if (! p##name)                                                            \
  468.       p##name = new rettype( pittype(0) );                                    \
  469.     if (p##name)                                                              \
  470.       BDTOOUTER( name, this )->Call##name( a, b, c, *p##name );               \
  471.     return p##name;                                                           \
  472.   }
  473.  
  474.  
  475. #endif // MISC_H
  476.