Polaris: Relation.h Source File

Relation.h

Go to the documentation of this file.
00001 ///
00002 ///
00003 /// file Relation.h
00004 ///
00005 #ifndef _RELATION_H
00006 #define _RELATION_H
00007 ///
00008 /// \class Relation 
00009 /// \brief A set of algebraic relationships  {<,=,>}
00010 /// \defgroup Polaris
00011 /// \ingroup Polaris
00012 ///  Range
00013 /// \see Relation.h
00014 ///
00015 /// \endcode
00016 /// \section Overview Overview
00017 /// A Relation object represents a set of algebraic relationships
00018 /// {<,=,>}.
00019 ///
00020 #include <stream.h>
00021 ///
00022 class Relation {
00023  public:
00024     inline         Relation();
00025     ///< Construct a Relation with no relationships. 
00026 
00027     inline         Relation(bool less_than, bool equal,
00028                 bool greater_than);
00029     ///< Construct a Relation with the given algebraic relationships
00030 
00031     inline         Relation(const Relation &other);
00032     ///< Construct a copy of the given Relation
00033 
00034     inline         ~Relation();
00035     ///< Destructor
00036 
00037     inline void    less_than(bool value);
00038     inline void    equal(bool value);
00039     inline void    greater_than(bool value);
00040     inline void    circular(bool value);
00041     ///< Set/Clear the less than, equal, greater than, or
00042     ///< circular relationships
00043 
00044     inline bool is_less_than() const;
00045     inline bool is_less_equal() const;
00046     inline bool is_equal() const;
00047     inline bool is_not_equal() const;
00048     inline bool is_greater_than() const;
00049     inline bool is_greater_equal() const;
00050     inline bool is_unknown() const;
00051     inline bool is_circular() const;
00052     ///< Return whether the specified relationship holds
00053 
00054     inline Relation &operator = (const Relation &other);
00055     ///< Assignment operator
00056 
00057     inline Relation &operator &= (const Relation &other);
00058     inline Relation operator & (const Relation &other) const;
00059     ///< And operator.  Returns a relation that will return true for one
00060     ///< of the is_*() methods if and only if that method would return
00061     ///< true for both of the given relations.
00062 
00063     inline void    print(ostream &o) const;
00064     inline friend  ostream & operator << (ostream & o, const Relation & r);
00065     ///< Print the relation as one of {<,<=,==,!=,>,>=,?,@}
00066 
00067  private:
00068     bool        _may_be_less_than;
00069     bool        _may_be_equal;
00070     bool        _may_be_greater_than;
00071     bool        _may_be_circular;
00072 };
00073 
00074 
00075 ///< inline functions
00076 
00077 inline
00078 Relation::Relation()
00079 {
00080     #ifdef CLASS_INSTANCE_REGISTRY
00081     register_instance(RELATION_CLASS, sizeof(Relation), this);
00082     #endif
00083 
00084     _may_be_less_than    = false;
00085     _may_be_equal        = false;
00086     _may_be_greater_than = false;
00087     _may_be_circular     = false;
00088 }
00089 
00090 inline
00091 Relation::Relation(bool less_than, bool equal, bool greater_than)
00092 {
00093     #ifdef CLASS_INSTANCE_REGISTRY
00094     register_instance(RELATION_CLASS, sizeof(Relation), this);
00095     #endif
00096 
00097     _may_be_less_than    = less_than;
00098     _may_be_equal        = equal;
00099     _may_be_greater_than = greater_than;
00100     _may_be_circular = false;
00101 }
00102 
00103 inline
00104 Relation::Relation(const Relation &other)
00105 {
00106     #ifdef CLASS_INSTANCE_REGISTRY
00107     register_instance(RELATION_CLASS, sizeof(Relation), this);
00108     #endif
00109 
00110     _may_be_less_than = other._may_be_less_than;
00111     _may_be_equal = other._may_be_equal;
00112     _may_be_greater_than = other._may_be_greater_than;
00113     _may_be_circular = other._may_be_circular;
00114 }
00115 
00116 inline
00117 Relation::~Relation()
00118 {
00119     #ifdef CLASS_INSTANCE_REGISTRY
00120     unregister_instance(RELATION_CLASS, this);
00121     #endif
00122 
00123     ///< nothing to do
00124 }
00125 
00126 inline void
00127 Relation::less_than(bool value)
00128 {
00129     _may_be_less_than = value;
00130 }
00131 
00132 inline void
00133 Relation::equal(bool value)
00134 {
00135     _may_be_equal = value;
00136 }
00137 
00138 inline void
00139 Relation::greater_than(bool value)
00140 {
00141     _may_be_greater_than = value;
00142 }
00143 
00144 inline void
00145 Relation::circular(bool value)
00146 {
00147   _may_be_circular = value;
00148 }
00149 
00150 inline bool
00151 Relation::is_less_than() const
00152 {
00153     return (_may_be_less_than && ! _may_be_equal && ! _may_be_greater_than);
00154 }
00155 
00156 inline bool
00157 Relation::is_less_equal() const
00158 {
00159     return ((_may_be_less_than || _may_be_equal) && ! _may_be_greater_than);
00160 }
00161 
00162 inline bool
00163 Relation::is_equal() const
00164 {
00165     return (! _may_be_less_than && _may_be_equal && ! _may_be_greater_than);
00166 }
00167 
00168 inline bool
00169 Relation::is_not_equal() const
00170 {
00171     return (! _may_be_equal && (_may_be_less_than || _may_be_greater_than));
00172 }
00173 
00174 inline bool
00175 Relation::is_greater_than() const
00176 {
00177     return (! _may_be_less_than && ! _may_be_equal && _may_be_greater_than);
00178 }
00179 
00180 inline bool
00181 Relation::is_greater_equal() const
00182 {
00183     return (! _may_be_less_than && (_may_be_equal || _may_be_greater_than));
00184 }
00185 
00186 inline bool
00187 Relation::is_unknown() const
00188 {
00189     return ((! _may_be_less_than && ! _may_be_equal && ! _may_be_greater_than)
00190         || (_may_be_less_than && _may_be_equal && _may_be_greater_than));
00191 }
00192 
00193 inline bool
00194 Relation::is_circular() const
00195 {
00196     return _may_be_circular;
00197 }
00198 
00199 inline Relation &
00200 Relation::operator = (const Relation &other)
00201 {
00202     _may_be_less_than = other._may_be_less_than;
00203     _may_be_equal = other._may_be_equal;
00204     _may_be_greater_than = other._may_be_greater_than;
00205     _may_be_circular = other._may_be_circular;
00206 
00207     return *this;
00208 }
00209 
00210 inline Relation &
00211 Relation::operator &= (const Relation &other)
00212 {
00213     _may_be_less_than = _may_be_less_than && other._may_be_less_than;
00214     _may_be_equal = _may_be_equal && other._may_be_equal;
00215     _may_be_greater_than = _may_be_greater_than && other._may_be_greater_than;
00216     _may_be_circular = _may_be_circular && other._may_be_circular;
00217     return *this;
00218 }
00219 
00220 inline Relation
00221 Relation::operator & (const Relation &other) const
00222 {
00223     Relation result(*this);
00224     result &= other;
00225     return result;
00226 }
00227 
00228 inline void
00229 Relation::print(ostream &o) const
00230 {
00231     if (is_equal())
00232     o << "==";
00233     else if (is_less_than())
00234     o << "<";
00235     else if (is_less_equal())
00236     o << "<=";
00237     else if (is_greater_than())
00238     o << ">";
00239     else if (is_greater_equal())
00240     o << ">=";
00241     else if (is_not_equal())
00242     o << "!=";
00243     else
00244     o << "?";
00245     if (is_circular())
00246         o << "@";
00247 }
00248 
00249 inline ostream &
00250 operator << (ostream & o, const Relation & r)
00251 {
00252     r.print(o);
00253     return o;
00254 }
00255 
00256 #endif
00257 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:06 2005