// -*- C++ -*-
#define _COMPARABLE_C_
#pragma implementation
/* [ec2 3.1.2.2]
 *
 *
 *
 * source file: /usr2/Src/eon/eiffel/3122/bibt/comparab.e
 *
 */

#ident "@(#)class_txt:comparab"
//
// Class: COMPARABLE (#14), Cluster: "bibt"
// Version: 1.0.0.2, Built by: root, on: 09:14:28 Jan 23 1995
//
#include <comparab.H>

void* COMPARABLE::_rev_cvt ( int _type)
{
   switch ( _type) {
      case 16: return (ANY*) this;
      case 17: return (PLATFORM*) this;
      case 18: return (GENERAL*) this;
   }
   return (COMPARABLE*) this;
}


COMPARABLE* COMPARABLE::_ert_cvt_to_class ( void *_v, int _type)
{
   COMPARABLE* _tmp;

   switch ( _type) {
      case 16: _tmp = (COMPARABLE*) ((ANY*)_v)->_BaseType ( 16); break;
      case 17: _tmp = (COMPARABLE*) ((PLATFORM*)_v)->_BaseType ( 17); break;
      case 18: _tmp = (COMPARABLE*) ((GENERAL*)_v)->_BaseType ( 18); break;
      default: _tmp = (COMPARABLE*) _v;
   }
   return _tmp;
}


COMPARABLE::COMPARABLE()
{
   _ert_expand++;
   _ert_expand--;
#ifdef NO_OPTIMISATION
   
#ifdef EIFFEL_ASSERT
   _class_assert = _set_class_assert ( 0x1f);
   _doing_invar = 0;
#endif // EIFFEL_ASSERT
#endif // NO_OPTIMISATION

   class_id = _ert_INTEGER_Const ( 14);
   _rescuing = 0;
   ANY::_base_id = class_id;
   PLATFORM::_base_id = class_id;
   GENERAL::_base_id = class_id;
   c_object_address = (POINTER)this;
   c_class_name = (POINTER)"COMPARABLE";
   bit_size = _ert_INTEGER_Const ( sizeof(*this) * BYTE_SIZE);
}
// Is current element less than `other'?
BOOLEAN COMPARABLE::_INFIX_LT ( COMPARABLE* other)
{
   BOOLEAN result = (BOOLEAN) 0;
#ifdef NO_OPTIMISATION
#endif // NO_OPTIMISATION
#ifdef NO_OPTIMISATION
#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s+++ COMPARABLE._INFIX_LT\n", (_ert_trace_depth++ * 3), "");
#endif // EIFFEL_TRACE

   _eiffel_rt_Assert( EXCEPT_NESTED_FUNCTIONS, "COMPARABLE", "_INFIX_LT", "env table size exceeded", (_ert_depth != _ERT_JMP_MAX - 1), (_ert_longjmp()));

#endif // NO_OPTIMISATION
   _ert_cenv[ _ert_depth].caddr = this;
   if ( setjmp ( _ert_cenv[ _ert_depth++].jmpenv)) {
      if ( _rescuing) {
         _rescuing--;
         _eiffel_rt_Assert ( 115, "COMPARABLE", "_INFIX_LT", "", false, (_ert_depth--,_ert_longjmp()));
      }
      goto _rescue;
   }

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT) && defined (EIFFEL_TRACE)
   if ( _class_assert) {
      if ( _doing_invar == 0)
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \"<\"", _make_arg_list ( "other", other, 14, (char *) 0));
      else
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \"<\"", _make_arg_list ( 0));
   }
#endif // EIFFEL_ASSERT && EIFFEL_TRACE
#endif // NO_OPTIMISATION

// Routine body "_INFIX_LT"

   _eiffel_rt_Assert ( 109, "COMPARABLE", "Infix \"<\"", "", false, (_ert_longjmp()));
#ifdef NO_OPTIMISATION

