From 892f382f0f25b6df141c9faaad093ea09f2658f4 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 11 Jul 2009 19:23:20 +0200 Subject: [PATCH] Ticket #182 --- src/lib/iter-adaptor.hpp | 78 +++++++++++++++++++++++++++ src/lib/lumitime-fmt.hpp | 94 +++++++++++++++++++++++++++++++++ src/lib/scoped-ptrvect.hpp | 21 +++++++- tests/40components.tests | 4 ++ tests/lib/Makefile.am | 1 + tests/lib/iter-adaptor-test.cpp | 71 +++++++++++++++++++++++++ 6 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 src/lib/iter-adaptor.hpp create mode 100644 src/lib/lumitime-fmt.hpp create mode 100644 tests/lib/iter-adaptor-test.cpp diff --git a/src/lib/iter-adaptor.hpp b/src/lib/iter-adaptor.hpp new file mode 100644 index 000000000..5adc27f66 --- /dev/null +++ b/src/lib/iter-adaptor.hpp @@ -0,0 +1,78 @@ +/* + ITER-ADAPTOR.hpp - helpers for building simple forward iterators + + Copyright (C) Lumiera.org + 2009, Hermann Vosseler + + 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 lumiera forward iterators. + ** 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, an iterator + ** is a promise for pulling values -- 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 +//#include + + +namespace lib { + +// using util::for_each; + + + + /** + */ + template + class PtrIter + { + }; + + + /** + */ + template + class PtrDerefIter + { + }; + + + + +} // namespace lib +#endif diff --git a/src/lib/lumitime-fmt.hpp b/src/lib/lumitime-fmt.hpp new file mode 100644 index 000000000..da0d58ee7 --- /dev/null +++ b/src/lib/lumitime-fmt.hpp @@ -0,0 +1,94 @@ +/* + LUMITIME.hpp - convenience wrapper for working with gavl_time in C++ + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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 + +extern "C" { +#include +} + +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 > > + { + 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 diff --git a/src/lib/scoped-ptrvect.hpp b/src/lib/scoped-ptrvect.hpp index 0dc509e8d..ca17b057f 100644 --- a/src/lib/scoped-ptrvect.hpp +++ b/src/lib/scoped-ptrvect.hpp @@ -135,6 +135,25 @@ namespace lib { } + /* === Element access and iteration === */ + + T& + operator[] (size_type i) + { + return *get(i); + } + + typedef PtrDerefIter iterator; + typedef PtrDerefIter 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)); diff --git a/tests/40components.tests b/tests/40components.tests index 06cfc0073..daca5bee5 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -281,6 +281,10 @@ return: 0 END +PLANNED "Lumiera Iterator Concept" IterAdaptor_test < \[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \] out: removed 0 ---> \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, \] diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index bba91c3ea..1679c19cf 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -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 \ diff --git a/tests/lib/iter-adaptor-test.cpp b/tests/lib/iter-adaptor-test.cpp new file mode 100644 index 000000000..4bb6df4ba --- /dev/null +++ b/tests/lib/iter-adaptor-test.cpp @@ -0,0 +1,71 @@ +/* + IterAdaptor(Test) - building simple iterators for a given container + + Copyright (C) Lumiera.org + 2009, Hermann Vosseler + + 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 +