CoCoALib-0.9905 date: 23 May 2007


module.H

Go to the documentation of this file.
00001 #ifndef CoCoA_module_H
00002 #define CoCoA_module_H
00003 
00004 //   Copyright (c)  2005  John Abbott
00005 
00006 //   This file is part of the source of CoCoALib, the CoCoA Library.
00007 
00008 //   CoCoALib is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License (version 2)
00010 //   as published by the Free Software Foundation.  A copy of the full
00011 //   licence may be found in the file COPYING in this directory.
00012 
00013 //   CoCoALib is distributed in the hope that it will be useful,
00014 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //   GNU General Public License for more details.
00017 
00018 //   You should have received a copy of the GNU General Public License
00019 //   along with CoCoA; if not, write to the Free Software
00020 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 
00023 // Header file for the classes module and ModuleBase, and ModuleElem
00024 
00025 
00026 #include "CoCoA/ring.H"
00027 #include "CoCoA/SmartPtrIRC.H"
00028 
00029 #include <cstddef>
00030 // using std::size_t;
00031 #include <iosfwd>
00032 // using std::ostream;
00033 
00034 
00035 namespace CoCoA
00036 {
00037 
00038   class OpenMathOutput; // forward declaration -- defined in OpenMath.H
00039 
00040   union ModuleRawPtr
00041   {
00042     void* ptr;
00043   };
00044 
00045   class ModuleBase; // forward decl for SmartPtrIRC
00046   /*-----------------------------------------------------------------*/
00047   /** \include module.txt  */
00048   /*-----------------------------------------------------------------*/
00049   class module
00050   {
00051   public:
00052     explicit module(const ModuleBase* ModulePtr): mySmartPtr(ModulePtr) {}
00053     // assignment disabled because SmartPtrIRC has no assignment
00054     const ModuleBase* operator->() const { return mySmartPtr.operator->(); }  ///< Allow const member fns to be called.
00055     const ModuleBase* myRawPtr() const { return mySmartPtr.myRawPtr(); } ///< Used by "downcasting" functions Is(..), As(..), etc.
00056     bool operator==(const module& PPM) const { return mySmartPtr==PPM.mySmartPtr; }
00057   private: // data members
00058     SmartPtrIRC<const ModuleBase> mySmartPtr;
00059   };
00060 
00061 
00062   class ModuleElem
00063   {
00064   private:
00065     module myM;
00066     ModuleRawPtr myValue;
00067 
00068   public:
00069     explicit ModuleElem(const module& M);
00070 //???    ModuleElem(const module& M, ConstRawPtr rawvalue);
00071     ModuleElem(const ModuleElem& copy);
00072     ~ModuleElem();
00073     ModuleElem& operator=(const ModuleElem& rhs);
00074     ConstRefRingElem operator[](std::size_t pos) const;  ///< v[pos] (READ ONLY), defined only if element of a FreeModule
00075 
00076     friend ModuleRawPtr& raw(ModuleElem& v);
00077     friend const ModuleRawPtr& raw(const ModuleElem& v);
00078     friend const module& owner(const ModuleElem& v);
00079   };
00080 
00081 
00082   /*-----------------------------------------------------------------*/
00083   /** \include module.txt  */
00084   /*-----------------------------------------------------------------*/
00085 
00086   class ModuleBase: protected IntrusiveReferenceCount  // abstract class
00087   {
00088     friend class SmartPtrIRC<const ModuleBase>; // morally "friend module", so it can alter reference count
00089 
00090   protected:
00091     ModuleBase(); // just zeroes myRefCount, inline (see below)
00092     virtual ~ModuleBase(); // this class is abstract!!
00093   public:
00094     typedef ModuleRawPtr RawPtr;
00095     typedef const ModuleRawPtr& ConstRawPtr;
00096 
00097     virtual const ring& myBaseRing() const = 0;
00098 
00099     virtual const ModuleElem& myZero() const = 0;
00100     virtual void myInit(RawPtr& rawv) const = 0;
00101     virtual void myInit(RawPtr& rawv, ConstRawPtr rawv1) const = 0;
00102     virtual void myKill(RawPtr& rawv) const = 0;                                  // destroys x (incl all resources)
00103     virtual void mySwap(RawPtr& rawv, RawPtr& raww) const = 0;                       // swap(x, y);
00104     virtual void myAssign(RawPtr& rawlhs, ConstRawPtr rawv) const = 0;             // lhs = v;
00105     virtual void myNegate(RawPtr& rawlhs, ConstRawPtr rawv) const = 0;             // lhs = -v
00106     virtual void myAdd(RawPtr& rawlhs, ConstRawPtr rawv, ConstRawPtr raww) const = 0;   // lhs = v+w;
00107     virtual void mySub(RawPtr& rawlhs, ConstRawPtr rawv, ConstRawPtr raww) const = 0;   // lhs = v-w;
00108 
00109     virtual void myMul(RawPtr& rawlhs, RingElemConstRawPtr rawx, ConstRawPtr rawv) const = 0; // lhs = v*r;
00110     virtual void myDiv(RawPtr& rawlhs, RingElemConstRawPtr rawx, ConstRawPtr rawv) const = 0; // lhs = v/r;
00111     virtual void myOutput(std::ostream& out, ConstRawPtr rawv) const = 0;               // out << v
00112     virtual void myOutputSelf(std::ostream& out) const = 0;                          // out << M
00113     virtual void myOutput(OpenMathOutput& OMOut, ConstRawPtr rawv) const = 0;        // OMOut << v
00114     virtual void myOutputSelf(OpenMathOutput& OMOut) const = 0;                   // OMOut << M
00115     virtual bool myIsZero(ConstRawPtr rawv) const = 0;                               // v == 0
00116 //???    virtual bool IsZeroAddMul(RawPtr& lhs, RingElemConstRawPtr rawy, ConstRawPtr rawz) const;  // lhs += y*z, result says whether lhs == 0.
00117     virtual bool myIsEqual(ConstRawPtr rawv, ConstRawPtr raww) const = 0;
00118   ///  virtual void convert(string&, RawPtr) const = 0;
00119   };
00120 
00121 
00122   // Some syntactic sugar for arithmetic on ModuleElems
00123   ModuleElem operator-(const ModuleElem&);
00124   ModuleElem operator+(const ModuleElem&, const ModuleElem&);
00125   ModuleElem operator-(const ModuleElem&, const ModuleElem&);
00126   ModuleElem operator*(ConstRefRingElem, const ModuleElem&);
00127   ModuleElem operator*(const ModuleElem&, ConstRefRingElem);
00128   ModuleElem operator/(const ModuleElem&, ConstRefRingElem);
00129 
00130   ModuleElem& operator+=(ModuleElem&, const ModuleElem&);
00131   ModuleElem& operator-=(ModuleElem&, const ModuleElem&);
00132   ModuleElem& operator*=(ModuleElem&, ConstRefRingElem);
00133   ModuleElem& operator/=(ModuleElem&, ConstRefRingElem);
00134 
00135   ModuleElem operator*(long, const ModuleElem&);
00136   ModuleElem operator*(const ModuleElem&, long);
00137   ModuleElem operator/(const ModuleElem&, long);
00138 
00139   ModuleElem& operator*=(ModuleElem&, long);
00140   ModuleElem& operator/=(ModuleElem&, long);
00141 
00142 
00143   std::ostream& operator<<(std::ostream&, const ModuleElem& v);
00144   std::ostream& operator<<(std::ostream&, const module& M);
00145   OpenMathOutput& operator<<(OpenMathOutput& OMOut, const ModuleElem& v);
00146   OpenMathOutput& operator<<(OpenMathOutput& OMOut, const module& M);
00147   bool IsZero(const ModuleElem&);
00148   //  const ModuleElem& zero(const module& M);
00149   bool operator==(const ModuleElem& v1, const ModuleElem& v2);
00150   bool operator!=(const ModuleElem& v1, const ModuleElem& v2);
00151 
00152 
00153   /////////////////////////////////////////////////////////////////////////////
00154   // Inline functions
00155 
00156 
00157   inline const ring& BaseRing(const module& M)
00158   {
00159     return M->myBaseRing();
00160   }
00161 
00162 
00163   inline const ModuleElem& zero(const module& M)
00164   {
00165     return M->myZero();
00166   }
00167 
00168 
00169   inline const module& owner(const ModuleElem& v)
00170   {
00171     return v.myM;
00172   }
00173 
00174 
00175   inline ModuleRawPtr& raw(ModuleElem& v)
00176   {
00177     return v.myValue;
00178   }
00179 
00180 
00181   inline const ModuleRawPtr& raw(const ModuleElem& v)
00182   {
00183     return v.myValue;
00184   }
00185 
00186 
00187   inline bool operator!=(const module& M1, const module M2)
00188   {
00189     return !(M1 == M2);
00190   }
00191 
00192 
00193   inline ModuleBase::ModuleBase():
00194     IntrusiveReferenceCount()
00195   {
00196     myRefCountInc(); // NOT ZERO, otherwise FreeModule ctor dies ???
00197   }
00198 
00199 
00200   //??? bool contains(const module& big_module, const module& little_module);
00201 
00202 
00203 } // end of namespace CoCoA
00204 
00205 // RCS header/log in the next few lines
00206 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/module.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00207 // $Log: module.H,v $
00208 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00209 // Imported files
00210 //
00211 // Revision 1.8  2007/01/15 13:33:34  cocoa
00212 // -- added prefix "raw" to RawPtr arguments names
00213 //
00214 // Revision 1.7  2006/12/06 17:18:40  cocoa
00215 // -- removed #include "config.H"
00216 //
00217 // Revision 1.6  2006/11/24 17:23:23  cocoa
00218 // -- removed OpenMathFwd.H
00219 //
00220 // Revision 1.5  2006/11/23 17:37:10  cocoa
00221 // -- changed: module is now a class (instead of typedef)
00222 //
00223 // Revision 1.4  2006/11/14 17:46:20  cocoa
00224 // -- changed: reference counting in modules now uses SmartPtrIRC
00225 //
00226 // Revision 1.3  2006/11/02 13:25:44  cocoa
00227 // Simplification of header files: the OpenMath classes have been renamed.
00228 // Many minor consequential changes.
00229 //
00230 // Revision 1.2  2006/10/06 14:04:15  cocoa
00231 // Corrected position of #ifndef in header files.
00232 // Separated CoCoA_ASSERT into assert.H from config.H;
00233 // many minor consequential changes (have to #include assert.H).
00234 // A little tidying of #include directives (esp. in Max's code).
00235 //
00236 // Revision 1.1.1.1  2006/05/30 11:39:37  cocoa
00237 // Imported files
00238 //
00239 // Revision 1.8  2006/05/12 16:10:58  cocoa
00240 // Added OpenMathFwd.H, and tidied OpenMath.H.
00241 // Many consequential but trivial changes.
00242 //
00243 // Revision 1.7  2006/04/21 14:56:33  cocoa
00244 // Changed return type of myCompt member function: now it returns a
00245 // ConstRefRingElem instead of a RingElem (i.e. a copy).
00246 //
00247 // Revision 1.6  2006/03/27 12:21:26  cocoa
00248 // Minor silly changes to reduce number of complaints from some compiler or other.
00249 //
00250 // Revision 1.5  2006/03/15 18:09:31  cocoa
00251 // Changed names of member functions which print out their object
00252 // into myOutputSelf -- hope this will appease the Intel C++ compiler.
00253 //
00254 // Revision 1.4  2006/03/12 21:28:34  cocoa
00255 // Major check in after many changes
00256 //
00257 // Revision 1.3  2005/11/29 13:04:47  cocoa
00258 // -- added "const" to myCompt argument
00259 //
00260 // Revision 1.2  2005/11/24 16:09:38  cocoa
00261 // -- added operator[] for ModuleElem
00262 //
00263 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00264 // Imported files
00265 //
00266 // Revision 1.1.1.1  2005/05/03 15:47:30  cocoa
00267 // Imported files
00268 //
00269 // Revision 1.3  2005/04/19 14:06:04  cocoa
00270 // Added GPL and GFDL licence stuff.
00271 //
00272 // Revision 1.2  2005/02/11 14:15:20  cocoa
00273 // New style ring elements and references to ring elements;
00274 // I hope I have finally got it right!
00275 //
00276 // Revision 1.1.1.1  2005/01/27 15:12:13  cocoa
00277 // Imported files
00278 //
00279 // Revision 1.7  2004/11/12 15:49:29  cocoa
00280 // Tidying prior to 0.90 release.
00281 // (a) documentation improved (or marked as poor)
00282 // (b) sundry minor improvements to the code
00283 //
00284 // Revision 1.6  2004/11/11 14:04:01  cocoa
00285 // -- minor changes for doxygen
00286 //
00287 // Revision 1.5  2004/11/09 16:10:43  cocoa
00288 // -- minor changes for doxygen
00289 //
00290 // Revision 1.4  2004/06/29 17:10:22  cocoa
00291 // Partially tidied use of "protected" and "private" in various
00292 // base classes.  Checking in at the end of the day -- it works,
00293 // and I wouldn't want it to be lost next time point's disk
00294 // misbehaves.
00295 //
00296 // Revision 1.3  2004/05/27 16:14:02  cocoa
00297 // Minor revision for new coding conventions.
00298 //
00299 // Revision 1.2  2004/01/28 15:35:37  cocoa
00300 // Major update -- was very much "old style" code, and didn't
00301 // compiler under the new organization.
00302 //
00303 // Revision 1.1.1.1  2003/09/24 12:55:43  cocoa
00304 // Imported files
00305 //
00306 // Revision 1.1  2003/05/30 15:10:47  abbott
00307 // Initial revision
00308 //
00309 //
00310 
00311 #endif

Generated on Wed May 23 13:45:23 2007 for CoCoALib by  doxygen 1.4.6