Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

MRAcrange.cpp

Go to the documentation of this file.
00001 // MRAcrange.cpp
00002 //////////////////////////////////////////////////////////////////////
00003 //          (c) Copyright 2002 Brown Deer Technology, LLC.
00004 //                        All rights reserved.
00005 //////////////////////////////////////////////////////////////////////
00006 
00007 #ifdef USE_STD
00008 #include <iostream>
00009 using namespace std;
00010 #else
00011 #include <iostream.h>
00012 #endif
00013 
00014 #include "BufferBase.h"
00015 #include "MRAclevel.h"
00016 
00017 #include "MRAcrange.h"
00018 
00019 // ##### overloaded namespace functions #####
00020 
00021 bool equal( MRAcrange lhs, MRAcrange rhs ) 
00022 {
00023    if ( lhs._state != rhs._state ) return false;
00024    if ( lhs.cmin != rhs.cmin ) return false;
00025    if ( lhs.cmax != rhs.cmax ) return false;
00026    return true;
00027 }
00028 
00029 bool contains( MRAcrange lhs, MRAcrange rhs )
00030 {
00031    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) return false;
00032    if ( rhs.is_empty() ) return true;
00033    if ( lhs.is_empty() ) return false;
00034    if ( int(rhs.cmin) < int(lhs.cmin) || int(rhs.cmax) > int(lhs.cmax) ) 
00035       return false;
00036    return true;
00037 }
00038 
00039 bool disjoint( MRAcrange lhs, MRAcrange rhs )
00040 {
00041    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) return false;
00042    if ( lhs.is_empty() || rhs.is_empty() ) return false;
00043    if ( lhs <= rhs || lhs >= rhs ) return false;
00044    if ( int(lhs.cmin) < int(rhs.cmin) && int(lhs.cmax) < int(rhs.cmin) ) 
00045       return true;
00046    if ( int(lhs.cmin) > int(rhs.cmax) && int(lhs.cmax) > int(rhs.cmax) ) 
00047       return true;
00048    return false;
00049 }
00050 
00051 bool connected( MRAcrange lhs, MRAcrange rhs )
00052 {
00053    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) return false;
00054    if ( lhs.is_empty() || rhs.is_empty() ) return false;
00055    if ( lhs <= rhs || lhs >= rhs ) return true;
00056    if ( int(lhs.cmin) <= int(rhs.cmin) && int(lhs.cmax) >= int(rhs.cmin) - 1 ) 
00057       return true;
00058    if ( int(lhs.cmax) >= int(rhs.cmax) && int(lhs.cmin) <= int(rhs.cmax) + 1 ) 
00059       return true;
00060    return false;
00061 }
00062 
00063 bool interior( MRAcrange lhs, MRAcrange rhs )
00064 {
00065    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) return false;
00066    if ( lhs.is_empty() || rhs.is_empty() ) return false;
00067    if ( lhs >= rhs || disjoint( lhs, rhs ) ) return false;
00068    if ( int(lhs.cmin) <= int(rhs.cmin) || int(lhs.cmax) >= int(rhs.cmax) ) 
00069       return false;
00070    return true;
00071 }
00072 
00073 MRAcrange Union( MRAcrange lhs, MRAcrange rhs )
00074 {
00075    MRAcrange crange;
00076    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) {
00077       crange.clrstate(MRAcrange::goodbit);
00078       crange.setstate(MRAcrange::failbit);
00079    } else if ( rhs.is_empty() ) {
00080       crange = lhs;
00081    } else if ( lhs.is_empty() ) {
00082       crange = rhs;
00083    } else if ( !connected( lhs, rhs ) ) {
00084       crange.clrstate(MRAcrange::goodbit);
00085       crange.setstate(MRAcrange::failbit);
00086       crange.setstate(MRAcrange::fragbit);
00087    } else {
00088       crange = lhs;
00089       if ( int(rhs.cmin) < int(crange.cmin) ) crange.cmin = rhs.cmin;
00090       if ( int(rhs.cmax) > int(crange.cmin) ) crange.cmax = rhs.cmax;
00091    } 
00092    return crange;
00093 }
00094 
00095 MRAcrange Intersection( MRAcrange lhs, MRAcrange rhs )
00096 {
00097    MRAcrange crange;
00098    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) {
00099       crange.clrstate(MRAcrange::goodbit);
00100       crange.setstate(MRAcrange::failbit);
00101    } else if ( lhs.is_empty() ) {
00102       crange = lhs;
00103    } else if ( rhs.is_empty() ) {
00104       crange = rhs;
00105    } else if ( disjoint( lhs, rhs ) ) {
00106       crange.set_empty();
00107    } else {
00108       crange = lhs;
00109       if ( int(rhs.cmin) > int(crange.cmin) ) crange.cmin = rhs.cmin;
00110       if ( int(rhs.cmax) < int(crange.cmax) ) crange.cmax = rhs.cmax;
00111    } 
00112    return crange;
00113 }
00114 
00115 MRAcrange Difference( MRAcrange lhs, MRAcrange rhs )
00116 {
00117    MRAcrange crange;
00118    if ( !lhs.good() || !rhs.good() || !lhs || !rhs ) {
00119       crange.clrstate(MRAcrange::goodbit);
00120       crange.setstate(MRAcrange::failbit);
00121    } else if ( lhs.is_empty() ) {
00122       crange = lhs;
00123    } else if ( rhs.is_empty() ) {
00124       crange = rhs;
00125    } else if ( disjoint( lhs, rhs ) ) {
00126       crange = lhs;
00127    } else if ( lhs == rhs ) {
00128       crange.set_empty();
00129    } else if ( lhs < rhs ) {
00130       crange.set_empty();
00131    } else if ( interior( lhs, rhs) ) {
00132       crange.clrstate(MRAcrange::goodbit);
00133       crange.setstate(MRAcrange::failbit);
00134       crange.setstate(MRAcrange::fragbit);
00135    } else {
00136       if ( interior( rhs, lhs ) ) {
00137          crange = lhs;
00138          crange.clrstate(MRAcrange::goodbit);
00139          crange.setstate(MRAcrange::failbit);
00140          crange.setstate(MRAcrange::fragbit);
00141       } else {
00142          crange = lhs; 
00143          if ( int(rhs.cmin) > int(lhs.cmin) ) crange.cmax = rhs.cmin - 1;
00144          if ( int(rhs.cmax) < int(lhs.cmax) ) crange.cmin = rhs.cmax + 1;
00145       }
00146    } 
00147    return crange;
00148 }
00149 
00150 // ##### class member functions #####
00151 
00152 MRAcrange& MRAcrange::Union( MRAcrange rhs )
00153 {
00154    if ( !good() || !rhs.good() || is_null() || !rhs ) {
00155       clrstate(MRAcrange::goodbit);
00156       setstate(MRAcrange::failbit);
00157    } else if ( rhs.is_empty() ) {
00158       return *this;
00159    } else if ( is_empty() ) {
00160       *this = rhs;
00161    } else if ( !connected( *this, rhs ) ) {
00162       clrstate(MRAcrange::goodbit);
00163       setstate(MRAcrange::failbit);
00164       setstate(MRAcrange::fragbit);
00165    } else {
00166       if ( int(rhs.cmin) < int(cmin) ) cmin = rhs.cmin;
00167       if ( int(rhs.cmax) > int(cmin) ) cmax = rhs.cmax;
00168    } 
00169    return *this;
00170 }
00171 
00172 MRAcrange& MRAcrange::Intersection( MRAcrange rhs )
00173 {
00174    if ( !good() || !rhs.good() || is_null() || !rhs ) {
00175       clrstate(MRAcrange::goodbit);
00176       setstate(MRAcrange::failbit);
00177    } else if ( is_empty() ) {
00178       return *this;
00179    } else if ( rhs.is_empty() ) {
00180       *this = rhs;
00181    } else if ( disjoint( *this, rhs ) ) {
00182       set_empty();
00183    } else {
00184       if ( int(rhs.cmin) > int(cmin) ) cmin = rhs.cmin;
00185       if ( int(rhs.cmax) < int(cmax) ) cmax = rhs.cmax;
00186    } 
00187    return *this;
00188 }
00189 
00190 MRAcrange& MRAcrange::Difference( MRAcrange rhs )
00191 {
00192    if ( !good() || !rhs.good() || is_null() || !rhs ) {
00193       clrstate(MRAcrange::goodbit);
00194       setstate(MRAcrange::failbit);
00195    } else if ( is_empty() ) {
00196       return *this;
00197    } else if ( rhs.is_empty() ) {
00198       *this = rhs;
00199    } else if ( disjoint( *this, rhs ) ) {
00200       return *this;;
00201    } else if ( *this == rhs ) {
00202       set_empty();
00203    } else if ( *this < rhs ) {
00204       set_empty();
00205    } else if ( interior( *this, rhs) ) {
00206       clrstate(MRAcrange::goodbit);
00207       setstate(MRAcrange::failbit);
00208       setstate(MRAcrange::fragbit);
00209    } else {
00210       if ( interior( rhs, *this ) ) {
00211          clrstate(MRAcrange::goodbit);
00212          setstate(MRAcrange::failbit);
00213          setstate(MRAcrange::fragbit);
00214       } else {
00215          if ( int(rhs.cmin) > int(cmin) ) cmax = rhs.cmin - 1;
00216          if ( int(rhs.cmax) < int(cmax) ) cmin = rhs.cmax + 1;
00217       }
00218    } 
00219    return *this;
00220 }
00221 

Generated on Mon May 31 21:38:50 2004 for SR2k4 Assembler by doxygen 1.3.6