CoCoALib-0.9905 date: 23 May 2007


utils.H

Go to the documentation of this file.
00001 #ifndef CoCoA_utils_H
00002 #define CoCoA_utils_H
00003 
00004 //   Copyright (c)  2006,2007  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 namespace CoCoA
00024 {
00025 
00026   // This function object class taken from Meyers's "Effective STL", page 38 (first ed.)
00027   // It can be used to delete all the elements in an STL container of pointers.
00028   struct DeleteObject
00029   {
00030     template<typename T> void operator()(const T* ptr) const
00031     {
00032       delete ptr;
00033     }
00034   };
00035 
00036 
00037 
00038   // Generic 3-way comparison function: assumes operator< is defined.
00039   // Result is <0 =0 or >0 according as a<b, a==b, a>b.
00040   template <typename T1, typename T2>
00041   inline int cmp(const T1& a, const T2& b)
00042   {
00043     if (a < b) return -1;
00044     if (b < a) return 1;
00045     return 0;
00046   }
00047 
00048 
00049   // LexCmp3 3-way lex comparison.  I think this ought to be in the STL.
00050   // Result is <0, =0, or >0 according as begin1..end1 < = > begin2..end2
00051   template <class InputIterator1, class InputIterator2>
00052   inline int LexCmp3(InputIterator1 begin1, InputIterator1 end1,
00053                      InputIterator2 begin2, InputIterator2 end2)
00054   {
00055     while (begin1 != end1 && begin2 != end2)
00056     {
00057       const int sign = cmp(*begin1, *begin2);
00058       if (sign != 0) return sign;
00059       ++begin1;
00060       ++begin2;
00061     }
00062     if (begin1 != end1) return 1;
00063     if (begin2 != end2) return -1;
00064     return 0;
00065   }
00066 
00067 
00068 } // end of namespace CoCoA
00069 
00070 
00071 
00072 // RCS header/log in the next few lines
00073 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/utils.H,v 1.3 2007/05/21 12:53:08 abbott Exp $
00074 // $Log: utils.H,v $
00075 // Revision 1.3  2007/05/21 12:53:08  abbott
00076 // No real change in the end.
00077 //
00078 // Revision 1.2  2007/03/23 18:38:43  abbott
00079 // Separated the "convert" functions (and CheckedCast) into their own files.
00080 // Many consequential changes.  Also corrected conversion to doubles.
00081 //
00082 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00083 // Imported files
00084 //
00085 // Revision 1.5  2007/03/08 18:42:05  cocoa
00086 // Cleaned up whitespace.
00087 //
00088 // Revision 1.4  2006/12/06 17:18:40  cocoa
00089 // -- removed #include "config.H"
00090 //
00091 // Revision 1.3  2006/11/27 13:06:23  cocoa
00092 // Anna and Michael made me check without writing a proper message.
00093 //
00094 // Revision 1.2  2006/10/06 14:04:15  cocoa
00095 // Corrected position of #ifndef in header files.
00096 // Separated CoCoA_ASSERT into assert.H from config.H;
00097 // many minor consequential changes (have to #include assert.H).
00098 // A little tidying of #include directives (esp. in Max's code).
00099 //
00100 // Revision 1.1  2006/08/07 21:23:25  cocoa
00101 // Removed almost all publicly visible references to SmallExponent_t;
00102 // changed to long in all PPMonoid functions and SparsePolyRing functions.
00103 // DivMask remains to sorted out.
00104 //
00105 
00106 #endif

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