summaryrefslogtreecommitdiff
path: root/o3tl
diff options
context:
space:
mode:
Diffstat (limited to 'o3tl')
-rw-r--r--o3tl/inc/o3tl/vector_pool.hxx132
-rw-r--r--o3tl/prj/build.lst2
-rw-r--r--o3tl/qa/export.map4
-rw-r--r--o3tl/qa/makefile.mk15
-rw-r--r--o3tl/qa/test-cow_wrapper.cxx18
-rw-r--r--o3tl/qa/test-heap_ptr.cxx6
-rw-r--r--o3tl/qa/test-range.cxx7
-rw-r--r--o3tl/qa/test-vector_pool.cxx69
8 files changed, 224 insertions, 29 deletions
diff --git a/o3tl/inc/o3tl/vector_pool.hxx b/o3tl/inc/o3tl/vector_pool.hxx
new file mode 100644
index 000000000000..19fc3d6d74c4
--- /dev/null
+++ b/o3tl/inc/o3tl/vector_pool.hxx
@@ -0,0 +1,132 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: lazy_update.hxx,v $
+ * $Revision: 1.3 $
+ *
+ * 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 INCLUDED_O3TL_VECTOR_POOL_HXX
+#define INCLUDED_O3TL_VECTOR_POOL_HXX
+
+#include <sal/types.h>
+#include <vector>
+
+namespace o3tl
+{
+ namespace detail
+ {
+ template<typename ValueType, class Container> class simple_pool_impl :
+ public Container
+ {
+ typedef typename Container::value_type value_type;
+ std::ptrdiff_t mnFirstFreeIndex;
+
+ public:
+ simple_pool_impl() :
+ mnFirstFreeIndex(-1)
+ {}
+
+ std::ptrdiff_t alloc()
+ {
+ return store(ValueType());
+ }
+
+ std::ptrdiff_t store(const ValueType& rCopy)
+ {
+ if( mnFirstFreeIndex != -1 )
+ {
+ std::ptrdiff_t nIdx=mnFirstFreeIndex;
+ mnFirstFreeIndex = this->at(mnFirstFreeIndex).nextFree;
+ this->at(nIdx).value = rCopy;
+ this->at(nIdx).nextFree = -1;
+
+ return nIdx;
+ }
+ else
+ {
+ push_back(value_type(rCopy));
+ return this->size()-1;
+ }
+ }
+
+ void free( std::ptrdiff_t nIdx )
+ {
+ this->at(nIdx).nextFree = mnFirstFreeIndex;
+ mnFirstFreeIndex = nIdx;
+ }
+
+ const ValueType& get( std::ptrdiff_t nIdx ) const
+ {
+ return this->operator[](nIdx).value;
+ }
+ ValueType& get( std::ptrdiff_t nIdx )
+ {
+ return this->operator[](nIdx).value;
+ }
+ };
+
+ template< typename ValueType > struct struct_from_value
+ {
+ struct type
+ {
+ type() :
+ value(),
+ nextFree(-1)
+ {}
+ explicit type( const ValueType& val ) :
+ value(val),
+ nextFree(-1)
+ {}
+
+ ValueType value;
+ std::ptrdiff_t nextFree;
+ };
+ };
+ }
+
+ /** Simple vector-based memory pool allocator
+
+ This template can be used to provide simple pooled memory
+ allocation from a container class that adheres to the stl
+ random access container concept. Note that alloc/free works
+ with _indices_ into the container!
+
+ @example
+ <pre>
+vector_pool<type> myPool;
+int nIdx=myPool.alloc();
+myPool[nIdx] = myVal;
+ ... do stuff ...
+myPool.free(nIdx);
+ </pre>
+ */
+ template<typename ValueType> struct vector_pool :
+ public detail::simple_pool_impl<ValueType,
+ std::vector<typename detail::struct_from_value<ValueType>::type > >
+ {};
+}
+
+#endif /* INCLUDED_O3TL_VECTOR_POOL_HXX */
diff --git a/o3tl/prj/build.lst b/o3tl/prj/build.lst
index 98293257e4bd..2606d1df8586 100644
--- a/o3tl/prj/build.lst
+++ b/o3tl/prj/build.lst
@@ -1,4 +1,4 @@
-ot o3tl : sal testshl2 BOOST:boost NULL
+ot o3tl : sal CPPUNIT:cppunit BOOST:boost NULL
ot o3tl usr1 - all ot_mkout NULL
ot o3tl\inc get - all ot_inc NULL
ot o3tl\prj get - all ot_prj NULL
diff --git a/o3tl/qa/export.map b/o3tl/qa/export.map
index 709047ae63e5..3308588ef6f8 100644
--- a/o3tl/qa/export.map
+++ b/o3tl/qa/export.map
@@ -25,9 +25,9 @@
#
#*************************************************************************
-UDK_3.1 {
+UDK_3_0_0 {
global:
- registerAllTestFunction;
+ cppunitTestPlugIn;
local:
*;
diff --git a/o3tl/qa/makefile.mk b/o3tl/qa/makefile.mk
index 7effe534bbee..3475aeeca9bb 100644
--- a/o3tl/qa/makefile.mk
+++ b/o3tl/qa/makefile.mk
@@ -35,6 +35,9 @@ ENABLE_EXCEPTIONS=TRUE
# --- Settings -----------------------------------------------------
.INCLUDE : settings.mk
+
+CFLAGSCXX += $(CPPUNIT_CFLAGS)
+
.IF "$(L10N_framework)"==""
# --- Common ----------------------------------------------------------
@@ -42,18 +45,19 @@ ENABLE_EXCEPTIONS=TRUE
SHL1OBJS= \
$(SLO)$/cow_wrapper_clients.obj \
$(SLO)$/test-cow_wrapper.obj \
+ $(SLO)$/test-vector_pool.obj \
$(SLO)$/test-heap_ptr.obj \
$(SLO)$/test-range.obj
SHL1TARGET= tests
SHL1STDLIBS= $(SALLIB) \
- $(TESTSHL2LIB)\
$(CPPUNITLIB)
SHL1IMPLIB= i$(SHL1TARGET)
DEF1NAME =$(SHL1TARGET)
SHL1VERSIONMAP = export.map
+SHL1RPATH = NONE
# END ------------------------------------------------------------------
@@ -65,16 +69,9 @@ SLOFILES=$(SHL1OBJS)
.ENDIF # L10N_framework
.INCLUDE : target.mk
-.INCLUDE : _cppunit.mk
# --- Enable test execution in normal build ------------------------
.IF "$(L10N_framework)"==""
-unittest : $(SHL1TARGETN)
- @echo ----------------------------------------------------------
- @echo - start unit test on library $(SHL1TARGETN)
- @echo ----------------------------------------------------------
- $(TESTSHL2) -sf $(mktmp ) $(SHL1TARGETN)
-
-ALLTAR : unittest
+.INCLUDE : _cppunit.mk
.ENDIF # L10N_framework
diff --git a/o3tl/qa/test-cow_wrapper.cxx b/o3tl/qa/test-cow_wrapper.cxx
index eebbb633f82b..84d615fca3db 100644
--- a/o3tl/qa/test-cow_wrapper.cxx
+++ b/o3tl/qa/test-cow_wrapper.cxx
@@ -1,6 +1,9 @@
// autogenerated file with codegen.pl
-#include <testshl/simpleheader.hxx>
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
#include "cow_wrapper_clients.hxx"
@@ -119,15 +122,6 @@ public:
};
// -----------------------------------------------------------------------------
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(cow_wrapper_test, "cow_wrapper_test");
-
-
-// -----------------------------------------------------------------------------
-
-// this macro creates an empty function, which will called by the RegisterAllFunctions()
-// to let the user the possibility to also register some functions by hand.
-void RegisterAdditionalFunctions(FktRegFuncPtr )
-{
-}
-// NOADDITIONAL;
+CPPUNIT_TEST_SUITE_REGISTRATION(cow_wrapper_test);
+CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/o3tl/qa/test-heap_ptr.cxx b/o3tl/qa/test-heap_ptr.cxx
index 44dc2083947a..fe2f78eec8af 100644
--- a/o3tl/qa/test-heap_ptr.cxx
+++ b/o3tl/qa/test-heap_ptr.cxx
@@ -25,7 +25,9 @@
*
************************************************************************/
-#include <testshl/simpleheader.hxx>
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
#include <o3tl/heap_ptr.hxx>
@@ -160,4 +162,4 @@ class heap_ptr_test : public CppUnit::TestFixture
}; // class heap_ptr_test
// -----------------------------------------------------------------------------
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(heap_ptr_test, "o3tltests");
+CPPUNIT_TEST_SUITE_REGISTRATION(heap_ptr_test);
diff --git a/o3tl/qa/test-range.cxx b/o3tl/qa/test-range.cxx
index 9ead908675b9..31cf2aec7c10 100644
--- a/o3tl/qa/test-range.cxx
+++ b/o3tl/qa/test-range.cxx
@@ -25,8 +25,9 @@
*
************************************************************************/
-
-#include <testshl/simpleheader.hxx>
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
#include <o3tl/range.hxx>
#include <vector>
@@ -230,4 +231,4 @@ public:
}; // class range_test
// -----------------------------------------------------------------------------
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(range_test, "o3tltests");
+CPPUNIT_TEST_SUITE_REGISTRATION(range_test);
diff --git a/o3tl/qa/test-vector_pool.cxx b/o3tl/qa/test-vector_pool.cxx
new file mode 100644
index 000000000000..4efaebdd3414
--- /dev/null
+++ b/o3tl/qa/test-vector_pool.cxx
@@ -0,0 +1,69 @@
+// autogenerated file with codegen.pl
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+
+#include <o3tl/vector_pool.hxx>
+
+using namespace ::o3tl;
+
+class vector_pool_test : public CppUnit::TestFixture
+{
+public:
+ void testPoolBasics()
+ {
+ vector_pool<int> aPool;
+
+ std::ptrdiff_t nIdx1 = aPool.alloc();
+ std::ptrdiff_t nIdx2 = aPool.alloc();
+ std::ptrdiff_t nIdx3 = aPool.alloc();
+
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 );
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 );
+
+ aPool.free(nIdx2);
+ aPool.free(nIdx3);
+
+ nIdx2 = aPool.alloc();
+ nIdx3 = aPool.alloc();
+
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 );
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 );
+ }
+
+ void testPoolValueSemantics()
+ {
+ vector_pool<int> aPool;
+
+ std::ptrdiff_t nIdx1 = aPool.store(0);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 );
+
+ std::ptrdiff_t nIdx2 = aPool.store(1);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 );
+
+ std::ptrdiff_t nIdx3 = aPool.store(2);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 );
+
+ aPool.free(nIdx2);
+ aPool.free(nIdx3);
+
+ nIdx2 = aPool.store(1);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 );
+
+ nIdx3 = aPool.store(2);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 );
+ }
+
+ // Change the following lines only, if you add, remove or rename
+ // member functions of the current class,
+ // because these macros are need by auto register mechanism.
+
+ CPPUNIT_TEST_SUITE(vector_pool_test);
+ CPPUNIT_TEST(testPoolBasics);
+ CPPUNIT_TEST(testPoolValueSemantics);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test);