Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Literal.hpp

Go to the documentation of this file.
00001 //
00002 //  file Literal.hpp
00003 //  defines class Literal
00004 //
00005 
00006 
00007 #ifndef __Literal__
00008 #define __Literal__
00009 
00010 
00011 #include "Atom.hpp"
00012 
00013 
00014 // ******************* class Literal, definition *********************
00015 
00016 
00017 class Literal {
00018  private:
00019   class Data;
00020 
00021  public:
00022   // constructor
00023   Literal ();
00024   Literal (bool sign, const Atom& atom);
00025   Literal (const Literal& t);
00026   Literal (const VampireKernel::Literal* lit, const VampireKernel& kernel);
00027   ~Literal ();
00028   void operator= (const Literal& rhs);
00029 
00030   // query/change the structure
00031   bool positive () const;
00032   bool negative () const;
00033   bool sign () const;
00034   const Atom& atom () const;
00035   bool exists () const;
00036 
00037   // various
00038   bool isless (Literal l) const;       // comparison, used for normalisation
00039   Compare compare (Literal l) const; // comparison, used for normalisation
00040   void normalize ();
00041   bool isRenamingOf (Literal l, Substitution& sbst) const;
00042  private:
00043   // structure
00044   Data* _data;
00045 }; // class Literal
00046 
00047 
00048 class Literal::Data 
00049 #   if DEBUG_PREPRO
00050     : public Memory <CID_LITERAL>
00051 #   endif
00052 {
00053  public:
00054   Data ();
00055   Data (bool sign, const Atom& atom);
00056 
00057   // structure access
00058   bool positive () const;
00059   bool negative () const;
00060   bool sign () const;
00061   const Atom& atom () const;
00062 
00063   void ref ();
00064   void deref ();
00065 
00066  protected:
00067   // structure
00068   int _counter;
00069   bool _sign;
00070   Atom _atom;
00071 }; // class Literal::Data
00072 
00073 
00074 class LiteralList 
00075 : public Lst<Literal>
00076 {
00077  public:
00078   // constructors
00079   LiteralList ();
00080   LiteralList (const LiteralList&);
00081   explicit LiteralList (const Literal& t); // one-element list
00082   LiteralList (const Literal& head, const LiteralList& tail);
00083   explicit LiteralList (LstData<Literal>*);
00084   LiteralList (const VampireKernel::Literal* lit, const VampireKernel& kernel);
00085 
00086   // inherited functions
00087   const LiteralList& tail () const
00088     { return static_cast<const LiteralList&>(Lst<Literal>::tail()); }
00089 
00090   // various
00091   bool isRenamingOf (LiteralList lst) const;
00092  private:
00093   bool isRenamingOf (LiteralList tried, LiteralList remaining, Substitution sbst) const;
00094 }; // class LiteralList
00095 
00096 
00097 // ******************* class Literal, implementation *********************
00098 
00099 
00100 inline
00101 Literal::Literal () 
00102   : 
00103   _data (0) 
00104 {
00105 } // Literal::Literal
00106 
00107 
00108 inline
00109 Literal::~Literal () 
00110 {
00111   if (_data) {
00112     _data->deref ();
00113   }
00114 } // Literal::~Literal
00115 
00116 
00117 inline
00118 Literal::Literal (const Literal& t)
00119   :
00120   _data (t._data)
00121 {
00122   if (_data) {
00123     _data->ref ();
00124   }
00125 } // Literal::Literal
00126 
00127 
00128 inline
00129 Literal::Literal (bool sign, const Atom& atom)
00130   :
00131   _data (new Data(sign,atom))
00132 {
00133 } // Literal::Literal (bool sign, const Atom& atom)
00134 
00135 
00136 inline
00137 bool Literal::exists () const 
00138 { 
00139   return _data != 0; 
00140 } // Literal::exists ()
00141 
00142 
00143 inline
00144 bool Literal::positive () const
00145 {
00146   return _data->sign();
00147 } // Literal::positive ()
00148 
00149 
00150 inline
00151 bool Literal::negative () const
00152 {
00153   return ! _data->sign();
00154 } // Literal::negative ()
00155 
00156 
00157 inline
00158 bool Literal::sign () const
00159 {
00160   return _data->sign();
00161 } // Literal::sign ()
00162 
00163 
00164 inline
00165 const Atom& Literal::atom () const
00166 {
00167   return _data->atom();
00168 } // Literal::Atom ()
00169 
00170 
00171 // **************** class Literal::Data implementation ******************
00172 
00173 
00174 inline
00175 Literal::Data::Data (bool sign, const Atom& atom) 
00176   : 
00177   _counter (1),
00178   _sign (sign), 
00179   _atom (atom)
00180 {
00181 } // Literal::Data::Data
00182 
00183 
00184 inline
00185 bool Literal::Data::sign () const 
00186 { 
00187   return _sign; 
00188 } // Literal::Data::sign ()
00189 
00190 
00191 inline
00192 const Atom& Literal::Data::atom () const 
00193 { 
00194   return _atom; 
00195 } // Literal::Data::atom ()
00196 
00197 
00198 inline
00199 void Literal::Data::ref () 
00200 { 
00201   ASS (this);
00202 
00203   _counter++;
00204 } // Literal::Data::ref ()
00205 
00206 
00207 inline
00208 void Literal::Data::deref () 
00209 { 
00210   ASS (this);
00211   ASS (_counter > 0);
00212   _counter--;
00213 
00214   if (_counter == 0) {
00215     delete this;
00216   }
00217 } // Literal::Data::deref ()
00218 
00219 
00220 // ******************* LiteralList definitions ************************
00221 
00222 inline
00223 LiteralList::LiteralList () 
00224   : 
00225   Lst<Literal> ()
00226 {
00227 } // LiteralList::LiteralList
00228 
00229 
00230 inline
00231 LiteralList::LiteralList (const LiteralList& ts)
00232   :
00233   Lst<Literal> (ts)
00234 {
00235 } // LiteralList::LiteralList
00236 
00237 
00238 inline
00239 LiteralList::LiteralList (LstData<Literal>* d)
00240   :
00241   Lst<Literal> (d)
00242 {
00243 } // LiteralList::LiteralList
00244 
00245 
00246 inline
00247 LiteralList::LiteralList (const Literal &hd, const LiteralList& tl)
00248   :
00249   Lst<Literal> (hd,tl)
00250 {
00251 } // LiteralList::LiteralList
00252 
00253 
00254 inline
00255 LiteralList::LiteralList (const Literal &hd)
00256   :
00257   Lst<Literal> (hd)
00258 {
00259 } // LiteralList::LiteralList
00260 
00261 
00262 #endif // Literal

Generated on Sat Jun 28 15:08:57 2003 for Vampire by doxygen 1.3.2