home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / TVINC.ZIP / OBJECTS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  6.5 KB  |  264 lines

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   OBJECTS.H                                                             */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes TPoint, TRect, TCollection, and TSortedCollection */
  9. /*                                                                         */
  10. /* ------------------------------------------------------------------------*/
  11.  
  12. #pragma option -Vo-
  13. #if defined( __BCOPT__ )
  14. #pragma option -po-
  15. #endif
  16.  
  17. #if defined( Uses_TPoint ) && !defined( __TPoint )
  18. #define __TPoint
  19.  
  20. class TPoint
  21. {
  22.  
  23. public:
  24.  
  25.     TPoint& operator+=( const TPoint& adder );
  26.     TPoint& operator-=( const TPoint& subber );
  27.     friend TPoint operator - ( const TPoint& one, const TPoint& two);
  28.     friend TPoint operator + ( const TPoint& one, const TPoint& two);
  29.     friend int operator == ( const TPoint& one, const TPoint& two);
  30.     friend int operator != ( const TPoint& one, const TPoint& two);
  31.  
  32.     int x,y;
  33.  
  34. };
  35.  
  36. inline TPoint& TPoint::operator += ( const TPoint& adder )
  37. {
  38.     x += adder.x;
  39.     y += adder.y;
  40.     return *this;
  41. }
  42.  
  43. inline TPoint& TPoint::operator -= ( const TPoint& subber )
  44. {
  45.     x -= subber.x;
  46.     y -= subber.y;
  47.     return *this;
  48. }
  49.  
  50. inline ipstream& operator >> ( ipstream& is, TPoint& p )
  51.     { return is >> p.x >> p.y; }
  52. inline ipstream& operator >> ( ipstream& is, TPoint*& p )
  53.     { return is >> p->x >> p->y; }
  54.  
  55. inline opstream& operator << ( opstream& os, TPoint& p )
  56.     { return os << p.x << p.y; }
  57. inline opstream& operator << ( opstream& os, TPoint* p )
  58.     { return os << p->x << p->y; }
  59.  
  60. #endif  // Uses_TPoint
  61.  
  62. #if defined( Uses_TRect ) && !defined( __TRect )
  63. #define __TRect
  64.  
  65. class TRect
  66. {
  67.  
  68. public:
  69.  
  70.     TRect( int ax, int ay, int bx, int by );
  71.     TRect( TPoint p1, TPoint p2 );
  72.     TRect();
  73.  
  74.     void move( int aDX, int aDY );
  75.     void grow( int aDX, int aDY );
  76.     void intersect( const TRect& r );
  77.     void Union( const TRect& r );
  78.     Boolean contains( const TPoint& p ) const;
  79.     Boolean operator == ( const TRect& r ) const;
  80.     Boolean operator != ( const TRect& r ) const;
  81.     Boolean isEmpty();
  82.  
  83.     TPoint a, b;
  84.  
  85. };
  86.  
  87. inline TRect::TRect( int ax, int ay, int bx, int by)
  88. {
  89.     a.x = ax;
  90.     a.y = ay;
  91.     b.x = bx;
  92.     b.y = by;
  93. }
  94.  
  95. inline TRect::TRect( TPoint p1, TPoint p2 )
  96. {
  97.     a = p1;
  98.     b = p2;
  99. }
  100.  
  101. inline TRect::TRect()
  102. {
  103. }
  104.  
  105. inline void TRect::move( int aDX, int aDY )
  106. {
  107.     a.x += aDX;
  108.     a.y += aDY;
  109.     b.x += aDX;
  110.     b.y += aDY;
  111. }
  112.  
  113. inline void TRect::grow( int aDX, int aDY )
  114. {
  115.     a.x -= aDX;
  116.     a.y -= aDY;
  117.     b.x += aDX;
  118.     b.y += aDY;
  119. }
  120.  
  121. inline void TRect::intersect( const TRect& r )
  122. {
  123.     a.x = max( a.x, r.a.x );
  124.     a.y = max( a.y, r.a.y );
  125.     b.x = min( b.x, r.b.x );
  126.     b.y = min( b.y, r.b.y );
  127. }
  128.  
  129. inline void TRect::Union( const TRect& r )
  130. {
  131.     a.x = min( a.x, r.a.x );
  132.     a.y = min( a.y, r.a.y );
  133.     b.x = max( b.x, r.b.x );
  134.     b.y = max( b.y, r.b.y );
  135. }
  136.  
  137. inline Boolean TRect::contains( const TPoint& p ) const
  138. {
  139.     return Boolean(
  140.         p.x >= a.x && p.x < b.x && p.y >= a.y && p.y < b.y
  141.         );
  142. }
  143.  
  144. inline Boolean TRect::operator == ( const TRect& r) const
  145. {
  146.     return Boolean( a == r.a && b == r.b );
  147. }
  148.  
  149. inline Boolean TRect::operator != ( const TRect& r ) const
  150. {
  151.     return Boolean( !(*this == r) );
  152. }
  153.  
  154. inline Boolean TRect::isEmpty()
  155. {
  156.     return Boolean( a.x >= b.x || a.y >= b.y );
  157. }
  158.  
  159. inline ipstream& operator >> ( ipstream& is, TRect& r )
  160.     { return is >> r.a >> r.b; }
  161. inline ipstream& operator >> ( ipstream& is, TRect*& r )
  162.     { return is >> r->a >> r->b; }
  163.  
  164. inline opstream& operator << ( opstream& os, TRect& r )
  165.     { return os << r.a << r.b; }
  166. inline opstream& operator << ( opstream& os, TRect* r )
  167.     { return os << r->a << r->b; }
  168.  
  169. #endif  // Uses_TRect
  170.  
  171. #if defined( Uses_TCollection ) && !defined( __TCollection )
  172. #define __TCollection
  173.  
  174. class TCollection : public virtual TNSCollection, public TStreamable
  175. {
  176.  
  177. public:
  178.  
  179.     TCollection( ccIndex aLimit, ccIndex aDelta )
  180.         { delta = aDelta; setLimit( aLimit ); }
  181.  
  182. private:
  183.  
  184.     virtual const char *streamableName() const
  185.         { return name; }
  186.  
  187.     virtual void *readItem( ipstream& ) = 0;
  188.     virtual void writeItem( void *, opstream& ) = 0;
  189.  
  190.  
  191. protected:
  192.  
  193.     TCollection( StreamableInit );
  194.     virtual void *read( ipstream& );
  195.     virtual void write( opstream& );
  196.  
  197. public:
  198.  
  199.     static const char * const near name;
  200.  
  201. };
  202.  
  203. inline ipstream& operator >> ( ipstream& is, TCollection& cl )
  204.     { return is >> (TStreamable&)cl; }
  205. inline ipstream& operator >> ( ipstream& is, TCollection*& cl )
  206.     { return is >> (void *&)cl; }
  207.  
  208. inline opstream& operator << ( opstream& os, TCollection& cl )
  209.     { return os << (TStreamable&)cl; }
  210. inline opstream& operator << ( opstream& os, TCollection* cl )
  211.     { return os << (TStreamable *)cl; }
  212.  
  213. #endif  // Uses_TCollection
  214.  
  215. #if defined( Uses_TSortedCollection ) && !defined( __TSortedCollection )
  216. #define __TSortedCollection
  217.  
  218. class TSortedCollection : public TNSSortedCollection, public TCollection
  219. {
  220.  
  221. public:
  222.  
  223.     TSortedCollection( ccIndex aLimit, ccIndex aDelta) :
  224.         TCollection( aLimit, aDelta ) {}
  225.  
  226. private:
  227.  
  228.     virtual int compare( void *key1, void *key2 ) = 0;
  229.  
  230.     virtual const char *streamableName() const
  231.         { return name; }
  232.     virtual void *readItem( ipstream& ) = 0;
  233.     virtual void writeItem( void *, opstream& ) = 0;
  234.  
  235. protected:
  236.  
  237.     TSortedCollection( StreamableInit );
  238.     virtual void *read( ipstream& );
  239.     virtual void write( opstream& );
  240.  
  241. public:
  242.  
  243.     static const char * const near name;
  244.  
  245. };
  246.  
  247. inline ipstream& operator >> ( ipstream& is, TSortedCollection& cl )
  248.     { return is >> (TStreamable&)cl; }
  249. inline ipstream& operator >> ( ipstream& is, TSortedCollection*& cl )
  250.     { return is >> (void *&)cl; }
  251.  
  252. inline opstream& operator << ( opstream& os, TSortedCollection& cl )
  253.     { return os << (TStreamable&)cl; }
  254. inline opstream& operator << ( opstream& os, TSortedCollection* cl )
  255.     { return os << (TStreamable *)cl; }
  256.  
  257. #endif  // Uses_TSortedCollection
  258.  
  259. #pragma option -Vo.
  260. #if defined( __BCOPT__ )
  261. #pragma option -po.
  262. #endif
  263.  
  264.