types.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2001-2006 Rational Discovery LLC 
00003 //
00004 //  @@ All Rights Reserved @@
00005 //
00006 
00007 #ifndef __RD_TYPES_H__
00008 #define __RD_TYPES_H__
00009 
00010 #ifdef WIN32
00011 #define _USE_MATH_DEFINES
00012 #endif
00013 
00014 #include <cmath>
00015 
00016 #include <RDGeneral/Invariant.h>
00017 #include "Dict.h"
00018 
00019 #include <vector>
00020 #include <deque>
00021 #include <map>
00022 #include <set>
00023 #include <string>
00024 #include <algorithm>
00025 #include <numeric>
00026 #include <list>
00027 #include<limits>
00028 
00029 #include <cstring>
00030 
00031 #include <boost/any.hpp>
00032 #include <boost/lexical_cast.hpp>
00033 
00034 
00035 namespace RDKit {
00036 
00037 #ifndef WIN32
00038   typedef long long int LONGINT;
00039 #else
00040   typedef __int64 LONGINT;
00041 #endif
00042 #ifdef max
00043 #undef max // FUCK I hate this nonsense
00044 #endif  
00045 #ifdef min
00046 #undef min // FUCK I hate this nonsense
00047 #endif  
00048   
00049   const double MAX_DOUBLE = std::numeric_limits<double>::max();
00050   const double EPS_DOUBLE = std::numeric_limits<double>::epsilon();
00051   const double SMALL_DOUBLE = 1.0e-8;
00052   const double MAX_INT = static_cast<double>(std::numeric_limits<int>::max());
00053   const double MAX_LONGINT = static_cast<double>(std::numeric_limits<LONGINT>::max());
00054   const double PI=3.1415926535897931;
00055 
00056   typedef unsigned int                       UINT;
00057   typedef unsigned short                     USHORT;
00058   typedef unsigned char                      UCHAR;
00059 
00060   typedef std::vector<int>                   INT_VECT;
00061   typedef INT_VECT::iterator                 INT_VECT_I;
00062   typedef INT_VECT::const_iterator           INT_VECT_CI;
00063   typedef INT_VECT::reverse_iterator        INT_VECT_RI;
00064   typedef INT_VECT::const_reverse_iterator  INT_VECT_CRI;
00065 
00066   typedef std::list<int>                     INT_LIST;
00067   typedef INT_LIST::iterator                 INT_LIST_I;
00068   typedef INT_LIST::const_iterator           INT_LIST_CI;
00069 
00070   typedef std::list<INT_VECT>                LIST_INT_VECT;
00071   typedef LIST_INT_VECT::iterator            LIST_INT_VECT_I;
00072   typedef LIST_INT_VECT::const_iterator      LIST_INT_VECT_CI;
00073 
00074   typedef std::vector<INT_VECT>              VECT_INT_VECT;
00075   typedef VECT_INT_VECT::iterator            VECT_INT_VECT_I;
00076   typedef VECT_INT_VECT::const_iterator      VECT_INT_VECT_CI;
00077 
00078   typedef std::vector<UINT>::const_iterator  UINT_VECT_CI;
00079   typedef std::vector<UINT>                  UINT_VECT;
00080 
00081   typedef std::vector<std::string>::const_iterator  STR_VECT_CI;
00082   typedef std::vector<std::string>::iterator        STR_VECT_I;
00083   typedef std::vector<std::string>                  STR_VECT;
00084 
00085 
00086   typedef std::vector<double>                 DOUBLE_VECT;
00087   typedef DOUBLE_VECT::iterator DOUBLE_VECT_I;
00088   typedef DOUBLE_VECT::const_iterator DOUBLE_VECT_CI;
00089   typedef std::vector<DOUBLE_VECT>            VECT_DOUBLE_VECT;
00090   typedef VECT_DOUBLE_VECT::iterator VECT_DOUBLE_VECT_I;
00091   typedef VECT_DOUBLE_VECT::const_iterator VECT_DOUBLE_VECT_CI;
00092         
00093   typedef std::map<std::string, UINT>                 STR_UINT_MAP;
00094   typedef std::map<std::string, UINT>::const_iterator STR_UINT_MAP_CI;
00095 
00096   typedef std::map<int, INT_VECT> INT_INT_VECT_MAP;
00097   typedef INT_INT_VECT_MAP::const_iterator INT_INT_VECT_MAP_CI;
00098 
00099   typedef std::map<int, int> INT_MAP_INT;
00100   typedef INT_MAP_INT::iterator INT_MAP_INT_I;
00101   typedef INT_MAP_INT::const_iterator INT_MAP_INT_CI;
00102 
00103   typedef std::deque<int> INT_DEQUE;
00104   typedef INT_DEQUE::iterator INT_DEQUE_I;
00105   typedef INT_DEQUE::const_iterator INT_DEQUE_CI;
00106 
00107   typedef std::map<int, INT_DEQUE> INT_INT_DEQ_MAP;
00108   typedef INT_INT_DEQ_MAP::const_iterator INT_INT_DEQ_MAP_CI;
00109 
00110   typedef std::set<int>                     INT_SET;
00111   typedef INT_SET::iterator                 INT_SET_I;
00112   typedef INT_SET::const_iterator           INT_SET_CI;
00113 
00114   //! functor to compare two doubles with a tolerance
00115   struct ltDouble {
00116   public:
00117     ltDouble() : _tol(1.0e-8) {};
00118     bool operator() (double d1, double d2) const {
00119       if (fabs(d1 - d2) < _tol) {
00120         return false;
00121       }
00122       else {
00123         return (d1 < d2);
00124       }
00125     }
00126   private:
00127     double _tol;
00128   };
00129 
00130   //! std::map from double to integer.
00131   typedef std::map<double, int, ltDouble> DOUBLE_INT_MAP;
00132 
00133   //! functor for returning the larger of two values
00134   template <typename T>
00135   struct larger_of {
00136     T operator()(T arg1,T arg2) { return arg1>arg2 ? arg1 : arg2; };
00137   };
00138 
00139 
00140   //! functor for comparing two strings
00141   struct charptr_functor {
00142     bool operator()(const char* s1, const char* s2) const
00143     {
00144       //std::cout << s1 << " " << s2 << " " << strcmp(s1, s2) << "\n";
00145 
00146       return strcmp(s1, s2) < 0;
00147     };
00148   };
00149   
00150   //! \brief calculate the union of two INT_VECTs and put the results in a
00151   //! third vector
00152   void Union(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res);
00153 
00154   //! \brief calculate the intersection of two INT_VECTs and put the results in a
00155   //! third vector
00156   void Intersect(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res);
00157 
00158   //! calculating the union of the INT_VECT's in a VECT_INT_VECT
00159   /*!
00160       \param rings   the INT_VECT's to consider
00161       \param res     used to return results
00162       \param exclude any values in this optional INT_VECT will be excluded
00163              from the union.
00164   */
00165   void Union(const VECT_INT_VECT &rings, INT_VECT &res, const INT_VECT *exclude=NULL);
00166 
00167   //! given a current combination of numbers change it to the next possible combination
00168   /*!
00169     \param comb the <b>sorted</b> vector to consider
00170     \param tot the maximum number possible in the vector
00171 
00172     \return -1 on failure, the index of the last number changed on success.
00173     Example:
00174       for all combinations 3 of numbers between 0 and tot=5 
00175       given (0,1,2) the function wil return (0,1,3) etc.
00176 
00177       
00178   */
00179   int nextCombination(INT_VECT &comb, int tot);
00180 
00181 
00182   //! rounds a value to the closest int
00183   double round(double v);  
00184 
00185 }; // end of namespace
00186 
00187 
00188 
00189 #endif

Generated on Tue Oct 7 06:10:11 2008 for RDCode by  doxygen 1.5.5