Defs.hpp

00001 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00002 //
00003 //        This file is part of E-Cell Simulation Environment package
00004 //
00005 //                Copyright (C) 1996-2002 Keio University
00006 //
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 //
00009 //
00010 // E-Cell is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 // 
00015 // E-Cell is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 // See the GNU General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU General Public
00021 // License along with E-Cell -- see the file COPYING.
00022 // If not, write to the Free Software Foundation, Inc.,
00023 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 // 
00025 //END_HEADER
00026 //
00027 // written by Koichi Takahashi <shafi@e-cell.org>,
00028 // E-Cell Project.
00029 //
00030 
00031 
00032 #ifndef __DEFS_HPP
00033 #define __DEFS_HPP
00034 #include "ecell_config.h"
00035 
00036 #include <stdint.h>
00037 #include <float.h>
00038 #include <string>
00039 #include <list>
00040 #include <vector>
00041 #include <map>
00042 
00043 #include <boost/call_traits.hpp>
00044 #include <boost/smart_ptr.hpp>
00045 
00046 #define DEBUG 1
00047 
00048 // stringifiers.  see preprocessor manual
00049 #define XSTR( S ) STR( S )
00050 #define STR( S ) #S
00051 
00052 
00053 #define USE_LIBECS using namespace libecs
00054 
00055 // cmath
00056 
00057 #if defined( HAVE_CMATH )
00058 #include <cmath>
00059 #elif defined( HAVE_MATH )
00060 #include <math>
00061 #else
00062 #error "either math or cmath header is needed."
00063 #endif /* HAVE_CMATH */
00064 
00065 
00066 // 
00067 // If USE_COMPILER_EXTENSIONS is defined, the compiler's special
00068 // language syntax and optimizations that are not part of the standard
00069 // (such as ISO C++) are exploited.
00070 //
00071 // Defined macros:
00072 //
00073 // LIBECS_USE_PMF_CONVERSIONS 
00074 // If this macro is defined, conversions from pointer-to-member-functions 
00075 // to usual function pointers can be used.
00076 //
00077 //
00078 // LIBECS_LIKELY( EXP ), LIBECS_UNLIKELY( EXP )
00079 // These macros indicate the expression EXP is very (un)likely to be true,
00080 // and the branch based on this will be frequently (not) taken.
00081 // These are typically used in if() statements.   Unless you are very sure,
00082 // it is a good idea to not to try to do this job by yourself and just 
00083 // rely on the compiler and CPU's branch prediction mechanisms and 
00084 // profile-based branch counters. These macros do nothing when 
00085 // libecs does not support branch prediction on the platform.
00086 //
00087 //
00088 // LIBECS_PREFETCH( ADDR, RW, LOCALITY )
00089 // This macro prefetches the content of memory at the address ADDR,
00090 // and refreshes the cache.   If RW is zero, the cache is prepared for
00091 // a read access, and one for a write access.  LOCALITY (0..3) indicates
00092 // the temporal locality of the access.   Larger values let the
00093 // accessed addresses more sticky on the cache.
00094 // These macros do nothing when libecs does not support prefetching
00095 // on the platform.
00096 //
00097 
00098 #if defined( USE_COMPILER_EXTENSIONS ) && defined( __GNUC__ )
00099 #    define LIBECS_USE_PMF_CONVERSIONS 1
00100 #    define LIBECS_LIKELY( EXP )       __builtin_expect( ( EXP ), 1 )
00101 #    define LIBECS_UNLIKELY( EXP )     __builtin_expect( ( EXP ), 0 )
00102 #    define LIBECS_PREFETCH( ADDR, RW, LOCALITY )\
00103             __builtin_prefetch( ( ADDR ), ( RW ), ( LOCALITY ) )
00104 #else
00105 // do not define LIBECS_USE_PMF_CONVERSIONS
00106 #    define LIBECS_LIKELY( EXP )       ( EXP )
00107 #    define LIBECS_UNLIKELY( EXP )     ( EXP )
00108 #    define LIBECS_PREFETCH            
00109 #endif /* defined( USE_COMPILER_EXTENSIONS ) && defined( __GNUC__ ) */
00110 
00111 
00112 namespace libecs
00113 {
00114 
00115   // Some macros those origins are libCoreLinux++
00116 
00117   /**
00118      IGNORE_RETURN is an indicator that the return
00119      value for a function is ignored.
00120      i.e   IGNORE_RETURN getSomething( ... );
00121      Eliminates a lint warning.
00122   */
00123 
00124 #define IGNORE_RETURN (void)
00125 
00126   /**
00127      Declare a new type and its pointer,
00128      const pointer, reference, and const reference types. For example
00129      DECLARE_TYPE( Dword, VeryLongTime );
00130      @param mydecl The base type
00131      @param mytype The new type
00132   */
00133 
00134 #define DECLARE_TYPE( mydecl, mytype )  \
00135 typedef mydecl         mytype;         \
00136 typedef mytype *       mytype ## Ptr;  \
00137 typedef const mytype * mytype ## Cptr; \
00138 typedef mytype &       mytype ## Ref;  \
00139 typedef const mytype & mytype ## Cref;
00140 
00141   /**
00142      Declare class , class pointer , 
00143      const pointer, class reference 
00144      and const class reference types for classes. For example
00145      DECLARE_CLASS( Exception );
00146      @param tag The class being declared
00147   */
00148 
00149 #define DECLARE_CLASS( tag )            \
00150    class   tag;                        \
00151    typedef tag *       tag ## Ptr;     \
00152    typedef const tag * tag ## Cptr;    \
00153    typedef tag &       tag ## Ref;     \
00154    typedef const tag & tag ## Cref;
00155 
00156 #define DECLARE_SHAREDPTR( type )\
00157   typedef boost::shared_ptr<type> type ## SharedPtr;\
00158   typedef type ## SharedPtr *       type ## SharedPtr ## Ptr;     \
00159   typedef const type ## SharedPtr * type ## SharedPtr ## Cptr;    \
00160   typedef type ## SharedPtr &       type ## SharedPtr ## Ref;     \
00161   typedef const type ## SharedPtr & type ## SharedPtr ## Cref;
00162 
00163 
00164 
00165   // *******************************************
00166   // Define the void pointer type.
00167   // *******************************************
00168    
00169   typedef void * VoidPtr;
00170 
00171   // *******************************************
00172   // Define the NULLPTR
00173   // *******************************************
00174 
00175 #define  NULLPTR  0
00176    
00177   /**
00178      STL list template. This macro generates all
00179      the type references and pointers for the collection and
00180      respective iterators for a list.
00181      @param name The name you want to give the collection
00182      @param type The type object the collection manages
00183   */
00184 #define DECLARE_LIST( type, name )                            \
00185       DECLARE_TYPE(std::list<type>,name);                       \
00186       typedef name::iterator name ## Iterator;                  \
00187       typedef name::iterator& name ## IteratorRef;              \
00188       typedef name::iterator* name ## IteratorPtr;              \
00189       typedef name::const_iterator name ## ConstIterator;       \
00190       typedef name::const_iterator& name ## ConstIteratorRef;   \
00191       typedef name::const_iterator* name ## ConstIteratorPtr;   \
00192       typedef name::reverse_iterator name ## Riterator;         \
00193       typedef name::reverse_iterator& name ## RiteratorRef;     \
00194       typedef name::reverse_iterator* name ## RiteratorPtr
00195 
00196 
00197   /**
00198      STL vector template. This macro generates all
00199      the type references and pointers for the collection and
00200      respective iterators for a vector.
00201      @param name The name you want to give the collection
00202      @param type The type for the vector
00203   */
00204 #define DECLARE_VECTOR( type, name )                            \
00205    DECLARE_TYPE(std::vector<type>,name);                       \
00206    typedef name::iterator name ## Iterator;                    \
00207    typedef name::iterator& name ## IteratorRef;                \
00208    typedef name::iterator* name ## IteratorPtr;                \
00209    typedef name::const_iterator name ## ConstIterator;         \
00210    typedef name::const_iterator& name ## ConstIteratorRef;     \
00211    typedef name::const_iterator* name ## ConstIteratorPtr;     \
00212    typedef name::reverse_iterator name ## Riterator;           \
00213    typedef name::reverse_iterator& name ## RiteratorRef;       \
00214    typedef name::reverse_iterator* name ## RiteratorPtr
00215 
00216 
00217   /**
00218      STL set template. This macro generates all
00219      the type references and pointers for the collection and
00220      respective iterators for a set.
00221      @param name The name you want to give the collection
00222      @param key The object that represents the set key
00223      @param comp The comparator functor
00224   */
00225 #define DECLARE_SET(key,comp,name)                                       \
00226       typedef set<key, comp > name;                                           \
00227       typedef name *       name ## Ptr;                                       \
00228       typedef const name * name ## Cptr;                                      \
00229       typedef name &       name ## Ref;                                       \
00230       typedef const name & name ## Cref;                                      \
00231       typedef name::iterator name ## Iterator;                                \
00232       typedef name::iterator& name ## IteratorRef;                            \
00233       typedef name::iterator* name ## IteratorPtr;                            \
00234       typedef name::const_iterator name ## ConstIterator;                     \
00235       typedef name::const_iterator& name ## ConstIteratorRef;                 \
00236       typedef name::const_iterator* name ## ConstIteratorPtr;                 \
00237       typedef name::reverse_iterator name ## Riterator;                       \
00238       typedef name::reverse_iterator& name ## RiteratorRef;                   \
00239       typedef name::reverse_iterator* name ## RiteratorPtr
00240    
00241   /**
00242      STL multiset template. This macro generates all
00243      the type references and pointers for the collection and
00244      respective iterators for a multiset.
00245      @param name The name you want to give the collection
00246      @param key The object that represents the mutliset key
00247      @param comp The comparator functor
00248   */
00249 #define DECLARE_MULTISET(key,comp,name)                                  \
00250       typedef multiset<key, comp > name;                                      \
00251       typedef name *       name ## Ptr;                                       \
00252       typedef const name * name ## Cptr;                                      \
00253       typedef name &       name ## Ref;                                       \
00254       typedef const name & name ## Cref;                                      \
00255       typedef name::iterator name ## Iterator;                                \
00256       typedef name::iterator& name ## IteratorRef;                            \
00257       typedef name::iterator* name ## IteratorPtr;                            \
00258       typedef name::const_iterator name ## ConstIterator;                     \
00259       typedef name::const_iterator& name ## ConstIteratorRef;                 \
00260       typedef name::const_iterator* name ## ConstIteratorPtr;                 \
00261       typedef name::reverse_iterator name ## Riterator;                       \
00262       typedef name::reverse_iterator& name ## RiteratorRef;                   \
00263       typedef name::reverse_iterator* name ## RiteratorPtr
00264 
00265 
00266   /**
00267      STL map template. This macro generates all
00268      the type references and pointers for the collection and
00269      respective iterators for a map.
00270      @param name The name you want to give the collection
00271      @param key The object that represents the map key
00272      @param value The object that the key is associated to
00273      @param comp The comparator functor
00274   */
00275 #define DECLARE_MAP(key,value,comp,name)                             \
00276       typedef std::map<key,value,comp > name;                      \
00277       typedef name *       name ## Ptr;                            \
00278       typedef const name * name ## Cptr;                           \
00279       typedef name &       name ## Ref;                            \
00280       typedef const name & name ## Cref;                           \
00281       typedef name::iterator name ## Iterator;                     \
00282       typedef name::iterator& name ## IteratorRef;                 \
00283       typedef name::iterator* name ## IteratorPtr;                 \
00284       typedef name::const_iterator name ## ConstIterator;          \
00285       typedef name::const_iterator& name ## ConstIteratorRef;      \
00286       typedef name::const_iterator* name ## ConstIteratorPtr;      \
00287       typedef name::reverse_iterator name ## Riterator;            \
00288       typedef name::reverse_iterator& name ## RiteratorRef;        \
00289       typedef name::reverse_iterator* name ## RiteratorPtr
00290    
00291   /**
00292      STL multimap template. This macro generates all
00293      the type references and pointers for the collection and
00294      respective iterators for a multimap.
00295      @param name The name you want to give the collection
00296      @param key The object that represents the map key
00297      @param value The object that the key is associated to
00298      @param comp The comparator functor
00299   */
00300 
00301 #define DECLARE_MULTIMAP(key,value,comp,name)                 \
00302       typedef std::multimap<key,value,comp > name;                 \
00303       typedef name *       name ## Ptr;                            \
00304       typedef const name * name ## Cptr;                           \
00305       typedef name &       name ## Ref;                            \
00306       typedef const name & name ## Cref;                           \
00307       typedef name::iterator name ## Iterator;                     \
00308       typedef name::iterator& name ## IteratorRef;                 \
00309       typedef name::iterator* name ## IteratorPtr;                 \
00310       typedef name::const_iterator name ## ConstIterator;          \
00311       typedef name::const_iterator& name ## ConstIteratorRef;      \
00312       typedef name::const_iterator* name ## ConstIteratorPtr;      \
00313       typedef name::reverse_iterator name ## Riterator;            \
00314       typedef name::reverse_iterator& name ## RiteratorRef;        \
00315       typedef name::reverse_iterator* name ## RiteratorPtr
00316 
00317 
00318   /**
00319      STL queue template. This macro generates all
00320      the type references and pointers for the collection and
00321      respective iterators for a queue.
00322      @param name The name you want to give the collection
00323      @param type The type to be queued
00324   */
00325 #define DECLARE_QUEUE( type, name )                          \
00326       DECLARE_TYPE(std::deque<type>,name);                     \
00327       typedef name::iterator name ## Iterator;                 \
00328       typedef name::iterator& name ## IteratorRef;             \
00329       typedef name::iterator* name ## IteratorPtr;             \
00330       typedef name::const_iterator name ## ConstIterator;      \
00331       typedef name::const_iterator& name ## ConstIteratorRef;  \
00332       typedef name::const_iterator* name ## ConstIteratorPtr;  \
00333       typedef name::reverse_iterator name ## Riterator;        \
00334       typedef name::reverse_iterator& name ## RiteratorRef;    \
00335       typedef name::reverse_iterator* name ## RiteratorPtr
00336 
00337   /**
00338      STL stack template. This macro generates all
00339      the type references and pointers for the collection and
00340      respective iterators for a stack.
00341      @param name The name you want to give the collection
00342      @param type The type to be stacked
00343   */
00344 #define DECLARE_STACK( type, name )                                 \
00345       DECLARE_TYPE(stack<type>,name)                                   
00346 
00347 
00348   // from Loki
00349 
00350   
00351 #define DECLARE_ASSOCVECTOR(key,value,comp,name)                             \
00352       typedef ::Loki::AssocVector<key,value,comp > name;                      \
00353       typedef name *       name ## Ptr;                            \
00354       typedef const name * name ## Cptr;                           \
00355       typedef name &       name ## Ref;                            \
00356       typedef const name & name ## Cref;                           \
00357       typedef name::iterator name ## Iterator;                     \
00358       typedef name::iterator& name ## IteratorRef;                 \
00359       typedef name::iterator* name ## IteratorPtr;                 \
00360       typedef name::const_iterator name ## ConstIterator;          \
00361       typedef name::const_iterator& name ## ConstIteratorRef;      \
00362       typedef name::const_iterator* name ## ConstIteratorPtr;      \
00363       typedef name::reverse_iterator name ## Riterator;            \
00364       typedef name::reverse_iterator& name ## RiteratorRef;        \
00365       typedef name::reverse_iterator* name ## RiteratorPtr
00366 
00367 #define DECLARE_ASSOCVECTOR_TEMPLATE(key,value,comp,name)                \
00368       typedef ::Loki::AssocVector<key,value,comp > name;                      \
00369       typedef name *       name ## Ptr;                            \
00370       typedef const name * name ## Cptr;                           \
00371       typedef name &       name ## Ref;                            \
00372       typedef const name & name ## Cref;                           \
00373       typedef typename name::iterator name ## Iterator;                     \
00374       typedef typename name::iterator& name ## IteratorRef;                 \
00375       typedef typename name::iterator* name ## IteratorPtr;                 \
00376       typedef typename name::const_iterator name ## ConstIterator;          \
00377       typedef typename name::const_iterator& name ## ConstIteratorRef;      \
00378       typedef typename name::const_iterator* name ## ConstIteratorPtr;      \
00379       typedef typename name::reverse_iterator name ## Riterator;            \
00380       typedef typename name::reverse_iterator& name ## RiteratorRef;        \
00381       typedef typename name::reverse_iterator* name ## RiteratorPtr
00382 
00383 
00384   // Types
00385 
00386   template <typename T>
00387   class Param
00388   {
00389   public:
00390     typedef typename boost::call_traits<T>::param_type type;
00391   };
00392 
00393   // String
00394 
00395   DECLARE_TYPE( std::string, String );
00396 
00397   DECLARE_TYPE( const char* const, StringLiteral );
00398 
00399   // Numeric types
00400 
00401   DECLARE_TYPE( long int, Integer );
00402   DECLARE_TYPE( unsigned long int, UnsignedInteger );
00403   typedef Param<Integer>::type IntegerParam;
00404   typedef Param<UnsignedInteger>::type UnsignedIntegerParam;
00405 
00406 
00407   // these can cause problem when used as template parameters
00408   //  DECLARE_TYPE( int64_t, Integer );
00409   //  DECLARE_TYPE( uint64_t, UnsignedInteger );
00410 
00411   //  DECLARE_TYPE( double, Real );
00412   DECLARE_TYPE( double, Real );
00413   typedef Param<Real>::type RealParam;
00414 
00415 #if defined( HAVE_LONG_DOUBLE )
00416   DECLARE_TYPE( long double, HighReal );
00417 #else
00418   DECLARE_TYPE( double, HighReal );
00419   #define HIGHREAL_IS_REAL 1
00420 #endif /* defined( HAVE_LONG_DOUBLE ) */
00421   typedef Param<HighReal>::type HighRealParam;
00422     
00423   //  DECLARE_TYPE( HighReal, Time );
00424   DECLARE_TYPE( Real, Time );
00425   typedef Param<Time>::type TimeParam;
00426     
00427   //! Infinity.  Currently this is defined as INFINITY symbol of C99 standard.
00428   const Real INF( INFINITY );
00429 
00430 
00431   //! Avogadro number. 
00432   const Real N_A( 6.0221367e+23 );
00433 
00434   //! 1 / Avogadro number (reciprocal of N_A)
00435   const Real N_A_R( 1.0 / N_A );
00436 
00437   // functions
00438 
00439 #if defined( FP_FAST_FMA )
00440   inline const Real FMA( const Real a, const Real b, const Real c )
00441   {
00442     return ::fma( a, b, c );
00443   }
00444 #else
00445   inline const Real FMA( const Real a, const Real b, const Real c )
00446   {
00447     return a * b + c;
00448   }
00449 #endif /* defined( FP_FAST_FMA ) */
00450 
00451 
00452   // MACROS
00453 
00454 #if 0
00455 
00456 #if !defined( HAVE_PRETTY_FUNCTION )
00457 #define __PRETTY_FUNCTION__ ""
00458 #endif
00459 
00460 #endif // 0
00461 
00462   /**
00463      Converts each type into a unique, insipid type.
00464      Invocation Type2Type<T> where T is a type.
00465      Defines the type OriginalType which maps back to T.
00466      
00467      taken from loki library.
00468 
00469      @ingroup util
00470   */
00471 
00472   template <typename T>
00473   struct Type2Type
00474   {
00475     typedef T OriginalType;
00476   };
00477 
00478 
00479 } // namespace libecs
00480 
00481 
00482 #endif /* __DEFS_HPP */
00483 
00484 
00485 /*
00486   Do not modify
00487   $Author: shafi $
00488   $Revision: 2559 $
00489   $Date: 2006-05-28 04:28:17 +0200 (Sun, 28 May 2006) $
00490   $Locker$
00491 */
00492 
00493 
00494 

Generated on Fri Sep 1 10:55:57 2006 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.4.7