#if defined (EIFFEL_ASSERT) && defined ( EA_ENSURE)
   if ( !_ert_in_assertion && _class_assert & 0x2) {
      _ert_in_assertion++;

      _eiffel_rt_Assert ( 101, "COMPARABLE", "_INFIX_LT", "condition: 1", _ert_BOOLEAN_IMPLIES (result,  ( !  ( (Current->_INFIX_GEQ ( other))))), _ert_longjmp());
      _ert_in_assertion--;

   }
#endif // EIFFEL_ASSERT && EA_ENSURE
#endif // NO_OPTIMISATION

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT)
#if defined (EA_INVARIANT)
   _class_invariant("_INFIX_LT");

#endif // EA_INVARIANT

   if ( _class_assert)
      _leave_routine();
#endif // EIFFEL_ASSERT

#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s--- COMPARABLE._INFIX_LT\n", (--_ert_trace_depth * 3), "");
#endif // EIFFEL_TRACE
#endif // NO_OPTIMISATION
   _ert_depth--;

   return result ? true : false;

_rescue:
   _rescuing++;

#ifdef EIFFEL_TRACE
   _ert_trace_log ( "COMPARABLE", "Infix \"<\"", EXCEPT_FAIL, _ert_depth);
#endif

   if ( _class_assert)
      _leave_routine();

   _rescuing--;
   _eiffel_rt_Assert ( 106, "COMPARABLE", "_INFIX_LT", "", false, (_ert_depth--,_ert_longjmp()));
   return (BOOLEAN) 0;
}  // _INFIX_LT

// Is current element less than or equal to `other'?
BOOLEAN COMPARABLE::_INFIX_LEQ ( COMPARABLE* other)
{
   BOOLEAN result = (BOOLEAN) 0;
#ifdef NO_OPTIMISATION
#endif // NO_OPTIMISATION
#ifdef NO_OPTIMISATION
#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s+++ COMPARABLE._INFIX_LEQ\n", (_ert_trace_depth++ * 3), "");
#endif // EIFFEL_TRACE

   _eiffel_rt_Assert( EXCEPT_NESTED_FUNCTIONS, "COMPARABLE", "_INFIX_LEQ", "env table size exceeded", (_ert_depth != _ERT_JMP_MAX - 1), (_ert_longjmp()));

#endif // NO_OPTIMISATION
   _ert_cenv[ _ert_depth].caddr = this;
   if ( setjmp ( _ert_cenv[ _ert_depth++].jmpenv)) {
      if ( _rescuing) {
         _rescuing--;
         _eiffel_rt_Assert ( 115, "COMPARABLE", "_INFIX_LEQ", "", false, (_ert_depth--,_ert_longjmp()));
      }
      goto _rescue;
   }

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT) && defined (EIFFEL_TRACE)
   if ( _class_assert) {
      if ( _doing_invar == 0)
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \"<=\"", _make_arg_list ( "other", other, 14, (char *) 0));
      else
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \"<=\"", _make_arg_list ( 0));
   }
#endif // EIFFEL_ASSERT && EIFFEL_TRACE
#endif // NO_OPTIMISATION

// Routine body "_INFIX_LEQ"

   result = !  ( (other->_INFIX_LT ( Current))) ? true : false;


//Routine body "_INFIX_LEQ" ends...
#ifdef NO_OPTIMISATION

#if defined (EIFFEL_ASSERT) && defined ( EA_ENSURE)
   if ( !_ert_in_assertion && _class_assert & 0x2) {
      _ert_in_assertion++;

      _eiffel_rt_Assert ( 101, "COMPARABLE", "_INFIX_LEQ", "condition: 1", _ert_BOOLEAN_IMPLIES (result,  ( !  ( (Current->_INFIX_GT ( other))))), _ert_longjmp());
      _ert_in_assertion--;

   }
