Changeset 84:f328970a6b47 in rrlib_util


Ignore:
Timestamp:
03.06.2013 17:16:48 (6 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Parents:
81:594fc1ba6b32 (diff), 83:10f32063cdf7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merged with changes from RRLab

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sFileIOUtils.cpp

    r80 r84  
    204204 
    205205//---------------------------------------------------------------------- 
     206// class sFileIOUtils::FileExists() 
     207//---------------------------------------------------------------------- 
     208bool sFileIOUtils::FileExists(const std::string &filename) 
     209{ 
     210  // catch empty file 
     211  if (filename == "") 
     212  { 
     213    return false; 
     214  } 
     215 
     216  // test if file exists 
     217  FILE* file = fopen(filename.c_str(), "rb"); 
     218  if (file == 0) 
     219  { 
     220    return false; 
     221  } 
     222  fclose(file); 
     223 
     224  return true; 
     225} 
     226 
     227 
     228//---------------------------------------------------------------------- 
    206229// class sFileIOUtils::ShellExpandFilename() 
    207230//---------------------------------------------------------------------- 
  • sFileIOUtils.cpp

    r83 r84  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    sFileIOUtils.cpp 
     22/*!\file    rrlib/util/sFileIOUtils.cpp 
    2323 * 
    2424 * \author  Bernd Helge Schaefer 
    2525 * \author  Jens Wettach 
    2626 * \author  Tim Braun 
    27  * \date    15.11.05 
     27 * 
     28 * \date    2005-11-15 
    2829 * 
    2930 */ 
  • sFileIOUtils.h

    r80 r84  
    122122   */ 
    123123  static void DecompressFile(const std::string& input_filename, const std::string& output_filename); 
     124 
     125 
     126  /*! 
     127   * \brief Test if file exists for given file name 
     128   * 
     129   * \returns true if file exists 
     130   */ 
     131  static bool FileExists(const std::string &filename); 
    124132 
    125133 
  • sFileIOUtils.h

    r83 r84  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    sFileIOUtils.h 
     22/*!\file    rrlib/util/sFileIOUtils.h 
    2323 * 
    2424 * \author  Bernd Helge Schaefer 
    2525 * \author  Jens Wettach 
    26  * \date    15.11.05 
     26 * 
     27 * \date    2005-11-15 
    2728 * 
    2829 * \brief   Contains static class sFileIOUtils 
  • tTime.h

    r80 r84  
    3535#include <sys/time.h> 
    3636#include <iostream> 
     37#include "rrlib/time/time.h" 
    3738 
    3839namespace rrlib 
     
    5152//! Repesents times (absolutes and differences) 
    5253/*! Use this class whenever you want to deal with times, 
    53   as it provides a number of operators and functions. 
     54 as it provides a number of operators and functions. 
    5455 */ 
    55 class  tTime 
     56class tTime 
    5657{ 
    5758public: 
     
    6263    tv_sec = 0; 
    6364    tv_usec = 0; 
    64   }; 
    65  
     65  } 
     66  ; 
    6667 
    6768  //! constructor, takes a timeval for creation 
     
    8788  } 
    8889 
     90  //! constructor that gets a time in seconds plus microseconds 
     91  tTime(const rrlib::time::tTimestamp &timestamp) 
     92  { 
     93    // 1970-01-01T00:00:00+00:00 
     94    const rrlib::time::tTimestamp unix_timestamp = std::chrono::system_clock::from_time_t(0); 
     95    rrlib::time::tDuration duration = timestamp - unix_timestamp; 
     96    tv_sec = std::chrono::duration_cast < std::chrono::seconds > (duration).count(); 
     97    tv_usec = std::chrono::duration_cast < std::chrono::microseconds > (duration).count() - tv_sec * 1000000; 
     98    NormalizeTime(); 
     99  } 
     100 
    89101  //! This static function returns a tTime that contains the current System-time 
    90102  static inline tTime Now() 
     
    96108 
    97109  /*! Returns the time of the current thread (time elapsed since start 
    98     of thread. It exists only for internal MCA usage. You do not need 
    99     to call it directly. */ 
     110   of thread. It exists only for internal MCA usage. You do not need 
     111   to call it directly. */ 
    100112  static inline tTime TaskTime() 
    101113  { 
     
    121133 
    122134  /*! Returns a time that is calculated by 
    123     tTime::Now()+tTime.FromMSec(msec) 
    124   */ 
     135   tTime::Now()+tTime.FromMSec(msec) 
     136   */ 
    125137  static inline tTime FutureMSec(long msec) 
    126138  { 
     
    195207 
    196208  /*! Returns tTime in nanoseconds */ 
    197   inline long long ToNSec()const 
     209  inline long long ToNSec() const 
    198210  { 
    199211    return ((long long)tv_usec + (long long)tv_sec * 1000000) * 1000; 
     
    201213 
    202214  /*! Returns tTime in microseconds */ 
    203   inline long long ToUSec()const 
     215  inline long long ToUSec() const 
    204216  { 
    205217    return (long long)tv_usec + (long long)tv_sec * 1000000; 
     
    207219 
    208220  /*! Returns tTime in milli seconds rounded down to an long integer.*/ 
    209   inline long long ToMSec()const 
     221  inline long long ToMSec() const 
    210222  { 
    211223    return (long long)tv_usec / 1000 + (long long)tv_sec * 1000; 
     
    213225 
    214226  /*! Returns tTime in seconds rounded down to an long integer.*/ 
    215   inline long ToSec()const 
     227  inline long ToSec() const 
    216228  { 
    217229    return tv_sec; 
     
    219231 
    220232  /*! Don't use this function: Returns the tv_sec value if timeval which is the basis of tTime */ 
    221   inline long TvSec()const 
     233  inline long TvSec() const 
    222234  { 
    223235    return tv_sec; 
     
    249261 
    250262  /*! Use this function if you want to express the time in hours, minutes and seconds */ 
    251   inline int Hours()const 
     263  inline int Hours() const 
    252264  { 
    253265    return tv_sec / 3600 % 24; 
     
    255267 
    256268  /*! Use this function if you want to express the time in hours, minutes and seconds */ 
    257   inline int Minutes()const 
     269  inline int Minutes() const 
    258270  { 
    259271    return (tv_sec % 3600) / 60; 
     
    261273 
    262274  /*! Use this function if you want to express the time in hours, minutes and seconds */ 
    263   inline int Seconds()const 
     275  inline int Seconds() const 
    264276  { 
    265277    return (tv_sec % 3600) % 60; 
     
    267279 
    268280  /*! Use this function if you want to get the subseconds in milliseconds (rounded) */ 
    269   inline int MSeconds()const 
     281  inline int MSeconds() const 
    270282  { 
    271283    return tv_usec / 1000; 
     
    273285 
    274286  /*! Adds two times */ 
    275   inline tTime operator+(const tTime& b)const 
     287  inline tTime operator+(const tTime& b) const 
    276288  { 
    277289    tTime a = *this; 
     
    290302 
    291303  /*! Substracts the second time from the first */ 
    292   inline tTime operator-(const tTime& b)const 
     304  inline tTime operator-(const tTime& b) const 
    293305  { 
    294306    tTime a = *this; 
     
    307319 
    308320  /*! sign operator */ 
    309   inline tTime operator-()const 
     321  inline tTime operator-() const 
    310322  { 
    311323    tTime a(-tv_sec, tv_usec); 
     
    316328 
    317329  /*! Multiplies the time by a factor. Uses operator*= (see below). */ 
    318   inline tTime operator*(double factor)const 
     330  inline tTime operator*(double factor) const 
    319331  { 
    320332    tTime a = *this; 
     
    332344 
    333345  /*! Compares two variables of type tTime. Returns true if they are not equal*/ 
    334   inline bool operator!=(const tTime& b)const 
     346  inline bool operator!=(const tTime& b) const 
    335347  { 
    336348    return (tv_usec != b.tv_usec) || (tv_sec != b.tv_sec); 
     
    367379  } 
    368380 
     381  operator rrlib::time::tTimestamp() 
     382  { 
     383    rrlib::time::tTimestamp timestamp = std::chrono::system_clock::from_time_t((time_t) this->tv_sec); 
     384    return timestamp + std::chrono::duration_cast<rrlib::time::tDuration>(std::chrono::microseconds(this->tv_usec)); 
     385  } 
     386 
    369387  /*! Casts this tTime object into timespec object (consists of tv_sec/tv_nsec, see h)*/ 
    370388  operator timespec() 
    371389  { 
    372     timespec t = {tv_sec, 1000 * tv_usec}; 
     390    timespec t = { tv_sec, 1000 * tv_usec }; 
    373391    return t; 
    374392  } 
     
    381399    return std::string(buffer); 
    382400  } 
    383  
    384401 
    385402  // some standard time intervals to be used for timeouts etc 
     
    418435 
    419436  /*! Makes sure that tv_usec lies in the interval [0; 1000000] by: 
    420       - converting multiples of 1000000 usec into multiples of sec 
    421       - transforming tv_sec and tv_usec so that the usec part is positive 
    422   */ 
     437   - converting multiples of 1000000 usec into multiples of sec 
     438   - transforming tv_sec and tv_usec so that the usec part is positive 
     439   */ 
    423440  inline void NormalizeTime() 
    424441  { 
     
    430447    if (tv_usec < 0) 
    431448    { 
    432       tv_sec --; 
     449      tv_sec--; 
    433450      tv_usec += 1000000; 
    434451    } 
     
    466483} 
    467484 
     485 
    468486#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
    469487 
  • tTime.h

    r82 r84  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    tTime.h 
     22/*!\file    rrlib/util/tTime.h 
     23 * 
     24 * \author  Jens Wettach 
     25 * 
     26 * \date    2011-01-04 
     27 * 
     28 * \brief 
    2329 * 
    2430 */ 
Note: See TracChangeset for help on using the changeset viewer.