CoCoALib-0.9905 date: 23 May 2007


OpenMath.H

Go to the documentation of this file.
00001 #ifndef CoCoA_OpenMath_H
00002 #define CoCoA_OpenMath_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 #include "CoCoA/SmartPtrIRC.H"
00024 
00025 #include <cstddef>
00026 // using std::size_t;
00027 #include <iosfwd>
00028 // using std::ostream;
00029 #include <string>
00030 // using std::string
00031 
00032 
00033 namespace CoCoA
00034 {
00035 
00036   class ZZ; // fwd decl, defined in ZZ.H
00037 
00038   class OpenMathSymbol
00039   {
00040   public:
00041     OpenMathSymbol(); // fills symbol with a default "unset" value
00042     OpenMathSymbol(const char* const cd, const char*const name);
00043     OpenMathSymbol(const std::string& cd, const std::string& name);
00044     // Default copy ctor, assignment and dtor are fine.
00045 
00046     void myOutputSelf(std::ostream& out) const;
00047 
00048   private: // data members
00049     std::string myCD;
00050     std::string myName;
00051     friend const std::string& CD(const OpenMathSymbol& s);   // accessor
00052     friend const std::string& name(const OpenMathSymbol& s); // accessor
00053   };
00054 
00055   std::ostream& operator<<(std::ostream& out, const OpenMathSymbol& oms);
00056 
00057   //---------------------------------------------------------------------------
00058   // Output functions etc.
00059 
00060   class OpenMathOutputBase; // fwd decl, defined below.
00061   class OpenMathOutput
00062   {
00063   public:
00064     explicit OpenMathOutput(OpenMathOutputBase* ptr): mySmartPtr(ptr) {}
00065     // assignment disabled because SmartPtrIRC has no assignment
00066     OpenMathOutputBase* operator->() const { return mySmartPtr.operator->(); }  ///< Allow const member fns to be called.
00067   private: // data members
00068     SmartPtrIRC<OpenMathOutputBase> mySmartPtr;
00069   };
00070 
00071 
00072   OpenMathOutput& operator<<(OpenMathOutput& OMOut, short n);
00073   OpenMathOutput& operator<<(OpenMathOutput& OMOut, int n);
00074   OpenMathOutput& operator<<(OpenMathOutput& OMOut, long n);
00075   OpenMathOutput& operator<<(OpenMathOutput& OMOut, unsigned short n);
00076   OpenMathOutput& operator<<(OpenMathOutput& OMOut, unsigned int n);
00077   OpenMathOutput& operator<<(OpenMathOutput& OMOut, unsigned long n);
00078   OpenMathOutput& operator<<(OpenMathOutput& OMOut, const ZZ& N);
00079   OpenMathOutput& operator<<(OpenMathOutput& OMOut, const OpenMathSymbol& s);
00080 
00081 
00082   class OpenMathOutputBase: protected IntrusiveReferenceCount
00083   {
00084     friend class SmartPtrIRC<OpenMathOutputBase>; // morally "friend OpenMathOutput", so it can alter referencce count
00085   protected:
00086     OpenMathOutputBase(); // just sets ref count to zero.
00087     virtual ~OpenMathOutputBase();
00088   public:
00089     virtual void mySend(long n) = 0;
00090     virtual void mySend(unsigned long n) = 0;
00091     virtual void mySend(const ZZ& N) = 0;  // outputs an integer
00092     virtual void mySend(const OpenMathSymbol& s) = 0;
00093     virtual void mySendApplyStart() = 0;
00094     virtual void mySendApplyEnd() = 0;
00095     virtual void mySendObjectStart() = 0;
00096     virtual void mySendObjectEnd() = 0;
00097 
00098     //void OutputAttribute() = 0;//??????
00099   };
00100 
00101 
00102   //---------------------------------------------------------------------------
00103   // Input functions etc.
00104 
00105   enum OpenMathTag { OpenMathObj, OpenMathApply, OpenMathInt, OpenMathSym, OpenMathAttr, OpenMathEOF };
00106 
00107   class OpenMathInputBase;  // fwd decl, defined below.
00108   class OpenMathInput
00109   {
00110   public:
00111     explicit OpenMathInput(OpenMathInputBase* ptr): mySmartPtr(ptr) {}
00112     // assignment disabled because SmartPtrIRC has no assignment
00113     OpenMathInputBase* operator->() const { return mySmartPtr.operator->(); }  ///< Allow const member fns to be called.
00114   private: // data members
00115     SmartPtrIRC<OpenMathInputBase> mySmartPtr;
00116   };
00117 
00118   class OpenMathInputBase: protected IntrusiveReferenceCount
00119   {
00120     friend class SmartPtrIRC<OpenMathInputBase>; // morally "friend OpenMathInput", so it can alter reference count
00121   protected:
00122     OpenMathInputBase(); // just sets ref count to zero.
00123     virtual ~OpenMathInputBase();
00124   public:
00125     virtual void advance() = 0;
00126     virtual OpenMathTag myCurrTag() = 0;
00127     virtual std::size_t NumDescendants() const = 0;
00128     virtual bool myRecv(long & n) = 0; // SHORT INTEGER
00129     virtual bool myRecv(ZZ& N) = 0;    // LONG INTEGER
00130     virtual bool myRecv(OpenMathSymbol& s) = 0; // result is false if node is of wrong type
00131 
00132 //       virtual void InputApplyStart() = 0;
00133 //       virtual void InputApplyEnd() = 0;
00134 //       virtual void InputObjectStart() = 0;
00135 //       virtual void InputObjectEnd() = 0;
00136 
00137     //void InputAttribute() = 0;//??????
00138   };
00139 
00140   OpenMathInput& operator>>(OpenMathInput& OMIn, long& n);
00141   OpenMathInput& operator>>(OpenMathInput& OMIn, ZZ& N);
00142   OpenMathInput& operator>>(OpenMathInput& OMIn, OpenMathSymbol& s); //????
00143 
00144 } // end of namespace CoCoA
00145 
00146 
00147 // RCS header/log in the next few lines
00148 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/OpenMath.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00149 // $Log: OpenMath.H,v $
00150 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00151 // Imported files
00152 //
00153 // Revision 1.6  2006/12/06 17:14:12  cocoa
00154 // -- removed #include "config.H"
00155 //
00156 // Revision 1.5  2006/11/27 13:04:35  cocoa
00157 // Added explicit OpenMath output operators for all integer types.
00158 //
00159 // Revision 1.4  2006/11/23 17:10:52  cocoa
00160 // -- changed: OpenMathOutput and OpenMathInput are now a class (instead of typedef)
00161 //
00162 // Revision 1.3  2006/11/02 13:25:44  cocoa
00163 // Simplification of header files: the OpenMath classes have been renamed.
00164 // Many minor consequential changes.
00165 //
00166 // Revision 1.2  2006/10/06 14:04:15  cocoa
00167 // Corrected position of #ifndef in header files.
00168 // Separated CoCoA_ASSERT into assert.H from config.H;
00169 // many minor consequential changes (have to #include assert.H).
00170 // A little tidying of #include directives (esp. in Max's code).
00171 //
00172 
00173 
00174 #endif

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