47 #ifndef _MIRA_TIMEHUMANREADABLE_H_ 48 #define _MIRA_TIMEHUMANREADABLE_H_ 84 namespace HumanReadableSerialization {
91 template<
bool AsString = true>
96 #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR) 126 template<
typename Reflector>
129 std::string s = to_iso_extended_string(date);
133 template<
typename Reflector>
136 DateSerializedAsYMD::ymd_type ymd = date.year_month_day();
140 r.member(
"Year", y,
"year");
141 r.member(
"Month", m,
"month");
142 r.member(
"Day", d,
"day");
144 r.roproperty(
"Weekday", boost::lexical_cast<std::string>(date.day_of_week()),
148 template<
typename Reflector>
153 date = boost::gregorian::from_string(s);
156 template<
typename Reflector>
160 r.member(
"Year", y,
"");
161 r.member(
"Month", m,
"");
162 r.member(
"Day", d,
"");
171 namespace HumanReadableSerialization {
178 template<
bool AsString = true>
182 #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR) 190 template<
typename Reflector>
193 if constexpr (AsString) {
194 std::string s = to_simple_string(*
this);
202 r.member(
"Hours", h,
"Hours 0..23");
203 r.member(
"Minutes", m,
"Minutes 0..59");
204 r.member(
"Seconds", s,
"Seconds 0..59");
205 r.member(
"MicroSeconds", us,
"Microseconds 0..999999 (optional, default=0)");
209 template<
typename Reflector>
212 if constexpr (AsString) {
215 if (s.find(
':') == std::string::npos) {
216 MIRA_THROW(XIO,
"DurationSerializedAsIsoString: Duration string for deserialization " 217 "expects format 'hh:mm[:ss[.frac]]'");
219 *
this =
Base(boost::posix_time::duration_from_string(s));
222 r.member(
"Hours", h,
"Hours 0..23");
223 r.member(
"Minutes", m,
"Minutes 0..59");
224 r.member(
"Seconds", s,
"Seconds 0..59");
225 r.member(
"MicroSeconds", us,
"Microseconds 0..999999 (optional, default=0)", 0);
227 *
this =
Base(h, m, s, us);
233 if constexpr (AsString) {
238 getter<bool>([
this]{
return !is_negative(); }),
239 setter<bool>([
this](
bool p){
if (p == is_negative()) *
this = invert_sign(); }),
242 getter<int>([
this]{
return std::abs(
hours()); }),
243 setter<int>([
this](
int h){
244 int hs = (is_negative() ? -h : h);
250 getter<int>([
this]{
return std::abs(
minutes()); }),
251 setter<int>([
this](
int m){
252 int ms = (is_negative() ? -m : m);
258 getter<int>([
this]{
return std::abs(
seconds()); }),
259 setter<int>([
this](
int s){
260 int ss = (is_negative() ? -s : s);
266 getter<int>([
this]{
return std::abs(
milliseconds()) * 1000ll
268 setter<int>([
this](
int us){
269 int uss = (is_negative() ? -us : us);
297 namespace HumanReadableSerialization {
304 template<
bool AsString = true>
308 #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR) 316 template<
typename Reflector>
319 if constexpr (AsString) {
320 std::string s = to_iso_extended_string(*
this);
329 template<
typename Reflector>
332 if constexpr (AsString) {
335 if (s.find(
'T') == std::string::npos) {
336 MIRA_THROW(XIO,
"TimeSerializedAsIsoString: Time string for deserialization " 337 "expects format 'yyyy-mm-ddThh:mm:ss[.frac]'");
339 #if BOOST_VERSION >= 107300 340 *
this =
Base(boost::posix_time::from_iso_extended_string(s));
342 *
this =
Base(boost::date_time::parse_delimited_time<Base>(s,
'T'));
351 *
this =
Base(date, timeOfDay);
357 if constexpr (AsString) {
365 getter<int>([
this]{
return date().year();}),
366 setter<int>([
this](
int y){
368 *
this =
Base(
Date(y, d.month(), d.day()),
373 getter<int>([
this]{
return date().month();}),
374 setter<int>([
this](
int m){
376 *
this =
Base(
Date(d.year(), m, d.day()),
381 getter<int>([
this]{
return date().day();}),
382 setter<int>([
this](
int dy){
384 *
this =
Base(
Date(d.year(), d.month(), dy),
389 getter<std::string>([
this]{
390 return boost::lexical_cast<std::string>(date().day_of_week());
394 getter<int>([
this]{
return time_of_day().hours(); }),
395 setter<int>([
this](
int h){
396 auto t = time_of_day();
397 *
this =
Base(date(),
Duration(h, t.minutes(), t.seconds(),
398 t.total_microseconds() % 1000000ll));
402 getter<int>([
this]{
return time_of_day().minutes(); }),
403 setter<int>([
this](
int m){
404 auto t = time_of_day();
405 *
this =
Base(date(),
Duration(t.hours(), m, t.seconds(),
406 t.total_microseconds() % 1000000ll));
410 getter<int>([
this]{
return time_of_day().seconds(); }),
411 setter<int>([
this](
int s){
412 auto t = time_of_day();
413 *
this =
Base(date(),
Duration(t.hours(), t.minutes(), s,
414 t.total_microseconds() % 1000000ll));
418 getter<int>([
this]{
return time_of_day().total_microseconds() % 1000000ll; }),
419 setter<int>([
this](
int us){
420 auto t = time_of_day();
421 *
this =
Base(date(),
Duration(t.hours(), t.minutes(), t.seconds(), us));
447 template<
typename SerializerTag>
450 template<
typename SerializerTag>
453 template<
typename SerializerTag>
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Definition: TimeHumanReadable.h:191
void reflectWrite(Reflector &r)
Definition: TimeHumanReadable.h:210
void reflectWrite(Reflector &r, Buffer< T, Allocator > &c)
Specialization of the non-intrusive reflect for Buffer.
Definition: Buffer.h:581
Type trait that indicates whether a type should be serialized "transparently", i.e.
Definition: IsTransparentSerializable.h:81
tick_type milliseconds() const
Returns normalized number of milliseconds (0..999)
Definition: Time.h:285
#define MIRA_SPLIT_REFLECT(Type)
Macro that inserts a reflect() method consisting of just a call to splitReflect() (splitting to refle...
Definition: SplitReflect.h:150
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Duration()
Default constructor constructs to Duration of 0 length.
Definition: Time.h:206
#define MIRA_SPLIT_REFLECT_MEMBER
Macro that insert a class member reflect() method just splitting reflection into a reflectRead() and ...
Definition: SplitReflect.h:209
Time and Duration wrapper class.
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
mira::Date Base
Definition: TimeHumanReadable.h:94
Contains internal accessor class that abstracts from the underlying getter and setter classes or dire...
void reflect(PropertySerializer &r)
Definition: TimeHumanReadable.h:355
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Derivation of mira::Date with human-readable serialization.
Definition: TimeHumanReadable.h:92
boost::posix_time::ptime Base
Definition: Time.h:422
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Definition: TimeHumanReadable.h:317
Flags controlling reflector behaviour.
Derivation of mira::Duration with human-readable serialization.
Definition: TimeHumanReadable.h:179
Time()
Default constructor constructs to not_a_date_time.
Definition: Time.h:451
Commonly used exception classes.
boost::posix_time::time_duration Base
Definition: Time.h:110
Serializer that handles properties and creates PropertyNodes.
PropertyHint limits(const T &min, const T &max)
Sets both attributes "minimum" and "maximum" to the specified values.
Definition: PropertyHint.h:275
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
min_type minutes() const
Returns normalized number of minutes (0..59)
Definition: Time.h:275
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:280
void roproperty(const char *name, const T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:213
Use this class to represent time durations.
Definition: Time.h:106
boost::gregorian::date Date
Typedef for the boost Gregorian calendar date.
Definition: Time.h:70
Type trait to define if a class is cheap to copy.
hour_type hours() const
Returns number of hours in the duration.
Definition: Time.h:270
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:137
A special PropertyReflector that creates a PropertyNode for each reflected property.
Definition: PropertySerializer.h:67
Setter< DateSerializedAsIsoString > humanReadableSetter(Date &date)
Setter for Date using DateSerializedAsIsoString proxy.
tick_type microseconds() const
Returns normalized number of microseconds (0..999)
Definition: Time.h:290
PropertyHint minimum(const T &min)
Sets the attribute "minimum" to the specified value.
Definition: PropertyHint.h:243
Date()
Definition: TimeHumanReadable.h:97
mira::Time Base
Definition: TimeHumanReadable.h:307
The Accessor class is used as an adapter to reduce the code bloat within the reflection and serializa...
Definition: Accessor.h:244
void reflectWrite(Reflector &r)
Definition: TimeHumanReadable.h:330
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
void reflectRead(Reflector &r, Buffer< T, Allocator > &c)
Specialization of the non-intrusive reflect for Buffer.
Definition: Buffer.h:565
Time()
Definition: TimeHumanReadable.h:309
Date(const Base &date)
Definition: TimeHumanReadable.h:99
TimeTypesSerializedAsElements()=default
void reflect(PropertySerializer &r)
Definition: TimeHumanReadable.h:231
Getter< DateSerializedAsIsoString > humanReadableGetter(const Date &date)
In addition to classes which can replace Date/Duration/Time, there are getters/setters/accessors for ...
Accessor< Getter< DateSerializedAsIsoString >, Setter< DateSerializedAsIsoString > > humanReadableAccessor(Date &date)
Accessor for Date using DateSerializedAsIsoString proxy.
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:126
Duration(const Base &date)
Definition: TimeHumanReadable.h:185
mira::Duration Base
Definition: TimeHumanReadable.h:181
HumanReadableSerialization::Duration< false > DurationSerializedAsHMS
Derivation of mira::Duration with serialization as hours/minutes/seconds/milli-/microseconds members...
Definition: TimeHumanReadable.h:285
Time(const Base &date)
Definition: TimeHumanReadable.h:311
HumanReadableSerialization::Date< false > DateSerializedAsYMD
Derivation of mira::Date with serialization as year/month/day members.
Definition: TimeHumanReadable.h:111
Derivation of mira::Time with human-readable serialization.
Definition: TimeHumanReadable.h:305
Duration()
Definition: TimeHumanReadable.h:183
A tag type used as parameter type in humanReadableGetter, humanReadableSetter, humanReadableAccessor ...
Definition: TimeHumanReadable.h:470