00001 /* 00002 Copyright (C) 2010 - 2014 Christoph Hänisch 00003 00004 Chair of Medical Engineering (mediTEC) 00005 RWTH Aachen University 00006 Pauwelsstr. 20 00007 52074 Aachen 00008 Germany 00009 00010 See license.txt for more information. 00011 00012 Version 0.3.1 (2014-07-05) 00013 */ 00014 00020 #include <ctime> 00021 #include <fstream> 00022 #include <string> 00023 00024 #include "TRTK/Tools.hpp" 00025 00026 00027 using namespace std; 00028 00029 00030 namespace TRTK 00031 { 00032 00033 00034 namespace Tools 00035 { 00036 00037 00045 bool fileExists(const char * file_name) 00046 { 00047 ifstream file(file_name); 00048 if (file) 00049 { 00050 file.close(); 00051 return true; 00052 } 00053 else 00054 { 00055 return false; 00056 } 00057 } 00058 00059 00073 unsigned long long fileLength(const char * file_name) 00074 { 00075 ifstream file(file_name, ifstream::binary); 00076 00077 if (file) 00078 { 00079 file.seekg(0, file.end); 00080 unsigned long long length = (unsigned long long) file.tellg(); 00081 00082 file.close(); 00083 00084 return length; 00085 } 00086 else 00087 { 00088 return 0; 00089 } 00090 } 00091 00092 00111 unsigned long long fileLength(ifstream & file_stream) 00112 { 00113 unsigned long long old_position = (unsigned long long) file_stream.tellg(); 00114 00115 file_stream.seekg(0, ios::end); 00116 unsigned long long length = (unsigned long long) file_stream.tellg(); 00117 00118 file_stream.seekg(old_position); 00119 00120 return length; 00121 } 00122 00123 00129 string getCurrentDate() 00130 { 00131 time_t rawtime = time(0); 00132 tm * now = localtime(& rawtime); 00133 00134 int year = now->tm_year + 1900; 00135 int month = now->tm_mon + 1; 00136 int day = now->tm_mday; 00137 00138 char buffer[11]; 00139 sprintf(buffer, "%04i-%02i-%02i", year, month, day); 00140 00141 return string(buffer); 00142 } 00143 00144 00150 string getCurrentTime() 00151 { 00152 time_t rawtime = time(0); 00153 tm * now = localtime(& rawtime); 00154 00155 int hours = now->tm_hour; 00156 int minutes = now->tm_min; 00157 int seconds = now->tm_sec; 00158 00159 char buffer[9]; 00160 sprintf(buffer, "%02i:%02i:%02i", hours, minutes, seconds); 00161 00162 return string(buffer); 00163 } 00164 00165 00173 double randn() 00174 { 00175 return randn<double>(); 00176 } 00177 00178 00179 } // namespace Tools 00180 00181 00182 } // namespace TRTK
Documentation generated by Doxygen