00001 #ifndef _GLOBAL_HPP
00002 #define _GLOBAL_HPP
00003
00004 #include <assert.h>
00005 #include <ios>
00006 #include <iostream>
00007 #include <cmath>
00008 #include <cerrno>
00009 #include <limits>
00010
00023
00024
00025
00026 namespace Arak {
00027
00031 enum Color {
00032 WHITE = 0,
00033 BLACK,
00034 INVALID_COLOR
00035 };
00036
00040 static inline Color opposite(Color c) {
00041 switch (c) {
00042 case WHITE:
00043 return BLACK;
00044 case BLACK:
00045 return WHITE;
00046 default:
00047 assert(false);
00048 }
00049 }
00050
00063 template<typename charT, typename traits>
00064 std::basic_istream<charT,traits>&
00065 skipline(std::basic_istream<charT,traits>& in) {
00066 charT c;
00067 while (in.get(c) && (c != '\n'))
00068 ;
00069 return in;
00070 }
00071
00088 template<typename charT, typename traits>
00089 std::basic_istream<charT,traits>&
00090 skipcomments(std::basic_istream<charT,traits>& in) {
00091 while (true) {
00092 in >> std::ws;
00093 if (in.peek() == '#')
00094 in >> skipline;
00095 else break;
00096 }
00097 return in;
00098 }
00099
00105 inline double ln(double x) {
00106 assert(x >= 0.0);
00107 if (x == 0.0)
00108 return -std::numeric_limits<double>::infinity();
00109 else
00110 return std::log(x);
00111 }
00112
00113 }
00114
00115 #endif