Extract the type-based counting into a separate facility
This commit is contained in:
parent
c921d927a2
commit
83cd7fd830
5 changed files with 236 additions and 32 deletions
119
src/lib/typed-counter.hpp
Normal file
119
src/lib/typed-counter.hpp
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
TYPED-COUNTER.hpp - maintain a set of type based contexts
|
||||
|
||||
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 typed-allocation-manager.hpp
|
||||
** Abstract foundation for building custom allocation managers.
|
||||
** Currently (as of 8/09) this is a draft, factored out of the command-registry.
|
||||
** The expectation is that we'll face several similar situations, and thus it
|
||||
** would be good to build up a common set of operations and behaviour.
|
||||
** @todo WIP WIP.
|
||||
**
|
||||
** \par Concept Summary
|
||||
** The idea is rather to tie the memory manager to a very specific usage situation,
|
||||
** then to provide a general-purpose allocator to be used by any instance of a given
|
||||
** type. Typically, the goal is to handle memory management for an index or registry,
|
||||
** holding implementation objects to be shielded from the client code. Moreover, we'll
|
||||
** have to deal with families of types rather then with individual types; usually
|
||||
** there will be some common or combined handling for all family members.
|
||||
**
|
||||
** The intention is for this TypedAllocationManager template to be used both as a base
|
||||
** class providing the implementation skeleton for the actual custom allocation manager,
|
||||
** and as an abstract interface, which can be forwarded to the \em implementation classes
|
||||
** in case there is some cooperation required to get the allocation done (for example,
|
||||
** there might be some type erasure involved, leaving the (otherwise opaque) implementation
|
||||
** class as the only entity with a limited knowledge about the actual memory layout, and
|
||||
** thus the only way of creating a clone properly would be to forward down into this
|
||||
** implementation class).
|
||||
**
|
||||
** Thus, TypedAllocationManager provides the classical operations of an allocator
|
||||
** - allocate
|
||||
** - construct
|
||||
** - deallocate
|
||||
** But each of these operations is to be invoked in a \em typed context. Besides,
|
||||
** there is a facility allowing to create ref-counting handles and smart-pointers,
|
||||
** which are internally tied to this memory manager through a deleter function.
|
||||
**
|
||||
** @todo using a quick-n-dirty heap allocation implementation for now (8/09),
|
||||
** but should write a custom allocator based on cehteh's mpool!
|
||||
**
|
||||
** @see CommandRegistry
|
||||
** @see AllocationCluster (another custom allocation scheme, which could be united)
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef LIB_TYPED_COUNTER_H
|
||||
#define LIB_TYPED_COUNTER_H
|
||||
|
||||
//#include "pre.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/format.hpp"
|
||||
#include "include/logging.h"
|
||||
|
||||
|
||||
#include <tr1/memory>
|
||||
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
||||
using std::tr1::shared_ptr;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* temporary helper to count the number of allocations
|
||||
* for diagnostic purpose. When actually implementing a
|
||||
* custom allocation, this information should be available
|
||||
* from the allocator.
|
||||
*/
|
||||
class TypedCounter
|
||||
{
|
||||
public:
|
||||
template<class X>
|
||||
size_t
|
||||
get() const
|
||||
{
|
||||
UNIMPLEMENTED ("get typed count");
|
||||
}
|
||||
|
||||
template<class X>
|
||||
void
|
||||
inc()
|
||||
{
|
||||
UNIMPLEMENTED ("increment typed count");
|
||||
}
|
||||
|
||||
template<class X>
|
||||
void
|
||||
dec()
|
||||
{
|
||||
UNIMPLEMENTED ("decrement typed count");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace lib
|
||||
#endif
|
||||
|
|
@ -69,6 +69,7 @@
|
|||
//#include "pre.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/format.hpp"
|
||||
#include "lib/typed-counter.hpp"
|
||||
#include "include/logging.h"
|
||||
|
||||
|
||||
|
|
@ -305,38 +306,7 @@ namespace control { ////////////////////////////////////////////////////////////
|
|||
|
||||
|
||||
private:
|
||||
/**
|
||||
* temporary helper to count the number of allocations
|
||||
* for diagnostic purpose. When actually implementing a
|
||||
* custom allocation, this information should be available
|
||||
* from the allocator.
|
||||
*/
|
||||
class SlotCounter
|
||||
{
|
||||
public:
|
||||
template<class X>
|
||||
size_t
|
||||
get() const
|
||||
{
|
||||
UNIMPLEMENTED ("get typed count");
|
||||
}
|
||||
|
||||
template<class X>
|
||||
void
|
||||
inc()
|
||||
{
|
||||
UNIMPLEMENTED ("increment typed count");
|
||||
}
|
||||
|
||||
template<class X>
|
||||
void
|
||||
dec()
|
||||
{
|
||||
UNIMPLEMENTED ("decrement typed count");
|
||||
}
|
||||
};
|
||||
|
||||
SlotCounter allocCnt_;
|
||||
lib::TypedCounter allocCnt_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -848,6 +848,11 @@ return: 0
|
|||
END
|
||||
|
||||
|
||||
PLANNED "building type based contexts" TypedCounter_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
TEST "VectorTransfer_test" VectorTransfer_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ test_lib_SOURCES = \
|
|||
$(testlib_srcdir)/test/testoptiontest.cpp \
|
||||
$(testlib_srcdir)/test/test-helper-test.cpp \
|
||||
$(testlib_srcdir)/typed-allocation-manager-test.cpp \
|
||||
$(testlib_srcdir)/typed-counter-test.cpp \
|
||||
$(testlib_srcdir)/vectortransfertest.cpp \
|
||||
$(testlib_srcdir)/visitingtoolconcept.cpp \
|
||||
$(testlib_srcdir)/visitingtoolextendedtest.cpp \
|
||||
|
|
|
|||
109
tests/lib/typed-counter-test.cpp
Normal file
109
tests/lib/typed-counter-test.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
TypedCounter(Test) - managing a set of type based contexts
|
||||
|
||||
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/test/test-helper.hpp"
|
||||
//#include "proc/control/command.hpp"
|
||||
#include "proc/control/typed-allocation-manager.hpp"
|
||||
//#include "proc/control/command-def.hpp"
|
||||
//#include "lib/lumitime.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
|
||||
#include <tr1/memory>
|
||||
//#include <boost/ref.hpp>
|
||||
//#include <boost/format.hpp>
|
||||
//#include <iostream>
|
||||
#include <cstdlib>
|
||||
//#include <string>
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
|
||||
// using boost::format;
|
||||
// using boost::str;
|
||||
//using lumiera::Time;
|
||||
//using util::contains;
|
||||
using std::tr1::shared_ptr;
|
||||
// using std::tr1::bind;
|
||||
// using std::string;
|
||||
using std::rand;
|
||||
//using std::cout;
|
||||
//using std::endl;
|
||||
// using lib::test::showSizeof;
|
||||
using util::isSameObject;
|
||||
// using util::contains;
|
||||
|
||||
// using session::test::TestClip;
|
||||
// using lib::Symbol;
|
||||
// using lumiera::P;
|
||||
|
||||
|
||||
//using lumiera::typelist::BuildTupleAccessor;
|
||||
// using lumiera::error::LUMIERA_ERROR_EXTERNAL;
|
||||
|
||||
namespace { // test data and helpers...
|
||||
|
||||
long checksum_ = 0;
|
||||
|
||||
/**
|
||||
* Yet-another fammily of dummy types....
|
||||
*/
|
||||
template<uint siz>
|
||||
class DummyType
|
||||
{
|
||||
char crap_[siz];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
* @test cover the basic implementation of a custom allocator, delegating to mpool.
|
||||
* TypedAllocationManager is a base class, used e.g. to build the CommandRegistry.
|
||||
*
|
||||
* @todo planned but not implemented as of 8/09 see also Ticket #217
|
||||
*
|
||||
* @see CommandRegistry
|
||||
* @see command-registry-test.cpp
|
||||
* @see allocationclustertest.cpp
|
||||
*/
|
||||
class TypedCounter_test : public Test
|
||||
{
|
||||
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
UNIMPLEMENTED ("type based contexts");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Register this test class... */
|
||||
LAUNCHER (TypedCounter_test, "unit common");
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
Loading…
Reference in a new issue