knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::TimeInterval Class Reference

#include <TimeInterval.h>

Inheritance diagram for knowrob::TimeInterval:
Collaboration diagram for knowrob::TimeInterval:

Public Member Functions

 TimeInterval (const std::optional< TimePoint > &since, const std::optional< TimePoint > &until)
 
bool operator== (const TimeInterval &other) const
 
std::shared_ptr< TimeIntervalintersectWith (const TimeInterval &other) const
 
const auto & since () const
 
const auto & until () const
 
void write (std::ostream &os) const override
 
 TimeInterval (const std::optional< TimePoint > &since, const std::optional< TimePoint > &until)
 
bool operator== (const TimeInterval &other) const
 
std::shared_ptr< TimeIntervalintersectWith (const TimeInterval &other) const
 
const auto & since () const
 
const auto & until () const
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Static Public Member Functions

static const TimeIntervalanytime ()
 
static TimeInterval currently ()
 
static TimeInterval during (const TimePoint &begin, const TimePoint &end)
 
static const TimeIntervalanytime ()
 
static TimeInterval currently ()
 
static TimeInterval during (const TimePoint &begin, const TimePoint &end)
 

Protected Attributes

std::optional< TimePointsince_
 
std::optional< TimePointuntil_
 

Detailed Description

A fuzzy time interval where start and end time point lie within a range.

Definition at line 19 of file TimeInterval.h.

Constructor & Destructor Documentation

◆ TimeInterval() [1/2]

TimeInterval::TimeInterval ( const std::optional< TimePoint > &  since,
const std::optional< TimePoint > &  until 
)
Parameters
sincethe time point where the interval starts
untilthe time point where the interval ends

Definition at line 10 of file TimeInterval.cpp.

11  : since_(since),
12  until_(until) {}
std::optional< TimePoint > until_
Definition: TimeInterval.h:71
std::optional< TimePoint > since_
Definition: TimeInterval.h:70
const auto & since() const
Definition: TimeInterval.h:59
const auto & until() const
Definition: TimeInterval.h:64

◆ TimeInterval() [2/2]

knowrob::TimeInterval::TimeInterval ( const std::optional< TimePoint > &  since,
const std::optional< TimePoint > &  until 
)
Parameters
sincethe time point where the interval starts
untilthe time point where the interval ends

Member Function Documentation

◆ anytime() [1/2]

const TimeInterval & TimeInterval::anytime ( )
static
Returns
a time interval without further constraints on begin and end time point of the interval.

Definition at line 18 of file TimeInterval.cpp.

18  {
19  static const TimeInterval timeInterval(std::nullopt, std::nullopt);
20  return timeInterval;
21 }

◆ anytime() [2/2]

static const TimeInterval& knowrob::TimeInterval::anytime ( )
static
Returns
a time interval without further constraints on begin and end time point of the interval.

◆ currently() [1/2]

TimeInterval TimeInterval::currently ( )
static
Returns
a time interval that at least intersects with the current time.

Definition at line 23 of file TimeInterval.cpp.

23  {
25  return {now, now};
26 }
TimePoint now()
Definition: TimePoint.cpp:12
std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds > TimePoint
Definition: TimePoint.h:16

◆ currently() [2/2]

static TimeInterval knowrob::TimeInterval::currently ( )
static
Returns
a time interval that at least intersects with the current time.

◆ during() [1/2]

TimeInterval TimeInterval::during ( const TimePoint begin,
const TimePoint end 
)
static
Parameters
beginthe begin time point of the interval
endthe end time point of the interval
Returns
a time interval that is valid between the given time points

Definition at line 28 of file TimeInterval.cpp.

28  {
29  return {begin, end};
30 }

◆ during() [2/2]

static TimeInterval knowrob::TimeInterval::during ( const TimePoint begin,
const TimePoint end 
)
static
Parameters
beginthe begin time point of the interval
endthe end time point of the interval
Returns
a time interval that is valid between the given time points

◆ intersectWith() [1/2]

std::shared_ptr< TimeInterval > TimeInterval::intersectWith ( const TimeInterval other) const

Intersect this time interval with another one.

Parameters
otheranother time interval.

Definition at line 32 of file TimeInterval.cpp.

32  {
33  return std::make_shared<TimeInterval>(std::max(since_, other.since_), std::min(until_, other.until_));
34 }

◆ intersectWith() [2/2]

std::shared_ptr<TimeInterval> knowrob::TimeInterval::intersectWith ( const TimeInterval other) const

Intersect this time interval with another one.

Parameters
otheranother time interval.

◆ operator==() [1/2]

bool TimeInterval::operator== ( const TimeInterval other) const
Parameters
otheranother time interval
Returns
true if both time intervals are equal

Definition at line 14 of file TimeInterval.cpp.

14  {
15  return since_ == other.since_ && until_ == other.until_;
16 }

◆ operator==() [2/2]

bool knowrob::TimeInterval::operator== ( const TimeInterval other) const
Parameters
otheranother time interval
Returns
true if both time intervals are equal

◆ since() [1/2]

const auto& knowrob::TimeInterval::since ( ) const
inline
Returns
the begin time point of the interval

Definition at line 59 of file TimeInterval.h.

59 { return since_; }

◆ since() [2/2]

const auto& knowrob::TimeInterval::since ( ) const
inline
Returns
the begin time point of the interval

Definition at line 59 of file TimeInterval.h.

59 { return since_; }

◆ until() [1/2]

const auto& knowrob::TimeInterval::until ( ) const
inline
Returns
the end time point of the interval

Definition at line 64 of file TimeInterval.h.

64 { return until_; }

◆ until() [2/2]

const auto& knowrob::TimeInterval::until ( ) const
inline
Returns
the end time point of the interval

Definition at line 64 of file TimeInterval.h.

64 { return until_; }

◆ write() [1/2]

void TimeInterval::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 36 of file TimeInterval.cpp.

36  {
37  os << '[';
38  if (since().has_value()) time::write(since().value(), os);
39  else os << '_';
40  os << ",";
41  if (until().has_value()) time::write(until().value(), os);
42  else os << '_';
43  os << ']';
44 }
void write(const TimePoint &tp, std::ostream &os)
Definition: TimePoint.cpp:28

◆ write() [2/2]

void knowrob::TimeInterval::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Member Data Documentation

◆ since_

std::optional< TimePoint > knowrob::TimeInterval::since_
protected

Definition at line 70 of file TimeInterval.h.

◆ until_

std::optional< TimePoint > knowrob::TimeInterval::until_
protected

Definition at line 71 of file TimeInterval.h.


The documentation for this class was generated from the following files: