home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / WCEXCEPT.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  7KB  |  193 lines

  1. //
  2. //  wcexcept.h    Definitions for exception base classes.  These classes are
  3. //          Inherited by each of the WATCOM Container Classes
  4. //
  5. //  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  6. //
  7. #ifndef _WCEXCEPT_H_INCLUDED
  8. #define _WCEXCEPT_H_INCLUDED
  9.  
  10. #ifndef __cplusplus
  11. #error wcexcept.h is for use with C++
  12. #endif
  13.  
  14. #ifndef _WCDEFS_H_INCLUDED
  15.  #include <wcdefs.h>
  16. #endif
  17.  
  18. #if defined(_M_IX86)
  19.   #pragma pack(__push,1);
  20. #else
  21.   #pragma pack(__push,8);
  22. #endif
  23.  
  24. //
  25. //  The WCExcept class defines the exception handling for the WATCOM
  26. //  Container non-iterative classes.  The current errors supported are:
  27. //
  28. //    empty_container - if an invalid operation on an empty container object
  29. //            is attempted, this error can be thrown
  30. //    index_range    -- if an index value is not valid, this error can
  31. //                         be thrown.
  32. //    not_empty      -- if a container object which should be empty is being
  33. //            destroyed by the class destructor, this error can be
  34. //            thrown.
  35. //    not_unique     -- if an attempt to insert a value into a set which
  36. //            previously contained an equivalent value is made, this
  37. //            error can be thrown.
  38. //    out_of_memory  -- if an attempt to allocate memory fails, this error
  39. //                   can be thrown.
  40. //    resize_required - if an attempt was made to insert into a full vector,
  41. //            or index a position with index length or greater in
  42. //            WCValVector or WCPtrVector, this exception can be
  43. //            thrown. If this exception is disabled, the necessary
  44. //            resize will be performed.
  45. //    zero_buckets   -- if an attempt to resize a hash table, hash set, or
  46. //            hash dictionary to zero buckets, this error can be
  47. //            thrown
  48. //
  49.  
  50. class WCExcept {
  51. private:
  52.     int             exception_flags;
  53.  
  54. protected:
  55.     inline void base_construct( const WCExcept * orig ) {
  56.     exception_flags = orig->exception_flags;
  57.     }
  58.     _WPRTLINK void base_throw_empty_container() const;
  59.     _WPRTLINK void base_throw_index_range() const;
  60.     //
  61.     // non-const since it disables the object's exceptions to try and prevent
  62.     // more than one exception being thrown
  63.     //
  64.     _WPRTLINK void base_throw_not_empty();
  65.     _WPRTLINK void base_throw_not_unique() const;
  66.     _WPRTLINK void base_throw_out_of_memory() const;
  67.     _WPRTLINK void base_throw_resize_required() const;
  68.     _WPRTLINK void base_throw_zero_buckets() const;
  69.  
  70. public:
  71.     inline WCExcept() : exception_flags(0) {};
  72.     inline virtual ~WCExcept() {};
  73.  
  74.     enum wcstate {                // Error state
  75.         all_fine          = 0x0000,    // - no errors
  76.         check_none         = all_fine,    // - don't throw any exceptions
  77.         not_empty         = 0x0001,    // - container not empty on destruction
  78.         index_range       = 0x0002,    // - index is out of range
  79.         empty_container    = 0x0004,    // - invalid request on empty container
  80.     out_of_memory     = 0x0008,    // - allocation failed
  81.     resize_required    = 0x0010,    // - resize required for request
  82.     not_unique    = 0x0020,    // - adding duplicate value to set
  83.     zero_buckets    = 0x0040,    // - resizing hash to zero buckets
  84.  
  85.         // value to use to check for all errors (all exceptions enabled)
  86.         check_all   = (not_empty|index_range|empty_container|out_of_memory
  87.               |resize_required|not_unique|zero_buckets)
  88.     };
  89.  
  90.     typedef int wc_state;
  91.  
  92.     // For back compatiblity
  93.     typedef wc_state wclist_state;
  94.  
  95.     // this object is thrown on an exception
  96.     class failure : public __WATCOM_exception {
  97.     private:
  98.         wc_state    _cause;
  99.     public:
  100.         failure( wc_state state ) : _cause( state ) {};
  101.         wc_state cause() const {
  102.             return( _cause );
  103.         };
  104.     };
  105.  
  106.     inline wc_state exceptions() const {
  107.         return( exception_flags );
  108.     }
  109.  
  110.     inline wc_state exceptions( wc_state const flag_set ) {
  111.         wc_state old_flags = exception_flags;
  112.         exception_flags = flag_set;
  113.         return( old_flags );
  114.     }
  115. };
  116.  
  117.  
  118. // For back compatiblity
  119. typedef WCExcept WCListExcept;
  120.  
  121.  
  122.  
  123.  
  124. //
  125. //  The WCIterExcept class defines the exception handling for WATCOM Container
  126. //  iterator classes.  The current errors supported are:
  127. //
  128. //      iter_range  -- the iterator advance value for the += or -= operators
  129. //               cannot be non-positive
  130. //      undef_item  -- if an iterator is outside the bounds of the object,
  131. //               or the iterator was never initialized with an object,
  132. //               this error can be thrown on call to the current member
  133. //               function (or the key and value member functions on
  134. //               an iterator for a dictionary).
  135. //      undef_iter  -- if an iterator is outside the bounds of the object, or
  136. //               if the iterator was never initialized with a object,
  137. //                     this error can be thrown on an invalid operation
  138. //               other than a call to the member function current (or
  139. //               the key and value member functions on an iterator for
  140. //               a dictionary).
  141. //
  142.  
  143. class WCIterExcept {
  144. private:
  145.     int exception_flags;
  146.  
  147. protected:
  148.     _WPRTLINK void base_throw_iter_range() const;
  149.     _WPRTLINK void base_throw_undef_item() const;
  150.     _WPRTLINK void base_throw_undef_iter() const;
  151.  
  152. public:
  153.     inline WCIterExcept() : exception_flags(0) {};
  154.     inline virtual ~WCIterExcept() {};
  155.  
  156.     enum wciterstate {                  // Error state
  157.         all_fine    = 0x0000,           // - no errors
  158.         check_none  = all_fine,        // - don't throw any exceptions
  159.         undef_iter  = 0x0001,           // - iterator position is undefined
  160.         undef_item  = 0x0002,           // - current iterator item is undefined
  161.         iter_range  = 0x0004,           // - iterator advance value is bad
  162.  
  163.         // value to use to check for all errors
  164.         check_all   = (undef_iter|undef_item|iter_range)
  165.     };
  166.     typedef int wciter_state;
  167.  
  168.     // this object is thrown on an exception
  169.     class failure : public __WATCOM_exception {
  170.     private:
  171.         wciter_state    _cause;
  172.     public:
  173.         failure( wciter_state state ) : _cause( state ) {};
  174.         wciter_state cause() const {
  175.             return( _cause );
  176.         };
  177.     };
  178.  
  179.     inline wciter_state exceptions() const {
  180.         return( exception_flags );
  181.     }
  182.  
  183.     inline wciter_state exceptions( wciter_state flag_set ) {
  184.         wciter_state old_flags = exception_flags;
  185.         exception_flags = flag_set;
  186.         return( old_flags );
  187.     }
  188. };
  189.  
  190. #pragma pack(__pop);
  191.  
  192. #endif
  193.