CoCoALib-0.9905 date: 23 May 2007


symbol.H

Go to the documentation of this file.
00001 #ifndef CoCoA_symbol_H
00002 #define CoCoA_symbol_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/assert.H"
00024 
00025 #include <cstddef>
00026 //using std::size_t;
00027 #include <vector>
00028 //using std::vector;
00029 #include <string>
00030 //using std::string;
00031 #include <iosfwd>
00032 //using std::ostream;
00033 
00034 
00035 namespace CoCoA
00036 {
00037 
00038   class symbol
00039   {
00040   public:
00041     explicit symbol(const std::string& head); // symbolic name without indices
00042     symbol(const std::string& head, int index); // symbolic name with 1 index
00043     symbol(const std::string& head, const std::vector<int>& indices); // symbolic name with indices
00044     // Default copy ctor and assignment are fine.
00045     // Default dtor is fine.
00046 
00047     void myOutputSelf(std::ostream& out) const;
00048     void myInput(std::istream& in);
00049 
00050     int myCmp(const symbol& sym2) const;
00051     static bool IsValidHead(const std::string& head);
00052   private: // data members
00053     std::string myHead;
00054     std::vector<int> myIndices;
00055     friend const std::string& head(const symbol& sym);
00056     friend std::size_t NumIndices(const symbol& sym);
00057     friend int index(const symbol& sym, size_t n);
00058   };
00059 
00060 
00061   const std::string& head(const symbol& sym);                   // inline
00062   std::size_t NumIndices(const symbol& sym);                    // inline
00063   int index(const symbol& sym, size_t n);
00064   std::ostream& operator<<(std::ostream& out, const symbol& sym);
00065   std::istream& operator>>(std::istream& in, symbol& sym);
00066   int cmp(const symbol& sym1, const symbol& sym2);              // inline
00067   bool operator==(const symbol& sym1, const symbol& sym2);      // inline
00068   bool operator!=(const symbol& sym1, const symbol& sym2);      // inline
00069   bool operator<(const symbol& sym1, const symbol& sym2);       // inline
00070   bool operator<=(const symbol& sym1, const symbol& sym2);      // inline
00071   bool operator>(const symbol& sym1, const symbol& sym2);       // inline
00072   bool operator>=(const symbol& sym1, const symbol& sym2);      // inline
00073 
00074   std::vector<symbol> SymbolRange(const symbol& sym1, const symbol& sym2);
00075   std::vector<symbol> SymbolRange(const std::string& head, int lo, int hi); // <==> SymbolRange(symbol(head,lo),symbol(head,hi));
00076   // Four convenience functions -- make creating simple PolyRings easier.
00077   std::vector<symbol> symbols(const std::string& head1);
00078   std::vector<symbol> symbols(const std::string& head1, const std::string& head2);
00079   std::vector<symbol> symbols(const std::string& head1, const std::string& head2, const std::string& head3);
00080   std::vector<symbol> symbols(const std::string& head1, const std::string& head2, const std::string& head3, const std::string& head4);
00081 
00082   //---------------------------------------------------------------------------
00083   // Inline implementations
00084 
00085   inline const std::string& head(const symbol& sym)
00086   {
00087     return sym.myHead;
00088   }
00089 
00090 
00091   inline std::size_t NumIndices(const symbol& sym)
00092   {
00093     return sym.myIndices.size();
00094   }
00095 
00096 
00097   inline int cmp(const symbol& sym1, const symbol& sym2)
00098   {
00099     return sym1.myCmp(sym2);
00100   }
00101 
00102   inline bool operator==(const symbol& sym1, const symbol& sym2)
00103   {
00104     return sym1.myCmp(sym2) == 0;
00105   }
00106 
00107   inline bool operator!=(const symbol& sym1, const symbol& sym2)
00108   {
00109     return sym1.myCmp(sym2) != 0;
00110   }
00111 
00112   inline bool operator<(const symbol& sym1, const symbol& sym2)
00113   {
00114     return sym1.myCmp(sym2) < 0;
00115   }
00116 
00117   inline bool operator<=(const symbol& sym1, const symbol& sym2)
00118   {
00119     return sym1.myCmp(sym2) <= 0;
00120   }
00121 
00122   inline bool operator>(const symbol& sym1, const symbol& sym2)
00123   {
00124     return sym1.myCmp(sym2) > 0;
00125   }
00126 
00127   inline bool operator>=(const symbol& sym1, const symbol& sym2)
00128   {
00129     return sym1.myCmp(sym2) >= 0;
00130   }
00131 
00132 } // end of namespace CoCoA
00133 
00134 
00135 
00136 // RCS header/log in the next few lines
00137 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/symbol.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00138 // $Log: symbol.H,v $
00139 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00140 // Imported files
00141 //
00142 // Revision 1.6  2007/03/08 16:55:06  cocoa
00143 // Changed name of "range" function to "SymbolRange".
00144 //
00145 // Revision 1.5  2007/03/08 14:38:07  cocoa
00146 // Added new range function in symbol.H, and tidied many calls to PolyRing
00147 // pseudo ctors (as a consequence).
00148 //
00149 // Revision 1.4  2006/11/27 14:20:09  cocoa
00150 // -- removed #include "CoCoA/config.H"
00151 //
00152 // Revision 1.3  2006/10/27 19:09:45  cocoa
00153 // Replaced some member functions of CoCoA::symbol by friend functions.
00154 // Removed some include dependency on symbol.H
00155 //
00156 // Revision 1.2  2006/10/06 14:04:15  cocoa
00157 // Corrected position of #ifndef in header files.
00158 // Separated CoCoA_ASSERT into assert.H from config.H;
00159 // many minor consequential changes (have to #include assert.H).
00160 // A little tidying of #include directives (esp. in Max's code).
00161 //
00162 // Revision 1.1.1.1  2006/05/30 11:39:37  cocoa
00163 // Imported files
00164 //
00165 // Revision 1.2  2006/03/15 18:09:31  cocoa
00166 // Changed names of member functions which print out their object
00167 // into myOutputSelf -- hope this will appease the Intel C++ compiler.
00168 //
00169 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00170 // Imported files
00171 //
00172 // Revision 1.1  2005/07/08 15:09:29  cocoa
00173 // Added new symbol class (to represent names of indets).
00174 // Integrated the new class into concrete polynomial rings
00175 // and PPMonoid -- many consequential changes.
00176 // Change ctors for the "inline" sparse poly rings: they no
00177 // longer expect a PPMonoid, but build their own instead
00178 // (has to be a PPMonoidOv).
00179 //
00180 
00181 #endif

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