#endif // EIFFEL_ASSERT && EA_ENSURE
#endif // NO_OPTIMISATION

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT)
#if defined (EA_INVARIANT)
   _class_invariant("_INFIX_LEQ");

#endif // EA_INVARIANT

   if ( _class_assert)
      _leave_routine();
#endif // EIFFEL_ASSERT

#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s--- COMPARABLE._INFIX_LEQ\n", (--_ert_trace_depth * 3), "");
#endif // EIFFEL_TRACE
#endif // NO_OPTIMISATION
   _ert_depth--;

   return result ? true : false;

_rescue:
   _rescuing++;

#ifdef EIFFEL_TRACE
   _ert_trace_log ( "COMPARABLE", "Infix \"<=\"", EXCEPT_FAIL, _ert_depth);
#endif

   default_rescue ();
   if ( _class_assert)
      _leave_routine();

   _rescuing--;
   _eiffel_rt_Assert ( 106, "COMPARABLE", "_INFIX_LEQ", "", false, (_ert_depth--,_ert_longjmp()));
   return (BOOLEAN) 0;
}  // _INFIX_LEQ

// Is current element greater than `other'?
BOOLEAN COMPARABLE::_INFIX_GT ( COMPARABLE* other)
{
   BOOLEAN result = (BOOLEAN) 0;
#ifdef NO_OPTIMISATION
#endif // NO_OPTIMISATION
#ifdef NO_OPTIMISATION
#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s+++ COMPARABLE._INFIX_GT\n", (_ert_trace_depth++ * 3), "");
#endif // EIFFEL_TRACE

   _eiffel_rt_Assert( EXCEPT_NESTED_FUNCTIONS, "COMPARABLE", "_INFIX_GT", "env table size exceeded", (_ert_depth != _ERT_JMP_MAX - 1), (_ert_longjmp()));

#endif // NO_OPTIMISATION
   _ert_cenv[ _ert_depth].caddr = this;
   if ( setjmp ( _ert_cenv[ _ert_depth++].jmpenv)) {
      if ( _rescuing) {
         _rescuing--;
         _eiffel_rt_Assert ( 115, "COMPARABLE", "_INFIX_GT", "", false, (_ert_depth--,_ert_longjmp()));
      }
      goto _rescue;
   }

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT) && defined (EIFFEL_TRACE)
   if ( _class_assert) {
      if ( _doing_invar == 0)
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \">\"", _make_arg_list ( "other", other, 14, (char *) 0));
      else
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \">\"", _make_arg_list ( 0));
   }
#endif // EIFFEL_ASSERT && EIFFEL_TRACE
#endif // NO_OPTIMISATION

// Routine body "_INFIX_GT"

   result = (other->_INFIX_LT ( Current)) ? true : false;


//Routine body "_INFIX_GT" ends...
#ifdef NO_OPTIMISATION

#if defined (EIFFEL_ASSERT) && defined ( EA_ENSURE)
   if ( !_ert_in_assertion && _class_assert & 0x2) {
      _ert_in_assertion++;

      _eiffel_rt_Assert ( 101, "COMPARABLE", "_INFIX_GT", "condition: 1", _ert_BOOLEAN_IMPLIES (result,  ( !  ( (Current->_INFIX_LEQ ( other))))), _ert_longjmp());
      _ert_in_assertion--;

   }
#endif // EIFFEL_ASSERT && EA_ENSURE
#endif // NO_OPTIMISATION

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT)
#if defined (EA_INVARIANT)
   _class_invariant("_INFIX_GT");

#endif // EA_INVARIANT

   if ( _class_assert)
      _leave_routine();
#endif // EIFFEL_ASSERT

#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s--- COMPARABLE._INFIX_GT\n", (--_ert_trace_depth * 3), "");
#endif // EIFFEL_TRACE
#endif // NO_OPTIMISATION
   _ert_depth--;

   return result ? true : false;

_rescue:
   _rescuing++;

