MSec

Files CCore/inc/gadget/MSec.h CCore/src/gadget/MSec.cpp

MSec represents a time in the millisecond units. Usually it is used to represent timeouts or short time intervals. To create a MSec you can use the following user-defined literals:


100_msec // 100 milliseconds
10_sec   // 10 seconds
5_min    // 5 minutes
1_hour   // 1 hour

You can also sum MSecs or multiply by unsigned:


10*1_hour+25_min

There are few helper methods of the class:


struct MSec
 {
  unsigned time;                                                    // in milliseconds
  
  // constructors

  // no default constructor -- this is deliberate
  
  constexpr MSec(NothingType) : time(0) {}                          // null value
  
  explicit constexpr MSec(unsigned time_) : time(time_) {}          // given value
  
  // methods
  
  constexpr unsigned operator + () const { return time; }           // extract time
                                                                    // time is not null
  
  constexpr bool operator ! () const { return !time; }              // time is null
  
  MSec cap(MSec lim) { Replace_min(time,lim.time); return *this; }  // cap self to limit
 };

MSec methods and functions are constexpr (except cap), so you can use it to create constants.