home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / c / LEDA_GUI.lha / files.lha / incl / LEDA / basic.h
Encoding:
C/C++ Source or Header  |  1995-02-06  |  5.5 KB  |  219 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1.2
  4. +
  5. +
  6. +  basic.h
  7. +
  8. +
  9. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 66123 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. #ifndef LEDA_BASIC_H
  17. #define LEDA_BASIC_H
  18.  
  19. #include <stdlib.h>
  20.  
  21. //------------------------------------------------------------------------------
  22. // compiler/system dependent definitions and includes
  23. //------------------------------------------------------------------------------
  24.  
  25. #if defined(__SVR4) || defined(__SVR4__)
  26. #define __svr4__
  27. #endif
  28.  
  29. // g++ (version < 2.6), bcc, and ztc cannot handle template functions correctly
  30. // and we have to use the LEDA_TYPE_PARAMETER macro for class type arguments.
  31. // (see <LEDA>/prog/basic/param.c for an example)
  32.  
  33. #define __TEMPLATE_FUNCTIONS__
  34.  
  35. #if (__GNUC__ == 2 && __GNUC_MINOR__ < 6 ) || defined(__ZTC__) || defined(__BORLANDC__)
  36. #undef __TEMPLATE_FUNCTIONS__
  37. #endif
  38.  
  39. // currently only g++ (>= 2.6) has a built-in boolean type
  40.  
  41. #if (__GNUC__ > 1 && __GNUC_MINOR__ > 5)
  42. #define __BUILTIN_BOOL__
  43. #endif
  44.  
  45.  
  46. // begin_cdr
  47. // Amiga GCC 2.6.3 has inconsistent include files
  48.  
  49. #if defined(AMIGA)
  50. #define MAXFLOAT    FLT_MAX
  51. #define MAXDOUBLE    DBL_MAX
  52. #define MINFLOAT    FLT_MIN
  53. #define MINDOUBLE    DBL_MIN
  54. // value of AHZ (<sys/acct.h>)
  55. #define HZ 64
  56. #endif
  57. // end_cdr
  58.  
  59.  
  60. // linux defines random as a macro 
  61. #if defined(random)
  62. #undef random
  63. #endif
  64.  
  65.  
  66. // we assume that ztc and wcc are used under DOS
  67.  
  68. #if defined(__ZTC__) || defined(__WATCOMC__)
  69. #define __MSDOS__
  70. #endif
  71.  
  72.  
  73.  
  74. // DOS and EMX have no <values.h>
  75.  
  76. #if defined(__MSDOS__) || defined(__EMX__)
  77. #define MAXINT          (int(0x7FFFFFFF))
  78. #define MAXFLOAT    (float(3.37E+38))
  79. #define MAXDOUBLE       (double(1.797693E+308))
  80. #else
  81. #include <values.h>
  82. #endif
  83.  
  84.  
  85. // EMX and WCC  have no PI in <math.h>
  86. #if defined(__WATCOMC__) || defined (__EMX__)
  87. #define    M_PI 3.14159265358979323846
  88. #endif
  89.  
  90.  
  91. // ztc header files end with .hpp
  92. #if defined(__ZTC__)
  93. #include <iostream.hpp>
  94. #else
  95. #include <iostream.h>
  96. #endif
  97.  
  98.  
  99.  
  100. //------------------------------------------------------------------------------
  101. // Global Types
  102. //------------------------------------------------------------------------------
  103.  
  104. typedef void* GenPtr;    // generic pointer type
  105.  
  106. enum rel_pos   { before = 1, after = 0 };
  107. enum direction { forward = 0, backward = 1 };
  108.  
  109. #define nil 0
  110.  
  111.  
  112. //------------------------------------------------------------------------------
  113. // STRINGIZE: turning a macro argument into a string
  114. //------------------------------------------------------------------------------
  115.  
  116. #if defined(__STDC__)  || defined(__MSDOS__)
  117. #define STRINGIZE(x) #x
  118. #else
  119. #define STRINGIZE(x) "x"
  120. #endif
  121.  
  122.  
  123. //------------------------------------------------------------------------------
  124. // automatically included LEDA header files
  125. //------------------------------------------------------------------------------
  126.  
  127. #include <LEDA/leda.h>
  128. #include <LEDA/error.h>
  129. #include <LEDA/memory.h>
  130. #include <LEDA/param_types.h>
  131. #include <LEDA/handle_types.h>
  132. #include <LEDA/bool.h>
  133. #include <LEDA/string.h>
  134. #include <LEDA/random.h>
  135. #include <LEDA/misc.h>
  136.  
  137.  
  138.  
  139. //------------------------------------------------------------------------------
  140. // Defining Linear Orders
  141. //------------------------------------------------------------------------------
  142.  
  143. #define DEFINE_LINEAR_ORDER(type,cmp,new_type)\
  144. struct new_type : public type\
  145. { new_type(type s)            : type(s) {}\
  146.   new_type(const new_type& s) : type(s) {}\
  147.   new_type() {}\
  148.  ~new_type() {}\
  149. };\
  150. inline int compare(const new_type& x, const new_type& y) { return cmp(x,y); }
  151.  
  152.  
  153. // INT<cmp>: int with user defined linear order cmp
  154.  
  155. typedef int (*CMP_INT_TYPE)(const int&, const int&);
  156.  
  157.  
  158. template<CMP_INT_TYPE cmp> class INT {
  159.  
  160.  int p;
  161.  
  162.  public:
  163.  INT(const int i=0) { p = i;}
  164.  operator int()     { return p; }
  165.  
  166. friend void Print(const INT<cmp>& x, ostream& out) { out << x.p; }
  167. friend void Read(INT<cmp>&  x, istream& in)        { in  >> x.p; }
  168. friend void Init(INT<cmp>&  x)            { x.p=0; }
  169. friend GenPtr Copy(const INT<cmp>& x)     { return GenPtr(x); }
  170. friend void Clear(INT<cmp>& x)            { x.p = 0; }
  171. friend GenPtr Convert(const INT<cmp>& x)  { return GenPtr(x.p); }
  172. friend INT<cmp>& Access(INT<cmp>*,const GenPtr& p) { return *(INT<cmp>*)&p; }
  173. friend int compare(const INT<cmp>& x, const INT<cmp>& y) { return cmp(x.p,y.p);}
  174. };
  175.  
  176.  
  177.  
  178. //------------------------------------------------------------------------------
  179. // ITERATION 
  180. //------------------------------------------------------------------------------
  181.  
  182. #define forall_items(x,S) for(x = (S).first_item(); x; x = (S).next_item(x) )
  183.  
  184. /*
  185.    To avoid multiple declarations of the "forall_loop_item" variable
  186.    we use a dummy for-loop to create a new scope for it.
  187.    This, however, does not work with all compilers (ztc,lucid ...)
  188.    and we have to use the old forall mechanism (no nesting).
  189. */
  190.   
  191. #if defined(__ZTC__) || defined(__lucid)
  192.  
  193. #define forall(x,S)\
  194. for((S).start_iteration(); (S).read_iterator(x); (S).move_to_succ())
  195.  
  196. #define Forall(x,S)\
  197. for((S).Start_iteration(); (S).read_iterator(x); (S).move_to_pred())
  198.  
  199. #else
  200.  
  201. #define forall(x,S)\
  202. for(LEDA::loop_dummy=0; LEDA::loop_dummy<1; LEDA::loop_dummy++)\
  203. for(GenPtr forall_loop_item=(S).first_item();\
  204. (S).forall_loop_test(forall_loop_item,x);\
  205. (S).loop_to_succ(forall_loop_item))
  206.  
  207. #define Forall(x,S)\
  208. for(LEDA::loop_dummy=0; LEDA::loop_dummy<1; LEDA::loop_dummy++)\
  209. for(GenPtr forall_loop_item=(S).last_item();\
  210. (S).forall_loop_test(forall_loop_item,x);\
  211. (S).loop_to_pred(forall_loop_item))
  212.  
  213. #endif
  214.  
  215.  
  216.  
  217. #endif
  218.