#ifdef EIFFEL_TRACE
   _ert_trace_log ( "COMPARABLE", "Infix \">\"", EXCEPT_FAIL, _ert_depth);
#endif

   default_rescue ();
   if ( _class_assert)
      _leave_routine();

   _rescuing--;
   _eiffel_rt_Assert ( 106, "COMPARABLE", "_INFIX_GT", "", false, (_ert_depth--,_ert_longjmp()));
   return (BOOLEAN) 0;
}  // _INFIX_GT

// Is current element greater than or equal to `other'?
BOOLEAN COMPARABLE::_INFIX_GEQ ( COMPARABLE* other)
{
   BOOLEAN result = (BOOLEAN) 0;
#ifdef NO_OPTIMISATION
#endif // NO_OPTIMISATION
#ifdef NO_OPTIMISATION
#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s+++ COMPARABLE._INFIX_GEQ\n", (_ert_trace_depth++ * 3), "");
#endif // EIFFEL_TRACE

   _eiffel_rt_Assert( EXCEPT_NESTED_FUNCTIONS, "COMPARABLE", "_INFIX_GEQ", "env table size exceeded", (_ert_depth != _ERT_JMP_MAX - 1), (_ert_longjmp()));

#endif // NO_OPTIMISATION
   _ert_cenv[ _ert_depth].caddr = this;
   if ( setjmp ( _ert_cenv[ _ert_depth++].jmpenv)) {
      if ( _rescuing) {
         _rescuing--;
         _eiffel_rt_Assert ( 115, "COMPARABLE", "_INFIX_GEQ", "", false, (_ert_depth--,_ert_longjmp()));
      }
      goto _rescue;
   }

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT) && defined (EIFFEL_TRACE)
   if ( _class_assert) {
      if ( _doing_invar == 0)
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \">=\"", _make_arg_list ( "other", other, 14, (char *) 0));
      else
         _enter_routine ( c_object_address, "COMPARABLE", "Infix \">=\"", _make_arg_list ( 0));
   }
#endif // EIFFEL_ASSERT && EIFFEL_TRACE
#endif // NO_OPTIMISATION

// Routine body "_INFIX_GEQ"

   result = !  ( (Current->_INFIX_LT ( other))) ? true : false;


//Routine body "_INFIX_GEQ" ends...
#ifdef NO_OPTIMISATION

#if defined (EIFFEL_ASSERT) && defined ( EA_ENSURE)
   if ( !_ert_in_assertion && _class_assert & 0x2) {
      _ert_in_assertion++;

      _eiffel_rt_Assert ( 101, "COMPARABLE", "_INFIX_GEQ", "condition: 1", _ert_BOOLEAN_IMPLIES (result,  ( !  ( (Current->_INFIX_LT ( other))))), _ert_longjmp());
      _ert_in_assertion--;

   }
#endif // EIFFEL_ASSERT && EA_ENSURE
#endif // NO_OPTIMISATION

#ifdef NO_OPTIMISATION
#if defined (EIFFEL_ASSERT)
#if defined (EA_INVARIANT)
   _class_invariant("_INFIX_GEQ");

#endif // EA_INVARIANT

   if ( _class_assert)
      _leave_routine();
#endif // EIFFEL_ASSERT

#ifdef EIFFEL_TRACE
   if ( _ert_trace_mode)
      printf ( "%*s--- COMPARABLE._INFIX_GEQ\n", (--_ert_trace_depth * 3), "");
#endif // EIFFEL_TRACE
#endif // NO_OPTIMISATION
   _ert_depth--;

   return result ? true : false;

_rescue:
   _rescuing++;

#ifdef EIFFEL_TRACE
   _ert_trace_log ( "COMPARABLE", "Infix \">=\"", EXCEPT_FAIL, _ert_depth);
