Ticket #182
This commit is contained in:
parent
9aa5ba560c
commit
892f382f0f
6 changed files with 268 additions and 1 deletions
78
src/lib/iter-adaptor.hpp
Normal file
78
src/lib/iter-adaptor.hpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
ITER-ADAPTOR.hpp - helpers for building simple forward iterators
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
/** @file iter-adaptor.hpp
|
||||
** Helper template(s) for creating <b>lumiera forward iterators</b>.
|
||||
** This denotes a concept similar to STL's "forward iterator", with
|
||||
** the addition of an bool check to detect iteration end. The latter
|
||||
** is inspired by the \c hasNext() function found in many current
|
||||
** languages supporting iterators. In a similar vein (inspired from
|
||||
** functional programming), we deliberately don't support the various
|
||||
** extended iterator concepts from STL and boost (random access iterators,
|
||||
** output iterators and the like). According to this concept, <i>an iterator
|
||||
** is a promise for pulling values</i> -- and nothing beyond that.
|
||||
**
|
||||
** @todo WIP WIP WIP
|
||||
** @todo see Ticket #182
|
||||
**
|
||||
** @see scoped-ptrvect.hpp
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LIB_ITER_ADAPTOR_H
|
||||
#define LIB_ITER_ADAPTOR_H
|
||||
|
||||
|
||||
//#include "include/logging.h"
|
||||
//#include "lib/error.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
//#include <vector>
|
||||
//#include <boost/noncopyable.hpp>
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
||||
// using util::for_each;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
template<class T, class CON>
|
||||
class PtrIter
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
template<class T, class CON>
|
||||
class PtrDerefIter
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace lib
|
||||
#endif
|
||||
94
src/lib/lumitime-fmt.hpp
Normal file
94
src/lib/lumitime-fmt.hpp
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
LUMITIME.hpp - convenience wrapper for working with gavl_time in C++
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LUMIERA_LUMITIME_H
|
||||
#define LUMIERA_LUMITIME_H
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
extern "C" {
|
||||
#include <gavl/gavltime.h>
|
||||
}
|
||||
|
||||
namespace lumiera {
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* This wrapper is deliberately kept rather limited as not to be completely
|
||||
* interchangeable with and integral type. The rationale is that time values
|
||||
* should be kept separate and tagged as time values. The following is supported:
|
||||
* - conversions from / to gavl_time_t (which is effectively a int64_t)
|
||||
* - additions and subtractions of time values
|
||||
* - multiplication with an integral factor
|
||||
* - comparisons between time values and gavl_time_t values
|
||||
*
|
||||
* @todo consider the possible extensions
|
||||
* - parsing and pretty printing
|
||||
* - quantising of floating point values
|
||||
* - conversion to boost::rational
|
||||
* - define a Framerate type
|
||||
*
|
||||
* @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::additive<Time,
|
||||
boost::totally_ordered<Time,
|
||||
boost::totally_ordered<Time, gavl_time_t> > >
|
||||
{
|
||||
gavl_time_t t_;
|
||||
|
||||
public:
|
||||
static const Time MAX ;
|
||||
static const Time MIN ;
|
||||
|
||||
explicit 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, gavl_time_t t2) { return t1.t_ < t2 ; }
|
||||
friend bool operator> (Time const& t1, gavl_time_t t2) { return t1.t_ > t2 ; }
|
||||
friend bool operator== (Time const& t1, Time const& t2) { return t1.t_ == t2.t_; }
|
||||
friend bool operator== (Time const& t1, gavl_time_t t2) { return t1.t_ == t2 ; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace lumiera
|
||||
#endif
|
||||
|
|
@ -135,6 +135,25 @@ namespace lib {
|
|||
}
|
||||
|
||||
|
||||
/* === Element access and iteration === */
|
||||
|
||||
T&
|
||||
operator[] (size_type i)
|
||||
{
|
||||
return *get(i);
|
||||
}
|
||||
|
||||
typedef PtrDerefIter<reference, _Vec> iterator;
|
||||
typedef PtrDerefIter<const_reference, _Vec> const_iterator;
|
||||
|
||||
iterator begin() { return iterator (_Vec::begin()); }
|
||||
const_iterator begin() const { return const_iterator (_Vec::begin()); }
|
||||
iterator end() { return iterator (); }
|
||||
const_iterator end() const { return const_iterator (); }
|
||||
|
||||
|
||||
|
||||
|
||||
/* ====== proxied vector functions ==================== */
|
||||
|
||||
size_type size () const { return _Vec::size(); }
|
||||
|
|
@ -144,7 +163,7 @@ namespace lib {
|
|||
|
||||
|
||||
private:
|
||||
/** currently not used as of 2/2009 */
|
||||
/** internal element access, including null check */
|
||||
T* get(size_type i)
|
||||
{
|
||||
T* p (_Vec::at (i));
|
||||
|
|
|
|||
|
|
@ -281,6 +281,10 @@ return: 0
|
|||
END
|
||||
|
||||
|
||||
PLANNED "Lumiera Iterator Concept" IterAdaptor_test <<END
|
||||
END
|
||||
|
||||
|
||||
TEST "RemoveFromSet_test" RemoveFromSet_test <<END
|
||||
out: removed nothing ---> \[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \]
|
||||
out: removed 0 ---> \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, \]
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ test_lib_SOURCES = \
|
|||
$(testlib_srcdir)/hash-indexed-test.cpp \
|
||||
$(testlib_srcdir)/helloworldtest.cpp \
|
||||
$(testlib_srcdir)/lifecycletest.cpp \
|
||||
$(testlib_srcdir)/iter-adaptor-test.cpp \
|
||||
$(testlib_srcdir)/mainsuite.cpp \
|
||||
$(testlib_srcdir)/meta/typelist-test.cpp \
|
||||
$(testlib_srcdir)/meta/typelist-manip-test.cpp \
|
||||
|
|
|
|||
71
tests/lib/iter-adaptor-test.cpp
Normal file
71
tests/lib/iter-adaptor-test.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
IterAdaptor(Test) - building simple iterators for a given container
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
//#include "lib/scoped-ptrvect.hpp"
|
||||
//#include "testdummy.hpp"
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
using ::Test;
|
||||
using util::isnil;
|
||||
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* @test create an iterator element for a given container and
|
||||
* verify its behaviour in accordance to the concept
|
||||
* "lumiera forward iterator"
|
||||
* @todo see Ticket #182
|
||||
*/
|
||||
class IterAdaptor_test : public Test
|
||||
{
|
||||
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
UNIMPLEMENTED ("build a simple lumiera forward iterator");
|
||||
simpleUsage();
|
||||
// iterating();
|
||||
// detaching();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
simpleUsage()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LAUNCHER (IterAdaptor_test, "unit common");
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
|
||||
Loading…
Reference in a new issue