misc.h
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:3k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  misc.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef LEDA_MISC_H
  12. #define LEDA_MISC_H
  13. /*{Manpage {misc} {} {Some Useful Functions}  }*/
  14. /*{Mtext
  15. The following functions and macros are defined in <LEDA/basic.h>.
  16. }*/
  17. int    read_int();
  18. int    read_int(string s);
  19. /*{Mfunc  prints $s$ and reads an integer from $cin$.}*/
  20. double read_real();
  21. double read_real(string s);
  22. /*{Mfunc  prints $s$ and reads a real number from $cin$.}*/
  23. void skip_line(istream& =cin);
  24. string read_line(istream& =cin);
  25. string read_string();
  26. string read_string(string s);
  27. /*{Mfunc  prints $s$ and reads a line from $cin$.}*/
  28. char   read_char();
  29. char   read_char(string s);
  30. /*{Mfunc  prints $s$ and reads a character from $cin$.}*/
  31. int   Yes();
  32. int   Yes(string s);
  33. /*{Mfunc  returns (read_char($s$) == `y').}*/
  34. float used_time();
  35. /*{Mfunc  returns the currently used cpu time in seconds.}*/
  36. float used_time(float& T);
  37. /*{Mfunc  returns the cpu time used by the program from time
  38.            $T$ up to this moment and assigns the current
  39.            time to $T$.}*/
  40. void  print_time(string s);
  41. void  print_time();
  42. void  wait(float sec);  
  43. /*{Mfunc suspends execution for $sec$ seconds.}*/
  44. /*{Mtext
  45. func void      print_statistics() { }  
  46.                            {prints a summary of the currently used memory.}
  47. }*/
  48. typedef int (*LEDA_SIG_PF) (...);
  49. extern LEDA_SIG_PF catch_interrupts(LEDA_SIG_PF handler = nil);
  50. // maximal and minimal values for some numerical types
  51. inline int    Max_Value(int& x)     { return x =  MAXINT;   }
  52. inline int    Min_Value(int& x)     { return x = -MAXINT;   }
  53. inline float  Max_Value(float& x)   { return x =  MAXFLOAT; }
  54. inline float  Min_Value(float& x)   { return x = -MAXFLOAT; }
  55. inline double Max_Value(double& x)  { return x =  MAXDOUBLE;}
  56. inline double Min_Value(double& x)  { return x = -MAXDOUBLE;}
  57. #if defined(__TEMPLATE_FUNCTIONS__) &&  (__SUNPRO_CC != 0x400)
  58. template <class T> inline 
  59. T Max(const T& a, const T& b) { return (a>b) ? a : b; }
  60. /*{Mfunc     returns the maximum of $a$ and $b$. } */
  61. template <class T> inline 
  62. T Min(const T& a, const T& b) { return (a<b) ? a : b; }
  63. /*{Mfunc     returns the minimum of $a$ and $b$. } */
  64. #else
  65. #define Max(a,b)        (((a)>(b)) ? (a) : (b))
  66. #define Min(a,b)        (((a)>(b)) ? (b) : (a))
  67. #endif
  68. #define newline         cout << endl
  69. #endif