Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLUtils/src/ICLUtils/Time.h ** 00010 ** Module : ICLUtils ** 00011 ** Authors: Christof Elbrechter, Robert Haschke ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #include <ICLUtils/CompatMacros.h> 00032 #include <string> 00033 #include <iostream> 00034 #include <stdint.h> 00035 00036 // ********************************************************************** 00037 // 00038 // Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. 00039 // 00040 // This copy of Ice is licensed to you under the terms described in the 00041 // ICE_LICENSE file included in this distribution. 00042 // 00043 // ********************************************************************** 00044 00045 #pragma once 00046 00047 00048 namespace icl{ 00049 namespace utils{ 00050 00052 class ICLUtils_API Time { 00053 public: 00054 00056 typedef int64_t value_type; 00057 00058 // undefined time: 0 00059 static const Time null; 00060 00061 Time(); 00062 00063 Time(value_type); 00064 00065 // No copy constructor and assignment operator necessary. The 00066 // automatically generated copy constructor and assignment 00067 // operator do the right thing. 00068 00069 static Time now(); 00070 static Time seconds(value_type); 00071 static Time milliSeconds(value_type); 00072 static Time microSeconds(value_type); 00073 00074 value_type toSeconds() const; 00075 value_type toMilliSeconds() const; 00076 value_type toMicroSeconds() const; 00077 00078 double toSecondsDouble() const; 00079 double toMilliSecondsDouble() const; 00080 double toMicroSecondsDouble() const; 00081 00082 std::string toString() const; 00083 00085 00096 std::string toStringFormated(const std::string &pattern, unsigned int bufferSize=32, bool zeropadded = false) const; 00097 00098 //xcf4cis stuff 00099 Time age() const { 00100 return Time::microSeconds(Time::now().m_usec - m_usec); 00101 } 00102 00104 inline std::string getAgeString() const{ 00105 return age().toString(); 00106 } 00107 00109 00115 inline void showAge(const std::string &title="") const{ 00116 std::cout << title << ":" << age().toMilliSecondsDouble() << "ms" << std::endl; 00117 } 00118 00119 00120 Time operator-() const 00121 { 00122 return Time(-m_usec); 00123 } 00124 00125 Time operator-(const Time& rhs) const 00126 { 00127 return Time(m_usec - rhs.m_usec); 00128 } 00129 00130 Time operator+(const Time& rhs) const 00131 { 00132 return Time(m_usec + rhs.m_usec); 00133 } 00134 00135 Time& operator+=(const Time& rhs) 00136 { 00137 m_usec += rhs.m_usec; 00138 return *this; 00139 } 00140 00141 Time& operator-=(const Time& rhs) 00142 { 00143 m_usec -= rhs.m_usec; 00144 return *this; 00145 } 00146 00147 bool operator<(const Time& rhs) const 00148 { 00149 return m_usec < rhs.m_usec; 00150 } 00151 00152 bool operator<=(const Time& rhs) const 00153 { 00154 return m_usec <= rhs.m_usec; 00155 } 00156 00157 bool operator>(const Time& rhs) const 00158 { 00159 return m_usec > rhs.m_usec; 00160 } 00161 00162 bool operator>=(const Time& rhs) const 00163 { 00164 return m_usec >= rhs.m_usec; 00165 } 00166 00167 bool operator==(const Time& rhs) const 00168 { 00169 return m_usec == rhs.m_usec; 00170 } 00171 00172 bool operator!=(const Time& rhs) const 00173 { 00174 return m_usec != rhs.m_usec; 00175 } 00176 00177 Time& operator*=(const Time& rhs) 00178 { 00179 m_usec *= rhs.m_usec; 00180 return *this; 00181 } 00182 00183 Time operator*(const Time& rhs) const 00184 { 00185 Time t; 00186 t.m_usec = m_usec * rhs.m_usec; 00187 return t; 00188 } 00189 00190 Time& operator/=(const Time& rhs) 00191 { 00192 m_usec /= rhs.m_usec; 00193 return *this; 00194 } 00195 00196 Time operator/(const Time& rhs) const 00197 { 00198 Time t; 00199 t.m_usec = m_usec / rhs.m_usec; 00200 return t; 00201 } 00202 00203 Time& operator*=(int rhs) 00204 { 00205 m_usec *= rhs; 00206 return *this; 00207 } 00208 00209 Time operator*(int rhs) const 00210 { 00211 Time t; 00212 t.m_usec = m_usec * rhs; 00213 return t; 00214 } 00215 00216 Time& operator/=(int rhs) 00217 { 00218 m_usec /= rhs; 00219 return *this; 00220 } 00221 00222 Time operator/(int rhs) const 00223 { 00224 Time t; 00225 t.m_usec = m_usec / rhs; 00226 return t; 00227 } 00228 00229 Time& operator*=(value_type rhs) 00230 { 00231 m_usec *= rhs; 00232 return *this; 00233 } 00234 00235 Time operator*(value_type rhs) const 00236 { 00237 Time t; 00238 t.m_usec = m_usec * rhs; 00239 return t; 00240 } 00241 00242 Time& operator/=(value_type rhs) 00243 { 00244 m_usec /= rhs; 00245 return *this; 00246 } 00247 00248 Time operator/(value_type rhs) const 00249 { 00250 Time t; 00251 t.m_usec = m_usec / rhs; 00252 return t; 00253 } 00254 00255 Time& operator*=(double rhs) 00256 { 00257 m_usec = static_cast<value_type>(static_cast<double>(m_usec) * rhs); 00258 return *this; 00259 } 00260 00261 Time operator*(double rhs) const 00262 { 00263 Time t; 00264 t.m_usec = static_cast<value_type>(static_cast<double>(m_usec) * rhs); 00265 return t; 00266 } 00267 00268 Time& operator/=(double rhs) 00269 { 00270 m_usec = static_cast<value_type>(static_cast<double>(m_usec) / rhs); 00271 return *this; 00272 } 00273 00274 Time operator/(double rhs) const 00275 { 00276 Time t; 00277 t.m_usec = static_cast<value_type>(static_cast<double>(m_usec) / rhs); 00278 return t; 00279 } 00280 00281 friend ICLUtils_API std::ostream& operator<<(std::ostream&, const Time&); 00282 00283 friend ICLUtils_API std::istream& operator>>(std::istream&, Time&); 00284 00285 private: 00286 00287 value_type m_usec; 00288 }; 00289 00291 ICLUtils_API std::ostream& operator<<(std::ostream&, const Time&); 00292 00294 ICLUtils_API std::istream& operator>>(std::istream&, Time&); 00295 00296 } // namespace utils 00297 } // End namespace icl 00298