@Joel: a simple convenience wrapper for gavl_time_t

This commit is contained in:
Fischlurch 2008-10-16 20:31:02 +02:00
parent 0595767736
commit dedb70aac9
3 changed files with 39 additions and 24 deletions

View file

@ -1,5 +1,5 @@
/*
Time - unified representation of a time point, including conversion functions
Time - convenience wrapper for working with gavl_time in C++
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
@ -28,10 +28,9 @@
namespace lumiera
{
// TODO: dummy values; should be adjusted when switching to the real time implementation provided by the backend
const Time Time::MAX = +std::numeric_limits<long>::max();
const Time Time::MIN = -std::numeric_limits<long>::max();
const Time Time::MAX = +std::numeric_limits<int64_t>::max();
const Time Time::MIN = -std::numeric_limits<int64_t>::max();
} // namespace lumiera

View file

@ -1,5 +1,5 @@
/*
LUMITIME.hpp - unified representation of a time point, including conversion functions
LUMITIME.hpp - convenience wrapper for working with gavl_time in C++
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
@ -26,35 +26,51 @@
#include <boost/operators.hpp>
extern "C" {
#include <gavl/gavltime.h>
}
namespace lumiera
{
namespace lumiera {
/**
* denotes a temporal position (time point), based on timeline start.
* C++ convenience wrapper representing a time value, which could denote
* a temporal position (time point) relative to an (implicit) timeline zero
* point, or it could represent a time interval.
*
* @todo currently (9/07) this is a dummy implementation to find out
* what interface the Proc layer needs. Cehteh has already written
* elaborate timehandling functions in the backend and the goal
* is for class Time to be just a thin wrapper!
* @note this is currently (10/08) an experimental implementation to ease
* the time handling within C++ code. It is advisable not to use it
* on external interfaces (use gavl_time_t there please).
*/
class Time : boost::totally_ordered<Time>
class Time
: boost::additive<Time,
boost::multipliable<Time, int64_t,
boost::totally_ordered<Time> > >
{
long dummy;
gavl_time_t t_;
public:
Time(long dum=0) : dummy(dum) {}
operator long () { return dummy; }
bool operator< (const Time& ot) const { return dummy < ot.dummy; }
bool operator== (const Time& ot) const { return dummy == ot.dummy; }
static const Time MAX ;
static const Time MIN ;
Time(gavl_time_t val=0) : t_(val) {}
operator gavl_time_t () { return t_; }
// Supporting additive
Time& operator+= (Time const& tx) { t_ += tx.t_; return *this; }
Time& operator-= (Time const& tx) { t_ -= tx.t_; return *this; }
// Supporting multiplication with integral factor
Time& operator*= (int64_t fact) { t_ *= fact; return *this; }
// Supporting totally_ordered
friend bool operator< (Time const& t1, Time const& t2) { return t1.t_ < t2.t_; }
friend bool operator== (Time const& t1, Time const& t2) { return t1.t_ == t2.t_; }
};
} // namespace lumiera
#endif

View file

@ -61,7 +61,7 @@ namespace asset {
PM cm = cc->getMedia();
ASSERT (cm);
ASSERT (0 < cc->getLength());
ASSERT (Time(0) < cc->getLength());
ASSERT (cm->ident.category.hasKind (VIDEO));
ASSERT (cm->getFilename() == mm->getFilename());
TODO ("implement Processing Pattern!!!");