00001 #if defined(__unix__) 00002 #include <unistd.h> 00003 #include <pwd.h> 00004 #include <sys/time.h> 00005 #include <sys/times.h> 00006 #include <sys/types.h> 00007 #endif 00008 00009 #include "util.h" 00010 00011 float used_time() 00012 { 00013 #if defined(__unix__) 00014 00015 #if defined(CLK_TCK) 00016 long clk_tck = CLK_TCK; 00017 #else 00018 long clk_tck = HZ; 00019 //long clk_tck = sysconf(_SC_CLK_TCK); 00020 #endif 00021 00022 tms x; 00023 times(&x); 00024 return float(x.tms_utime)/clk_tck; 00025 00026 #else 00027 00028 return float(clock())/CLOCKS_PER_SEC; 00029 00030 #endif 00031 } 00032 00033 00034 float used_time(float& T) 00035 { float t = T; 00036 T = used_time(); 00037 return T-t; 00038 } 00039 00040 00041 00042 ostream& operator<<(ostream& out, const list<string>& L) 00043 { 00044 list<string>::iterator x; 00045 list<string> vl; 00046 vl = L; 00047 for (x = vl.begin(); x != vl.end(); x++) 00048 out << *x << "\n"; 00049 return out; 00050 } 00051 00052 00053 istream& operator>>(istream& in, list<string>& L) 00054 { 00055 L.clear(); 00056 string x; 00057 for(;;) 00058 { 00059 char c; 00060 while (in.get(c) && isspace(c)); 00061 if (!in) break; 00062 in.putback(c); 00063 x = string(); in >> x; L.push_back(x); 00064 } 00065 return in; 00066 } 00067 00068 ostream& operator<<(ostream& out, const list<int>& L) 00069 { 00070 list<int>::iterator x; 00071 list<int> vl; 00072 vl = L; 00073 for (x = vl.begin(); x != vl.end(); x++) 00074 out << *x << "\n"; 00075 return out; 00076 } 00077 00078 00079 istream& operator>>(istream& in, list<int>& L) 00080 { 00081 L.clear(); 00082 int x; 00083 for(;;) 00084 { 00085 char c; 00086 while (in.get(c) && isspace(c)); 00087 if (!in) break; 00088 in.putback(c); 00089 in >> x; L.push_back(x); 00090 } 00091 return in; 00092 } 00093 00094 00095 bool is_file(string fname) 00096 { struct stat stat_buf; 00097 if (stat(fname.c_str(),&stat_buf) != 0) return false; 00098 return (stat_buf.st_mode & S_IFMT) == S_IFREG; 00099 } 00100 00101 00102 bool is_directory(string fname) 00103 { struct stat stat_buf; 00104 if (stat(fname.c_str(),&stat_buf) != 0) return false; 00105 return (stat_buf.st_mode & S_IFMT) == S_IFDIR; 00106 }