summaryrefslogtreecommitdiff
path: root/cosv/inc/cosv/tpl
diff options
context:
space:
mode:
Diffstat (limited to 'cosv/inc/cosv/tpl')
-rw-r--r--cosv/inc/cosv/tpl/dyn.hxx238
-rw-r--r--cosv/inc/cosv/tpl/funcall.hxx307
-rw-r--r--cosv/inc/cosv/tpl/processor.hxx183
-rw-r--r--cosv/inc/cosv/tpl/range.hxx191
-rw-r--r--cosv/inc/cosv/tpl/swelist.hxx369
-rw-r--r--cosv/inc/cosv/tpl/tpltools.hxx228
-rw-r--r--cosv/inc/cosv/tpl/vvector.hxx539
7 files changed, 2055 insertions, 0 deletions
diff --git a/cosv/inc/cosv/tpl/dyn.hxx b/cosv/inc/cosv/tpl/dyn.hxx
new file mode 100644
index 000000000000..ab305b264ae8
--- /dev/null
+++ b/cosv/inc/cosv/tpl/dyn.hxx
@@ -0,0 +1,238 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_DYN_HXX
+#define CSV_DYN_HXX
+
+
+
+
+namespace csv
+{
+
+
+/** Dyn owns an object on the heap, which will be automatically
+ deleted in its D'tor.
+
+ Dyn's main purpose is for class members on the heap:
+ You can't forget to delete them in the D'tor. Constness will be transfered
+ to the hold object.
+
+ Dyn forbids the CopyC'tor and operator=(). So you can't incidentally
+ run into problems with compiler defined CopyC'tor or operator=() of the
+ owning class. If you need those, you have to define them explicitely - as
+ you should do anyway with all classes, that own members on the heap.
+
+ Dyn also works with incomplete types.
+ You only need to write
+ class DX;
+ but needn't include #include <DX>.hxx.
+ This is a difference to std::auto_ptr, where it is not absolutely clear
+ if it is allowed to use it with incomplete types.
+
+ You can also use Dyn within function bodies, to make them exception safe.
+
+ @attention
+ If you use Dyn with an incomplete type, the owning class needs to
+ define a non-inline D'tor. Else the compiler will complain.
+*/
+template <class DX>
+class Dyn
+{
+ public:
+ // LIFECYCLE
+ /// From now on, let_dpObject is owned by this Dyn-object.
+ explicit Dyn(
+ DX * let_dpObject = 0);
+ ~Dyn();
+ // OPERATORS
+ /** This deletes a prevoiusly existing dpObject!
+ From now on, let_dpObject is owned by this Dyn-object.
+ */
+ Dyn<DX> & operator=(
+ DX * let_dpObject);
+ /// @return true, if any valid object is hold, false else.
+ operator bool() const;
+
+ const DX * operator->() const;
+ DX * operator->();
+
+ const DX & operator*() const;
+ DX & operator*();
+
+ // OPERATIONS
+ /** @return The hold object on the heap.
+
+ @ATTENTION
+ The caller of the function is responsible to delete
+ the returned object
+
+ @postcond
+ this->dpObject == 0.
+ */
+ DX * Release();
+
+ // INQUIRY
+ /// Shorthand for operator->(), if implicit overloading of -> can not be used.
+ const DX * Ptr() const;
+
+ // ACCESS
+ /// Shorthand for operator->(), if implicit overloading of -> can not be used.
+ DX * Ptr();
+ /// So const objects can return mutable pointers to the owned object.
+ DX * MutablePtr() const;
+
+ private:
+ /* Does NOT set dpObject to zero! Because it is only used
+ internally in situations where dpObject is set immediately
+ after.
+ */
+ void Delete();
+
+ /** Forbidden function!
+ -------------------
+ Help ensure, that classes with
+ dynamic pointers use a selfdefined copy constructor
+ and operator=(). If the default versions of these
+ functions are used, the compiler will throw an error.
+ **/
+ Dyn( const Dyn<DX> & );
+ /** Forbidden function!
+ -------------------
+ Help ensure, that classes with
+ dynamic pointers use a selfdefined copy constructor
+ and operator=(). If the default versions of these
+ functions are used, the compiler will throw an error.
+ **/
+ Dyn<DX> & operator=( const Dyn<DX> & );
+
+ // DATA
+ /// An owned heap object. Needs to be deleted by this class.
+ DX * dpObject;
+};
+
+
+
+
+// IMPLEMENTATION
+template <class DX>
+void
+Dyn<DX>::Delete()
+{
+ if (dpObject != 0)
+ delete dpObject;
+}
+
+template <class DX>
+inline
+Dyn<DX>::Dyn( DX * let_dpObject )
+ : dpObject(let_dpObject) {}
+
+template <class DX>
+inline
+Dyn<DX>::~Dyn()
+{ Delete(); }
+
+
+template <class DX>
+inline Dyn<DX> &
+Dyn<DX>::operator=( DX * let_dpObject )
+{
+ if ( dpObject == let_dpObject )
+ return *this;
+
+ Delete();
+ dpObject = let_dpObject;
+ return *this;
+}
+
+template <class DX>
+inline
+Dyn<DX>::operator bool() const
+{ return dpObject != 0; }
+
+template <class DX>
+inline
+const DX *
+Dyn<DX>::operator->() const
+{ return dpObject; }
+
+template <class DX>
+inline DX *
+Dyn<DX>::operator->()
+{ return dpObject; }
+
+template <class DX>
+inline const DX &
+Dyn<DX>::operator*() const
+{ csv_assert(dpObject != 0);
+ return *dpObject;
+}
+
+template <class DX>
+inline DX &
+Dyn<DX>::operator*()
+{ csv_assert(dpObject != 0);
+ return *dpObject;
+}
+
+template <class DX>
+inline DX *
+Dyn<DX>::Release()
+{ DX * ret = dpObject;
+ dpObject = 0;
+ return ret;
+}
+
+template <class DX>
+inline const DX *
+Dyn<DX>::Ptr() const
+{ return dpObject; }
+
+template <class DX>
+inline DX *
+Dyn<DX>::Ptr()
+{ return dpObject; }
+
+template <class DX>
+inline DX *
+Dyn<DX>::MutablePtr() const
+{ return dpObject; }
+
+} // namespace csv
+
+
+
+
+#ifndef CSV_HIDE_DYN
+#define Dyn ::csv::Dyn
+#endif
+
+
+
+
+#endif
diff --git a/cosv/inc/cosv/tpl/funcall.hxx b/cosv/inc/cosv/tpl/funcall.hxx
new file mode 100644
index 000000000000..03ff8a3bba55
--- /dev/null
+++ b/cosv/inc/cosv/tpl/funcall.hxx
@@ -0,0 +1,307 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_TPL_FUNCALL_HXX
+#define CSV_TPL_FUNCALL_HXX
+
+// BASE CLASSES
+#include <algorithm>
+
+
+
+
+namespace csv
+{
+namespace func
+{
+
+
+/** @concept "csv:: Function Objects"
+
+ A set of function objects that can be generated from any kind of
+ function or member function with none or one parameter by the
+ helper function ->make_func().
+
+ Naming Scheme
+ =============
+
+ The naming scheme consists of three variables
+ f - the kind of function
+ p - the parameter of the function
+ c - call operator() of the function object with these arguments
+
+ Each of those may have the following values:
+ f:
+ f - free, no owning class
+ c - const member function of a class
+ m - modifying member function of a class
+ p:
+ n - no parameter
+ c - const parameter by reference
+ m - modifyable parameter by reference,
+ v - parameter by value
+ c:
+ n - none
+ o - the owning object on which the function shall be called
+ a - the argument of the function
+ b - both, the object on which the function shall be called
+ and the argument of the function
+
+ Which gives the following 35 possible combinations:
+ ff_pn_cn
+ ff_pc_cn
+ ff_pc_ca
+ ff_pm_cn
+ ff_pm_ca
+ ff_pv_cn
+ ff_pv_ca
+
+ fc_pn_cn
+ fc_pn_co
+ fc_pc_cn
+ fc_pc_co
+ fc_pc_ca
+ fc_pc_cb
+ fc_pm_cn
+ fc_pm_co
+ fc_pm_ca
+ fc_pm_cb
+ fc_pv_cn
+ fc_pv_co
+ fc_pv_ca
+ fc_pv_cb
+
+ fm_pn_cn
+ fm_pn_co
+ fm_pc_cn
+ fm_pc_co
+ fm_pc_ca
+ fm_pc_cb
+ fm_pm_cn
+ fm_pm_co
+ fm_pm_ca
+ fm_pm_cb
+ fm_pv_cn
+ fm_pv_co
+ fm_pv_ca
+ fm_pv_cb
+
+ These function objects are complicate to handle, so they can be created
+ with the overloaded function
+ <function_object> csv::make_func(<function_type>, <argument_types>);
+
+ For the rare, but possible case that the owning class and the function
+ argument have the same type, these clarifying variations to make_func()
+ can be used:
+ make_func_callwith_obj(), make_func_callwith_arg().
+*/
+
+
+/** Function object.
+
+ @concept ->"csv::func Function Objects"
+ @see csv::make_func()
+*/
+template <class R>
+struct ff_pn_cn
+{
+ typedef R result_type;
+ typedef R (* function_type )();
+
+ R operator()() const
+ { return (*f)(); }
+
+ ff_pn_cn(
+ function_type i_f)
+ : f(i_f) {}
+ private:
+ function_type f;
+};
+
+
+/** Function object.
+
+ @concept ->"csv::func Function Objects"
+ @see csv::make_func()
+*/
+template <class R, class C>
+struct fc_pn_co
+{
+ typedef R result_type;
+ typedef R (C::* function_type )() const;
+
+ R operator()(
+ const C & i_c ) const
+ { return (i_c.*f)(); }
+
+ fc_pn_co(
+ function_type i_f)
+ : f(i_f) {}
+ private:
+ function_type f;
+};
+
+
+
+/** Function object.
+
+ @concept ->"csv::func Function Objects"
+ @see csv::make_func()
+*/
+template <class R, class C, class P>
+struct fc_pm_co
+{
+ typedef R result_type;
+ typedef R (C::* function_type )(P&) const;
+
+ R operator()(
+ const C & i_c ) const
+ { return (i_c.*f)(p); }
+
+ fc_pm_co(
+ function_type i_f,
+ P & i_p)
+ : f(i_f), p(i_p) {}
+ private:
+ function_type f;
+ P & p;
+};
+
+
+
+
+
+
+
+} // namespace func
+
+
+/** Creates a function object of type ff_pn_cn.
+ @concept ->"csv::func Function Objects"
+*/
+template <class R>
+inline func::ff_pn_cn<R>
+make_func( R(*i_f)() )
+{
+ return func::ff_pn_cn<R>(i_f);
+}
+
+///** Creates a function object of type ff_py_cn.
+// @concept ->"csv::func Function Objects"
+//*/
+//template <class R, class P>
+//inline func::ff_py_cn<R,P>
+//make_func( R(*i_f)(P), P i_p )
+//{
+// return func::ff_py_cn<R,A>(i_f, i_p);
+//}
+//
+///** Creates a function object of type ff_py_ca.
+// @concept ->"csv::func Function Objects"
+//*/
+//template <class R, class P>
+//inline func::ff_py_ca<R,P>
+//make_func( R(*i_f)(P) )
+//{
+// return func::ff_py_ca<R,P>(i_f);
+//}
+
+
+/** Creates a function object of type fc_pn_co.
+ @concept ->"csv::func Function Objects"
+*/
+template <class R, class C>
+inline func::fc_pn_co<R,C>
+make_func( R(C::*i_f)() const )
+{
+ return func::fc_pn_co<R,C>(i_f);
+}
+
+
+
+/** Creates a function object of type fc_pm_co.
+ @concept ->"csv::func Function Objects"
+*/
+template <class R, class C, class P>
+inline func::fc_pm_co<R,C,P>
+make_func( R(C::*i_f)(P &) const, P & i_p)
+{
+ return func::fc_pm_co<R,C,P>(i_f, i_p);
+}
+
+
+
+/* Because std::for_each is defined as a non-modifying algorithm
+ it is redefined here. It is also provided for containers.
+*/
+
+template <class I, class F>
+F
+for_each(I i_itBegin, I i_itEnd, F io_functionToBeCalled)
+{
+ for (I it = i_itBegin; it != i_itEnd; ++it)
+ {
+ io_functionToBeCalled(*it);
+ }
+ return io_functionToBeCalled;
+}
+
+template <class C, class F>
+F
+for_each_in(const C & i_container, F io_functionToBeCalled)
+{
+ typename C::const_iterator const
+ itEnd = i_container.end();
+ for ( typename C::const_iterator it = i_container.begin();
+ it != itEnd;
+ ++it )
+ {
+ io_functionToBeCalled(*it);
+ }
+ return io_functionToBeCalled;
+}
+
+template <class C, class F>
+F
+for_each_in(C & i_container, F io_functionToBeCalled)
+{
+ typename C::iterator const
+ itEnd = i_container.end();
+ for ( typename C::iterator it = i_container.begin();
+ it != itEnd;
+ ++it )
+ {
+ io_functionToBeCalled(*it);
+ }
+ return io_functionToBeCalled;
+}
+
+
+
+
+} // namespace csv
+#endif
diff --git a/cosv/inc/cosv/tpl/processor.hxx b/cosv/inc/cosv/tpl/processor.hxx
new file mode 100644
index 000000000000..fc9a8277568a
--- /dev/null
+++ b/cosv/inc/cosv/tpl/processor.hxx
@@ -0,0 +1,183 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_TPL_PROCESSOR_HXX
+#define CSV_TPL_PROCESSOR_HXX
+
+// USED SERVICES
+
+
+
+
+namespace csv
+{
+
+
+/** Implements an acyclic visitor pattern. This is the abstract
+ base for the classes doing the work (the "visitors").
+*/
+class ProcessorIfc
+{
+ public:
+ virtual ~ProcessorIfc() {}
+};
+
+
+
+/** Implements an acyclic visitor pattern. This is the abstract
+ base for the classes to be processed (the "visitables").
+*/
+class ConstProcessorClient
+{
+ public:
+ virtual ~ConstProcessorClient() {}
+
+ void Accept(
+ ProcessorIfc & io_processor ) const
+ { do_Accept(io_processor); }
+ private:
+ virtual void do_Accept(
+ ProcessorIfc & io_processor ) const = 0;
+};
+
+/** Implements an acyclic visitor pattern. This is the abstract
+ base for the classes to be processed (the "visitables").
+*/
+class ProcessorClient
+{
+ public:
+ virtual ~ProcessorClient() {}
+
+ void Accept(
+ ProcessorIfc & io_processor )
+ { do_Accept(io_processor); }
+ private:
+ virtual void do_Accept(
+ ProcessorIfc & io_processor ) = 0;
+};
+
+
+
+
+
+/** Typed base for "visitor" classes, leaving the visited
+ object const.
+
+ @see ProcessorIfc
+ @see Processor<>
+*/
+template <typename X, typename R = void>
+class ConstProcessor
+{
+ public:
+ virtual ~ConstProcessor() {}
+
+ R Process(
+ const X & i_object )
+ { return do_Process(i_object ); }
+ private:
+ virtual R do_Process(
+ const X & i_object ) = 0;
+};
+
+
+/** Typed base for "visitor" classes which may change the visited
+ object.
+
+ @see ProcessorIfc
+ @see ConstProcessor<>
+*/
+template <typename X, typename R = void>
+class Processor
+{
+ public:
+ virtual ~Processor() {}
+
+ R Process(
+ X & i_object )
+ { return do_Process(i_object ); }
+ private:
+ virtual R do_Process(
+ X & i_object ) = 0;
+};
+
+
+template <class C>
+inline void
+CheckedCall( ProcessorIfc & io_processor,
+ const C & i_client )
+{
+ ConstProcessor<C> *
+ pProcessor = dynamic_cast< csv::ConstProcessor<C> * >
+ (&io_processor);
+ if (pProcessor != 0)
+ pProcessor->Process(i_client);
+}
+
+template <class C>
+inline void
+CheckedCall( ProcessorIfc & io_processor,
+ C & io_client )
+{
+ Processor<C> *
+ pProcessor = dynamic_cast< csv::Processor<C> * >
+ (&io_processor);
+ if (pProcessor != 0)
+ pProcessor->Process(io_client);
+}
+
+template <class C>
+inline void
+AssertedCall( ProcessorIfc & io_processor,
+ const C & i_client )
+{
+ ConstProcessor<C> *
+ pProcessor = dynamic_cast< csv::ConstProcessor<C> * >
+ (&io_processor);
+ csv_assert( pProcessor != 0
+ && "csv::AssertedCall() failed. Processed object did not match processor." );
+ pProcessor->Process(i_client);
+}
+
+template <class C>
+inline void
+AssertedCall( ProcessorIfc & io_processor,
+ C & io_client )
+{
+ Processor<C> *
+ pProcessor = dynamic_cast< csv::Processor<C> * >
+ (&io_processor);
+ csv_assert( pProcessor != 0
+ && "csv::AssertedCall() failed. Processed object did not match processor." );
+ pProcessor->Process(io_client);
+}
+
+
+
+
+} // namespace csv
+#endif
diff --git a/cosv/inc/cosv/tpl/range.hxx b/cosv/inc/cosv/tpl/range.hxx
new file mode 100644
index 000000000000..ea6ce84fa480
--- /dev/null
+++ b/cosv/inc/cosv/tpl/range.hxx
@@ -0,0 +1,191 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_RANGE_HXX
+#define CSV_RANGE_HXX
+
+#include <cstring> // for std::size_t
+
+
+
+
+namespace csv
+{
+
+
+/** Represents a range of integer or iterator values.
+
+ @tpl T
+ Has to be assignable, add- and subtractable. That is:
+ either it is
+ - an integral type
+ - or a random access iterator.
+*/
+template <class T>
+class range
+{
+ public:
+ typedef T element_type; /// Provided for generic programming.
+ typedef range<T> self;
+
+ // LIFECYCLE
+ range(
+ T i_inclusiveLowerBorder,
+ T i_exclusiveUpperBorder );
+ ~range();
+ // INQUIRY
+ T begin() const;
+ T end() const;
+ std::size_t size() const;
+
+ bool contains(
+ T i_value ) const;
+ bool contains(
+ const self & i_other ) const;
+ bool overlaps(
+ const self & i_other ) const;
+ /// @return i_other.begin() - this->end()
+ long distance_to(
+ const self & i_other ) const;
+ private:
+ // DATA
+ T nBegin;
+ T nEnd;
+};
+
+
+template <class T>
+inline range<T>
+make_range(T i1, T i2)
+{
+ return range<T>(i1, i2);
+}
+
+template <class T>
+inline range<typename T::const_iterator>
+range_of(const T & i_container)
+{
+ return make_range( i_container.begin(),
+ i_container.end()
+ );
+}
+
+template <class T>
+inline range<typename T::iterator>
+range_of(T & io_container)
+{
+ return make_range( io_container.begin(),
+ io_container.end()
+ );
+}
+
+
+
+
+
+// IMPLEMENTATION
+
+template <class T>
+range<T>::range( T i_inclusiveLowerBorder,
+ T i_exclusiveUpperBorder )
+ : nBegin(i_inclusiveLowerBorder),
+ nEnd(i_exclusiveUpperBorder)
+{
+ csv_assert( nBegin <= nEnd
+ && "Invalid parameters for range<> constructor.");
+}
+
+template <class T>
+range<T>::~range()
+{
+}
+
+template <class T>
+inline T
+range<T>::begin() const
+{
+ return nBegin;
+}
+
+template <class T>
+inline T
+range<T>::end() const
+{
+ return nEnd;
+}
+
+template <class T>
+inline std::size_t
+range<T>::size() const
+{
+ csv_assert( nBegin <= nEnd
+ && "Invalid range limits in range<>::size().");
+ return static_cast<std::size_t>( end() - begin() );
+}
+
+template <class T>
+bool
+range<T>::contains(T i_value ) const
+{
+ return begin() <= i_value
+ && i_value < end();
+}
+
+template <class T>
+bool
+range<T>::contains(const self & i_other) const
+{
+ // This is subtle, because this would be wrong:
+ // begin() <= i_other.begin()
+ // && i_other.end() <= end();
+ // An empty range that begins and starts at my end()
+ // must not be contained.
+
+ return contains(i_other.begin())
+ && i_other.end() <= end();
+}
+
+template <class T>
+bool
+range<T>::overlaps(const self & i_other) const
+{
+ return contains(i_other.begin())
+ || i_other.contains(begin());
+}
+
+template <class T>
+long
+range<T>::distance_to(const self & i_other) const
+{
+ return i_other.begin() - end();
+}
+
+
+
+
+} // namespace csv
+#endif
diff --git a/cosv/inc/cosv/tpl/swelist.hxx b/cosv/inc/cosv/tpl/swelist.hxx
new file mode 100644
index 000000000000..0a56fae1e16e
--- /dev/null
+++ b/cosv/inc/cosv/tpl/swelist.hxx
@@ -0,0 +1,369 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_SWELIST_HXX
+#define CSV_SWELIST_HXX
+
+// USED SERVICES
+ // BASE CLASSES
+ // COMPONENTS
+ // PARAMETERS
+#include <cosv/tpl/dyn.hxx>
+
+
+namespace csv
+{
+
+
+template <class XX>
+class SweListElement
+{
+ public:
+ typedef SweListElement<XX> self;
+
+ SweListElement(
+ const XX & in_aObj )
+ : aObj(in_aObj), pNext(0) {}
+
+ const XX & Obj() const { return aObj; }
+ XX & Obj() { return aObj; }
+ self * Next() const { return pNext; }
+
+ void SetNext(
+ self * i_pNext )
+ { pNext = i_pNext; }
+ private:
+ XX aObj;
+ self * pNext;
+};
+
+
+
+template <class XX> class SweListIterator;
+template <class XX> class SweListCIterator;
+
+
+template <class XX>
+class SweList
+{
+ public:
+ // TYPES
+ typedef SweList<XX> self;
+ typedef XX value_type;
+ typedef SweListIterator<XX> iterator;
+ typedef SweListCIterator<XX> const_iterator;
+ private:
+ typedef SweListElement<XX> elem;
+
+ public:
+ // LIFECYCLE
+ SweList() : pTop(0), pTail(0) {}
+ ~SweList() { erase_all(); }
+ // OPERATIONS
+ void push_front(
+ const XX & i_aObj );
+ void pop_front();
+ void push_back(
+ const XX & i_aObj );
+ void erase_all();
+
+ // INQUIRY
+ const_iterator begin() const { return pTop; }
+ iterator begin() { return pTop; }
+ const_iterator end() const { return (elem*)0; }
+ iterator end() { return (elem*)0; }
+ const XX & front() const { return pTop->Obj(); }
+ XX & front() { return pTop->Obj(); }
+ const XX & back() const { return pTail->Obj(); }
+ XX & back() { return pTail->Obj(); }
+
+ bool empty() const { return pTop == 0; }
+ uintt size() const;
+
+
+ private:
+ // Forbiddden methods.
+ SweList(
+ const self & i_rList );
+ self & operator=(
+ const self & i_rList );
+
+ // DATA
+ DYN elem * pTop;
+ elem * pTail;
+};
+
+template <class XX>
+class SweList_dyn
+{
+ public:
+ // TYPES
+ typedef SweList_dyn<XX> self;
+ typedef SweListElement< XX* > elem;
+ typedef SweListIterator< XX* > iterator;
+
+ // LIFECYCLE
+ SweList_dyn() : pTop(0), pTail(0) {}
+ ~SweList_dyn() { erase_all(); }
+ // OPERATIONS
+ void push_front(
+ XX * i_pObj );
+ void push_back(
+ XX * i_pObj );
+ void pop_front();
+ void erase_all();
+
+ // INQUIRY
+ iterator begin() const { return pTop; }
+ iterator end() const { return (elem*)0; }
+ XX * front() const { return pTop->Obj(); }
+ XX * back() const { return pTail->Obj(); }
+
+ bool empty() const { return pTop == 0; }
+ uintt size() const;
+
+ private:
+ // Forbiddden methods.
+ SweList_dyn(
+ const self & i_rList );
+ self & operator=(
+ const self & i_rList );
+
+ DYN elem * pTop;
+ elem * pTail;
+};
+
+
+
+
+template<class XX>
+class SweListIterator
+{
+ public:
+ typedef SweListIterator<XX> self;
+ typedef SweListElement<XX> elem;
+
+ SweListIterator(
+ elem * i_pElem = 0)
+ : pElem(i_pElem) { }
+
+ // OPERATORS
+ XX & operator*() const { return pElem->Obj(); }
+ self & operator++() { if (pElem != 0) pElem = pElem->Next();
+ return *this; }
+ bool operator==(
+ const self & i_rIter ) const
+ { return pElem == i_rIter.pElem; }
+ bool operator!=(
+ const self & i_rIter ) const
+ { return pElem != i_rIter.pElem; }
+ private:
+ friend class SweListCIterator<XX>;
+
+ elem * pElem;
+};
+
+template<class XX>
+class SweListCIterator
+{
+ public:
+ typedef SweListCIterator<XX> self;
+ typedef SweListElement<XX> elem;
+
+ SweListCIterator(
+ const elem * i_pElem = 0)
+ : pElem(i_pElem) { }
+
+ // OPERATORS
+ self & operator=(
+ const SweListIterator<XX> &
+ i_rIter )
+ { pElem = i_rIter.pElem; return *this; }
+
+ const XX & operator*() const { return pElem->Obj(); }
+ self & operator++() { if (pElem != 0) pElem = pElem->Next();
+ return *this; }
+ bool operator==(
+ const self & i_rIter ) const
+ { return pElem == i_rIter.pElem; }
+ bool operator!=(
+ const self & i_rIter ) const
+ { return pElem != i_rIter.pElem; }
+ private:
+ const elem * pElem;
+};
+
+// Implementierung
+
+template <class XX>
+void
+SweList<XX>::push_front( const XX & i_aObj )
+{
+ DYN elem * dpNew = new elem(i_aObj);
+ dpNew->SetNext(pTop);
+ pTop = dpNew;
+ if (pTail == 0)
+ pTail = pTop;
+}
+
+template <class XX>
+void
+SweList<XX>::push_back( const XX & i_aObj)
+{
+ if (pTail != 0)
+ {
+ pTail->SetNext(new elem(i_aObj));
+ pTail = pTail->Next();
+ }
+ else
+ {
+ pTop = pTail = new elem(i_aObj);
+ }
+}
+
+template <class XX>
+void
+SweList<XX>::pop_front()
+{
+ if (pTop != 0)
+ {
+ elem * pDel = pTop;
+ pTop = pTop->Next();
+ delete pDel;
+ if (pTop == 0)
+ pTail = 0;
+ }
+}
+
+template <class XX>
+uintt
+SweList<XX>::size() const
+{
+ uintt ret = 0;
+ for ( const_iterator iter = begin();
+ iter != end();
+ ++iter )
+ {
+ ++ret;
+ }
+ return ret;
+}
+
+
+template <class XX>
+void
+SweList<XX>::erase_all()
+{
+ for (pTail = pTop ; pTop != 0; pTail = pTop)
+ {
+ pTop = pTop->Next();
+ delete pTail;
+ }
+ pTop = pTail = 0;
+}
+
+
+template <class XX>
+void
+SweList_dyn<XX>::push_front( XX * i_pObj )
+{
+ DYN elem * dpNew = new elem(i_pObj);
+ dpNew->SetNext(pTop);
+ pTop = dpNew;
+ if (pTail == 0)
+ pTail = pTop;
+}
+
+template <class XX>
+void
+SweList_dyn<XX>::push_back( XX * i_pObj )
+{
+ if (pTail != 0)
+ {
+ pTail->SetNext(new elem(i_pObj));
+ pTail = pTail->Next();
+ }
+ else
+ {
+ pTop = pTail = new elem(i_pObj);
+ }
+}
+
+template <class XX>
+void
+SweList_dyn<XX>::pop_front()
+{
+ if (pTop != 0)
+ {
+ elem * pDel = pTop;
+ pTop = pTop->Next();
+ if (pDel->Obj() != 0)
+ Delete_dyn(pDel->Obj());
+ delete pDel;
+ if (pTop == 0)
+ pTail = 0;
+ }
+}
+
+
+template <class XX>
+void
+SweList_dyn<XX>::erase_all()
+{
+ for (pTail = pTop ; pTop != 0; pTail = pTop)
+ {
+ pTop = pTop->Next();
+ if (pTail->Obj() != 0)
+ {
+ delete pTail->Obj();
+ }
+ delete pTail;
+ }
+ pTop = pTail = 0;
+}
+
+template <class XX>
+uintt
+SweList_dyn<XX>::size() const
+{
+ uintt ret = 0;
+ for ( iterator iter = begin();
+ iter != end();
+ ++iter )
+ {
+ ++ret;
+ }
+ return ret;
+}
+
+
+} // namespace csv
+
+
+#endif
+
+
diff --git a/cosv/inc/cosv/tpl/tpltools.hxx b/cosv/inc/cosv/tpl/tpltools.hxx
new file mode 100644
index 000000000000..98d5190310d9
--- /dev/null
+++ b/cosv/inc/cosv/tpl/tpltools.hxx
@@ -0,0 +1,228 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_TPLTOOLS_HXX
+#define CSV_TPLTOOLS_HXX
+
+#include <vector>
+#include <map>
+
+
+
+
+namespace csv
+{
+
+
+template <class COLLECTION>
+inline void erase_container(
+ COLLECTION & o_rCollection );
+
+/// Version for std::map
+template <class COLLECTION>
+void erase_map_of_heap_ptrs(
+ COLLECTION & o_rCollection );
+
+/// Version for other containers than std::map, with non-pair value_type.
+template <class COLLECTION>
+void erase_container_of_heap_ptrs(
+ COLLECTION & o_rCollection );
+
+template <class VECTOR_ELEM>
+void adjust_vector_size(
+ std::vector<VECTOR_ELEM> &
+ io_rVector,
+ uintt i_nSize,
+ const VECTOR_ELEM & i_nFill );
+
+
+template <class KEY, class VAL>
+const VAL * find_in_map( /// Usable for all kinds of values
+ const std::map< KEY, VAL > &
+ i_rMap,
+ const KEY & i_rKey );
+
+
+/** @return the value in the map, if it is in there, else 0.
+ @precond VAL has to be convertable to "0".
+*/
+template <class KEY, class VAL>
+VAL value_from_map(
+ const std::map< KEY, VAL > &
+ i_rMap,
+ const KEY & i_rKey );
+
+/** @return the value in the map, if it is in there, else i_notFound.
+*/
+template <class KEY, class VAL>
+VAL value_from_map(
+ const std::map< KEY, VAL > &
+ i_rMap,
+ const KEY & i_rKey,
+ VAL i_notFound );
+
+template <class COLLECTION, class VALUE>
+bool contains(
+ const COLLECTION & i_collection,
+ const VALUE & i_value );
+
+// Object oriented for_each:
+template <class COLLECTION, class CLASS, class MEMFUNC>
+void call_for_each(
+ const COLLECTION & i_rList,
+ CLASS * io_pThis,
+ MEMFUNC i_fMethod );
+
+
+
+
+// IMPLEMENTATION
+template <class COLLECTION>
+inline void
+erase_container( COLLECTION & o_rCollection )
+{
+ o_rCollection.erase( o_rCollection.begin(),
+ o_rCollection.end() );
+}
+
+template <class COLLECTION>
+void
+erase_map_of_heap_ptrs( COLLECTION & o_rCollection )
+{
+ typename COLLECTION::iterator itEnd = o_rCollection.end();
+ for ( typename COLLECTION::iterator it = o_rCollection.begin();
+ it != itEnd;
+ ++it )
+ {
+ delete (*it).second;
+ }
+
+ o_rCollection.erase( o_rCollection.begin(),
+ o_rCollection.end() );
+}
+
+template <class COLLECTION>
+void
+erase_container_of_heap_ptrs( COLLECTION & o_rCollection )
+{
+ typename COLLECTION::iterator itEnd = o_rCollection.end();
+ for ( typename COLLECTION::iterator it = o_rCollection.begin();
+ it != itEnd;
+ ++it )
+ {
+ delete *it;
+ }
+
+ o_rCollection.erase( o_rCollection.begin(),
+ o_rCollection.end() );
+}
+
+template <class VECTOR_ELEM>
+void
+adjust_vector_size( std::vector<VECTOR_ELEM> & io_rVector,
+ uintt i_nSize,
+ const VECTOR_ELEM & i_nFill )
+{
+ if ( io_rVector.size() > i_nSize )
+ {
+ io_rVector.erase( io_rVector.begin() + i_nSize, io_rVector.end() );
+ }
+ else
+ {
+ io_rVector.reserve(i_nSize);
+ while ( io_rVector.size() < i_nSize )
+ io_rVector.push_back(i_nFill);
+ }
+}
+
+
+template <class KEY, class VAL>
+const VAL *
+find_in_map( const std::map< KEY, VAL > & i_rMap,
+ const KEY & i_rKey )
+{
+ typename std::map< KEY, VAL >::const_iterator
+ ret = i_rMap.find(i_rKey);
+ return ret != i_rMap.end()
+ ? & (*ret).second
+ : (const VAL*)0;
+}
+
+template <class KEY, class VAL>
+VAL
+value_from_map( const std::map< KEY, VAL > & i_rMap,
+ const KEY & i_rKey )
+{
+ typename std::map< KEY, VAL >::const_iterator
+ ret = i_rMap.find(i_rKey);
+ return ret != i_rMap.end()
+ ? (*ret).second
+ : VAL(0);
+}
+
+template <class KEY, class VAL>
+VAL
+value_from_map( const std::map< KEY, VAL > & i_rMap,
+ const KEY & i_rKey,
+ VAL i_notFound )
+{
+ typename std::map< KEY, VAL >::const_iterator
+ ret = i_rMap.find(i_rKey);
+ return ret != i_rMap.end()
+ ? (*ret).second
+ : i_notFound;
+}
+
+template <class COLLECTION, class VALUE>
+bool
+contains( const COLLECTION & i_collection,
+ const VALUE & i_value )
+{
+ return std::find(i_collection.begin(), i_collection.end(), i_value)
+ !=
+ i_collection.end();
+}
+
+template <class COLLECTION, class CLASS, class MEMFUNC>
+void
+call_for_each( const COLLECTION & i_rList,
+ CLASS * io_pThis,
+ MEMFUNC i_fMethod )
+{
+ typename COLLECTION::const_iterator it = i_rList.begin();
+ typename COLLECTION::const_iterator itEnd = i_rList.end();
+ for ( ; it != itEnd; ++it )
+ {
+ (io_pThis->*i_fMethod)(*it);
+ }
+}
+
+
+
+
+} // namespace csv
+#endif
diff --git a/cosv/inc/cosv/tpl/vvector.hxx b/cosv/inc/cosv/tpl/vvector.hxx
new file mode 100644
index 000000000000..312a79d4f229
--- /dev/null
+++ b/cosv/inc/cosv/tpl/vvector.hxx
@@ -0,0 +1,539 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef CSV_VVECTOR_HXX
+#define CSV_VVECTOR_HXX
+
+// USED SERVICES
+#include <vector>
+#include <cosv/tpl/tpltools.hxx>
+
+
+
+
+namespace csv
+{
+namespace vvector
+{
+
+
+template <class TYPE>
+struct delete_ptrs
+{
+ static void Destruct(
+ std::vector< TYPE* > &
+ v)
+ { csv::erase_container_of_heap_ptrs(v); }
+
+ /// @precond ->it is a valid iterator within v
+ static void Erase(
+ std::vector< TYPE* > &
+ v,
+ typename std::vector< TYPE* >::iterator
+ it2erase )
+ { delete *it2erase; v.erase(it2erase); }
+
+ /// @precond ->v.size() > 0
+ static void PopBack(
+ std::vector< TYPE* > &
+ v )
+ { delete v.back(); v.pop_back(); }
+
+ /// @precond ->it is a valid iterator
+ static void ReplacePtr(
+ typename std::vector< TYPE* >::iterator
+ it,
+ DYN TYPE * pass_new )
+ { delete *it; *it = pass_new; }
+};
+
+
+/** One helper class for the ->csv::VirtualVector.
+ Implements a
+*/
+template <class TYPE>
+struct keep_ptrs
+{
+ static void Destruct(std::vector< TYPE* > & v)
+ {}
+
+ static void Erase(
+ std::vector< TYPE* > &
+ v,
+ typename std::vector< TYPE* >::iterator
+ it2erase )
+ { v.erase(it2erase); }
+
+ static void PopBack(
+ std::vector< TYPE* > &
+ v )
+ { v.pop_back(); }
+
+ /// @precond ->it is a valid iterator
+ static void ReplacePtr(
+ typename std::vector< TYPE* >::iterator
+ it,
+ TYPE * io_new )
+ { *it = io_new; }
+};
+
+
+} // namespace vvector
+
+
+
+
+/** Implements a vector of different implementations of a base
+ class.
+
+ Implementation has to be by pointers to get the polymorphic
+ behaviour, however access is by references to the base class.
+
+ @tpl XX
+ The common base class of vector elements.
+
+ @tpl PTRDEL
+ Has two possible values:
+ vvector::delete_ptrs<XX> Elements have to be on the heap and
+ are deleted when removed (default).
+ vvector::keep_ptrs<XX> Elements are only referenced and not
+ deleted when removed.
+
+*/
+template <class XX, class PTRDEL = vvector::delete_ptrs<XX> >
+class VirtualVector
+{
+ public:
+ typedef VirtualVector<XX,PTRDEL> self;
+ typedef std::vector< DYN XX* > impl_type;
+ typedef typename impl_type::size_type size_type;
+ typedef ptrdiff_t difference_type;
+
+ class const_iterator;
+ class iterator;
+
+ // LIFECYCLE
+ VirtualVector();
+ explicit VirtualVector(
+ int i_size );
+ ~VirtualVector();
+
+ // OPERATORS
+ const XX & operator[](
+ size_type i_pos ) const;
+ XX & operator[](
+ size_type i_pos );
+
+ // OPERATIONS
+ void push_back(
+ DYN XX & i_drElement );
+ void pop_back();
+
+ iterator insert(
+ iterator i_pos,
+ DYN XX & i_drElement );
+ void erase(
+ iterator i_pos );
+ void replace(
+ iterator i_pos,
+ DYN XX & i_drElement );
+ void reserve(
+ size_type i_size );
+
+ // INQUIRY
+ bool empty() const;
+ size_t size() const;
+ const_iterator begin() const;
+ const_iterator end() const;
+ const XX & front() const;
+ const XX & back() const;
+
+ // ACCESS
+ iterator begin();
+ iterator end();
+ XX & front();
+ XX & back();
+
+ private:
+ // Forbidden:
+ VirtualVector(const VirtualVector&);
+ VirtualVector & operator=(const VirtualVector&);
+
+ // DATA
+ std::vector< DYN XX* >
+ aData;
+};
+
+
+
+
+/** Should be usable for all STL algorithms.
+ Implements the Random Access Iterator concept.
+*/
+template <class XX, class PTRDEL>
+class VirtualVector<XX,PTRDEL>::
+ const_iterator
+
+ // This derivation provides type information for the STL
+ // It introduces the types "value_type" and "difference_type".
+ : public std::iterator<std::random_access_iterator_tag,
+ const XX>
+{
+ public:
+ typedef VirtualVector<XX,PTRDEL> my_container;
+ typedef typename my_container::impl_type::const_iterator impl_iterator;
+
+ // LIFECYCLE
+ const_iterator(
+ impl_iterator i_implIter )
+ : itImpl(i_implIter) {}
+
+
+ /////////// STL ITERATOR CONCEPT IMPLEMENTATION //////////////
+
+ // Default Constructible functions:
+ const_iterator()
+ : itImpl() {}
+
+ // Assignable functions:
+ // Assignment and copy constructor use the compiler generated versions.
+
+ // Equality Comparable functions:
+ bool operator==(
+ const_iterator i_other ) const
+ { return itImpl == i_other.itImpl; }
+ bool operator!=(
+ const_iterator i_other ) const
+ { return itImpl != i_other.itImpl; }
+
+ // Trivial Iterator functions:
+ const XX & operator*() const
+ { return *(*itImpl); }
+
+ // Input Iterator functions:
+ const_iterator & operator++()
+ { ++itImpl; return *this; }
+ const_iterator operator++(int)
+ { return const_iterator(itImpl++); }
+
+ // Bidirectional Iterator functions:
+ const_iterator & operator--()
+ { --itImpl; return *this; }
+ const_iterator operator--(int)
+ { return const_iterator(itImpl--); }
+
+ // Less Than Comparable functions:
+ bool operator<(
+ const_iterator i_other ) const
+ { return itImpl < i_other.itImpl; }
+
+ // Random Access Iterator functions:
+ const_iterator & operator+=(
+ difference_type i_diff )
+ { itImpl += i_diff; return *this; }
+ const_iterator operator+(
+ difference_type i_diff ) const
+ { const_iterator ret(itImpl);
+ return ret += i_diff; }
+ const_iterator & operator-=(
+ difference_type i_diff )
+ { itImpl -= i_diff; return *this; }
+ const_iterator operator-(
+ difference_type i_diff ) const
+ { const_iterator ret(itImpl);
+ return ret -= i_diff; }
+ difference_type operator-(
+ const_iterator i_it ) const
+ { return itImpl - i_it.itImpl; }
+ const XX & operator[](
+ difference_type i_index )
+ { return *(*itImpl[i_index]); }
+
+ //////////////////////////////////////////////////////////////////////////
+
+ private:
+ friend class VirtualVector<XX,PTRDEL>;
+ impl_iterator ImplValue() const { return itImpl; }
+
+ // DATA
+ impl_iterator itImpl;
+};
+
+
+
+
+/** Should be usable for all STL algorithms.
+ Implements the Random Access Iterator concept.
+*/
+template <class XX, class PTRDEL>
+class VirtualVector<XX,PTRDEL>::
+ iterator
+
+ // This derivation provides type information for the STL
+ // It introduces the types "value_type" and "difference_type".
+ : public std::iterator<std::random_access_iterator_tag,
+ XX>
+{
+ public:
+ typedef VirtualVector<XX,PTRDEL> my_container;
+ typedef typename my_container::impl_type::iterator impl_iterator;
+
+ // LIFECYCLE
+ iterator(
+ impl_iterator i_implIter )
+ : itImpl(i_implIter) {}
+
+
+ /////////// STL ITERATOR CONCEPT IMPLEMENTATION //////////////
+
+ // Default Constructible functions:
+ iterator()
+ : itImpl() {}
+
+ // Assignable functions:
+ // Assignment and copy constructor use the compiler generated versions.
+
+ // Equality Comparable functions:
+ bool operator==(
+ iterator i_other ) const
+ { return itImpl == i_other.itImpl; }
+ bool operator!=(
+ iterator i_other ) const
+ { return itImpl != i_other.itImpl; }
+
+ // Trivial Iterator functions:
+ XX & operator*() const
+ { return *(*itImpl); }
+
+ // Input Iterator functions:
+ iterator & operator++()
+ { ++itImpl; return *this; }
+ iterator operator++(int)
+ { return iterator(itImpl++); }
+
+ // Bidirectional Iterator functions:
+ iterator & operator--()
+ { --itImpl; return *this; }
+ iterator operator--(int)
+ { return iterator(itImpl--); }
+
+ // Less Than Comparable functions:
+ bool operator<(
+ iterator i_other ) const
+ { return itImpl < i_other.itImpl; }
+
+ // Random Access Iterator functions:
+ iterator & operator+=(
+ difference_type i_diff )
+ { itImpl += i_diff; return *this; }
+ iterator operator+(
+ difference_type i_diff ) const
+ { iterator ret(itImpl);
+ return ret += i_diff; }
+ iterator & operator-=(
+ difference_type i_diff )
+ { itImpl -= i_diff; return *this; }
+ iterator operator-(
+ difference_type i_diff ) const
+ { iterator ret(itImpl);
+ return ret -= i_diff; }
+ difference_type operator-(
+ iterator i_it ) const
+ { return itImpl - i_it.itImpl; }
+ XX & operator[](
+ difference_type i_index )
+ { return *(*itImpl[i_index]); }
+
+ //////////////////////////////////////////////////////////////////////////
+
+ private:
+ friend class VirtualVector<XX,PTRDEL>;
+ impl_iterator ImplValue() const { return itImpl; }
+
+ // DATA
+ impl_iterator itImpl;
+};
+
+
+
+
+// IMPLEMENTATION
+template <class XX, class PTRDEL>
+inline
+VirtualVector<XX,PTRDEL>::VirtualVector()
+ : aData()
+{
+}
+
+template <class XX, class PTRDEL>
+inline
+VirtualVector<XX,PTRDEL>::VirtualVector(int i_size)
+ : aData(i_size, 0)
+{
+}
+
+template <class XX, class PTRDEL>
+inline
+VirtualVector<XX,PTRDEL>::~VirtualVector()
+{
+ PTRDEL::Destruct(aData);
+}
+
+template <class XX, class PTRDEL>
+inline const XX &
+VirtualVector<XX,PTRDEL>::operator[]( size_type i_pos ) const
+{
+ return *aData[i_pos];
+}
+
+template <class XX, class PTRDEL>
+inline XX &
+VirtualVector<XX,PTRDEL>::operator[]( size_type i_pos )
+{
+ return *aData[i_pos];
+}
+
+template <class XX, class PTRDEL>
+inline void
+VirtualVector<XX,PTRDEL>::push_back( DYN XX & i_drElement )
+{
+ aData.push_back(&i_drElement);
+}
+
+template <class XX, class PTRDEL>
+inline void
+VirtualVector<XX,PTRDEL>::pop_back()
+{
+ if (NOT aData.empty())
+ PTRDEL::PopBack(aData);
+}
+
+template <class XX, class PTRDEL>
+inline typename VirtualVector<XX,PTRDEL>::iterator
+VirtualVector<XX,PTRDEL>::insert( iterator i_pos,
+ DYN XX & i_drElement )
+{
+ return iterator(aData.insert(i_pos.ImplValue(), &i_drElement));
+}
+
+template <class XX, class PTRDEL>
+inline void
+VirtualVector<XX,PTRDEL>::erase( iterator i_pos )
+{
+ PTRDEL::Erase(aData, i_pos.ImplValue());
+}
+
+template <class XX, class PTRDEL>
+inline void
+VirtualVector<XX,PTRDEL>::replace( iterator i_pos,
+ DYN XX & i_drElement )
+{
+ PTRDEL::ReplacePtr(*i_pos, &i_drElement);
+}
+
+template <class XX, class PTRDEL>
+inline void
+VirtualVector<XX,PTRDEL>::reserve( size_type i_size )
+{
+ aData.reserve(i_size);
+}
+
+template <class XX, class PTRDEL>
+inline bool
+VirtualVector<XX,PTRDEL>::empty() const
+{
+ return aData.empty();
+}
+
+template <class XX, class PTRDEL>
+inline size_t
+VirtualVector<XX,PTRDEL>::size() const
+{
+ return aData.size();
+}
+
+template <class XX, class PTRDEL>
+inline typename VirtualVector<XX,PTRDEL>::const_iterator
+VirtualVector<XX,PTRDEL>::begin() const
+{
+ return const_iterator(aData.begin());
+}
+
+template <class XX, class PTRDEL>
+inline typename VirtualVector<XX,PTRDEL>::const_iterator
+VirtualVector<XX,PTRDEL>::end() const
+{
+ return const_iterator(aData.end());
+}
+
+template <class XX, class PTRDEL>
+inline const XX &
+VirtualVector<XX,PTRDEL>::front() const
+{
+ return *aData.front();
+}
+
+template <class XX, class PTRDEL>
+inline const XX &
+VirtualVector<XX,PTRDEL>::back() const
+{
+ return *aData.back();
+}
+
+template <class XX, class PTRDEL>
+inline typename VirtualVector<XX,PTRDEL>::iterator
+VirtualVector<XX,PTRDEL>::begin()
+{
+ return iterator(aData.begin());
+}
+
+template <class XX, class PTRDEL>
+inline typename VirtualVector<XX,PTRDEL>::iterator
+VirtualVector<XX,PTRDEL>::end()
+{
+ return iterator(aData.end());
+}
+
+template <class XX, class PTRDEL>
+inline XX &
+VirtualVector<XX,PTRDEL>::front()
+{
+ return *aData.front();
+}
+
+template <class XX, class PTRDEL>
+inline XX &
+VirtualVector<XX,PTRDEL>::back()
+{
+ return *aData.back();
+}
+
+
+
+
+} // namespace csv
+#endif