#endif

   default_rescue ();
   if ( _class_assert)
      _leave_routine();

   _rescuing--;
   _eiffel_rt_Assert ( 106, "COMPARABLE", "_INFIX_GEQ", "", false, (_ert_depth--,_ert_longjmp()));
   return (BOOLEAN) 0;
}  // _INFIX_GEQ

#ifdef NO_OPTIMISATION

#if defined (EIFFEL_ASSERT) && defined (EA_INVARIANT)
void
COMPARABLE::_class_invariant ( char* rtn)
{
   if ( _doing_invar++)
      return;

   if ( ! (_class_assert & 0x4))
      return;
   _doing_invar = 0;

   return;
}
#endif // EIFFEL_ASSERT && EA_INVARIANT
#endif // NO_OPTIMISATION

void COMPARABLE::_Copy( INTEGER deep, INTEGER sclass, COMPARABLE* _arg)
{

   if ( deep) {
      if ( sclass) ANY::_Copy ( 1, 0, _arg);
      if ( sclass) PLATFORM::_Copy ( 1, 0, _arg);
      if ( sclass) GENERAL::_Copy ( 1, 0, _arg);
   }
}

COMPARABLE* COMPARABLE::_localClone( INTEGER deep, INTEGER sclass)
{
   COMPARABLE* result;

   result = new COMPARABLE;


   if ( deep) {
      if ( sclass) ANY::_localClone (1, 0);
      if ( sclass) PLATFORM::_localClone (1, 0);
      if ( sclass) GENERAL::_localClone (1, 0);
   }

   return result;
}

COMPARABLE* COMPARABLE::_Clone( INTEGER deep, INTEGER sclass, COMPARABLE* _arg)
{
   COMPARABLE* result;

   result = new COMPARABLE;

   result->_Copy ( deep, sclass, _arg);

   return result;
}

BOOLEAN COMPARABLE::_Equal ( INTEGER deep, INTEGER sclass, COMPARABLE* _arg)
{

   if ( deep) {
      if ( sclass) if ( ANY::_Equal ( 1, 0, _arg) == false) return false;
      if ( sclass) if ( PLATFORM::_Equal ( 1, 0, _arg) == false) return false;
      if ( sclass) if ( GENERAL::_Equal ( 1, 0, _arg) == false) return false;
   }

   return true;
}

BOOLEAN COMPARABLE::_Conforms_to ( INTEGER other_id)
{
   INTEGER Parents[3] = { 16, 17, 18}, i;

   if ( class_id == other_id)
      return true;

   for ( i = 0; i < 3; i++)
      if ( Parents[i] == (int)other_id)
         return true;

   return false;
}

void COMPARABLE::_Add_gp ( )
{
   _gp_ids[0] = 0;
}

#ifdef NO_OPTIMISATION
COMPARABLE *_COMPARABLE_chk(COMPARABLE *rtc, char *fname)
{
   if ( !rtc)
      _eiffel_rt_Assert ( 107, "COMPARABLE", fname, "void target", 
			false, _ert_longjmp());
   return rtc;
}
#endif // NO_OPTIMISATION
   void COMPARABLE::copy (COMPARABLE* p1) { _Copy(0,1,p1); }
   void COMPARABLE::deep_copy (COMPARABLE* p1) { _Copy(1,1,p1); }
   COMPARABLE* COMPARABLE::clone (COMPARABLE* p1) { return p1->_Clone(0,1,p1); }
   COMPARABLE* COMPARABLE::deep_clone (COMPARABLE* p1) { return p1->_Clone(1,1,p1); }
   void COMPARABLE::standard_copy (COMPARABLE* p1) { _Copy(0,1,p1); }
   void COMPARABLE::standard_deep_copy (COMPARABLE* p1) { _Copy(1,1,p1); }
   COMPARABLE* COMPARABLE::standard_clone (COMPARABLE* p1) { return p1->_Clone(0,1,p1); }
   COMPARABLE* COMPARABLE::standard_deep_clone (COMPARABLE* p1) { return p1->_Clone(1,1,p1); }


