Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

api_deltabase.h

Go to the documentation of this file.
00001 // Delta implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2003 Hermann Schichl
00004 //
00005 // This file is part of the COCONUT API.  This library
00006 // is free software; you can redistribute it and/or modify it under the
00007 // terms of the Library GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // Library GNU General Public License for more details.
00015 
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the Library GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the Library GNU General Public License.
00024 
00030 #ifndef _API_DELTABASE_H_
00031 #define _API_DELTABASE_H_
00032 
00033 #include <coconut_config.h>
00034 #include <string>
00035 #include <database>
00036 
00037 #define DEBUG_DELTA 0
00038 
00039 class work_node;
00040 
00041 class delta_base;
00042 
00043 class undelta_base;
00044 
00045 typedef vdbl::rowid delta_id;
00046 
00047 class delta
00048 {
00049 private:
00050   delta_base* _d;
00051 
00052 public:
00053   delta() : _d(NULL) {}
00054 private:
00055   delta(delta_base* __d) : _d(__d) {}
00056 public:
00057   delta(const delta_base& __d);
00058   delta(const delta& __d);
00059 
00060   ~delta();
00061 
00062   const std::string& get_action() const;
00063   const delta_base* get_base() const;
00064 
00065   bool apply(work_node& _x, const delta_id& _d) const;
00066   bool apply3(work_node& _x, const work_node& _y, const delta_id& _d) const;
00067   void convert(work_node& _x);
00068   delta_id store(work_node& _x);
00069 
00070   delta& operator=(const delta& _d);
00071   
00072   friend std::ostream& operator<< (std::ostream& o, const delta& t);
00073   friend class delta_base;
00074   friend class ie_return_type;
00075 };
00076 
00077 inline std::ostream& operator<< (std::ostream& o, const delta& t)
00078 {
00079   o << "Don't know how to print a delta!";
00080   return o;
00081 }
00082 
00083 class delta_base
00084 {
00085 protected:
00086   std::string _action; 
00087 
00088 public:
00089   delta_base() : _action() {}
00090   delta_base(const std::string& a) : _action(a) {}
00091   delta_base(const char* a) : _action(std::string(a)) {}
00092   delta_base(const delta_base& __d) : _action(__d._action) {}
00093 
00094   virtual delta_base* new_copy() const { return new delta_base(*this); } // clone operation
00095   virtual void destroy_copy(delta_base* __d) { delete __d; }
00096 
00097   virtual ~delta_base() {}
00098 
00099   delta make_delta(const std::string& a)
00100   {
00101     delta_base* __tmp = new delta_base(a);
00102     return delta(__tmp);
00103   }
00104 
00105   const std::string& get_action() const { return _action; }
00106 
00107   virtual void convert(work_node& _x, delta_base*& _d)
00108      { _d = this; } 
00109 
00110   virtual bool apply(work_node& _x, undelta_base*& _u) const
00111      { _u = NULL; return false; }
00112 
00113   // these should be implemented better in each delta,
00114   // they, however, need not be
00115   virtual bool apply3(work_node& _x, const work_node& _y, undelta_base*& _u)
00116                                                                         const;
00117 };
00118 
00119 class undelta
00120 {
00121 private:
00122   undelta_base* _d;
00123 
00124 public:
00125   undelta() : _d(NULL) {}
00126   undelta(undelta_base* __d) : _d(__d) {}
00127   undelta(const undelta& __d);
00128 
00129   ~undelta();
00130 
00131   const undelta_base* get_base() const;
00132 
00133   bool unapply(work_node& _x) const;
00134   bool unapply3(work_node& _x, const work_node& _y) const;
00135   
00136   undelta& operator=(const undelta& _u);
00137 };
00138 
00139 class undelta_base
00140 {
00141 public:
00142   undelta_base() {}
00143   undelta_base(const undelta_base& __d) {}
00144 
00145   virtual undelta_base* new_copy() const { return new undelta_base(*this); } // clone operation
00146   virtual void destroy_copy(undelta_base* __d) { delete __d; }
00147 
00148   virtual ~undelta_base() {}
00149 
00150   undelta make_undelta()
00151   {
00152     undelta_base* __tmp = new undelta_base();
00153     return undelta(__tmp);
00154   }
00155 
00156   virtual bool unapply(work_node& _x) const { return false; }
00157 
00158   // these should be implemented better in each delta,
00159   // they, however, need not be
00160   virtual bool unapply3(work_node& _x, const work_node& _y) const;
00161 };
00162 
00163 #endif /* _API_DELTABASE_H_ */

Generated on Tue Nov 4 01:57:56 2003 for COCONUT API by doxygen1.2.18