clean-up: some further bits never actually used
design sketches, prototype, textbook-implementation, this-might-be-a-good-idea stuff
This commit is contained in:
parent
bec55a89e0
commit
08bdb912a5
13 changed files with 38 additions and 1270 deletions
|
|
@ -1,166 +0,0 @@
|
||||||
/*
|
|
||||||
HashFNV - FNV hash functions
|
|
||||||
|
|
||||||
original by chongo <Landon Curt Noll> /\oo/\
|
|
||||||
http://www.isthe.com/chongo/
|
|
||||||
adapted for Lumiera
|
|
||||||
2010, 2011 Christian Thaeter <ct@pipapo.org>
|
|
||||||
|
|
||||||
Please do not copyright this code. This code is in the public domain.
|
|
||||||
|
|
||||||
LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
||||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
|
||||||
EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
||||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
|
||||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
Share and Enjoy! :-)
|
|
||||||
|
|
||||||
* *****************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/** @file hash-fnv.c
|
|
||||||
** Implementation of FNV ("Fowler-Noll-Vo") hashing functions.
|
|
||||||
** @remarks code for this implementation is public domain
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "lib/hash-fnv.h"
|
|
||||||
|
|
||||||
#include <nobug.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64a_buf (const void *buf, size_t len, uint64_t hval)
|
|
||||||
{
|
|
||||||
const unsigned char *bp = (const unsigned char *)buf;
|
|
||||||
const unsigned char *be = bp + len;
|
|
||||||
while (bp < be)
|
|
||||||
{
|
|
||||||
hval ^= (uint64_t)*bp++;
|
|
||||||
hval *= HASH_FNV64_PRIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32a_buf (const void *buf, size_t len, uint32_t hval)
|
|
||||||
{
|
|
||||||
const unsigned char *bp = (const unsigned char *)buf;
|
|
||||||
const unsigned char *be = bp + len;
|
|
||||||
while (bp < be)
|
|
||||||
{
|
|
||||||
hval ^= (uint32_t)*bp++;
|
|
||||||
hval *= HASH_FNV32_PRIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64a_strn (const char* str, size_t len, uint64_t hval)
|
|
||||||
{
|
|
||||||
const unsigned char *bp = (const unsigned char *)str;
|
|
||||||
if (bp)
|
|
||||||
while (*bp && len--)
|
|
||||||
{
|
|
||||||
hval ^= (uint64_t)*bp++;
|
|
||||||
hval *= HASH_FNV64_PRIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32a_strn (const char* str, size_t len, uint32_t hval)
|
|
||||||
{
|
|
||||||
const unsigned char *bp = (const unsigned char *)str;
|
|
||||||
if (bp)
|
|
||||||
while (*bp && len--)
|
|
||||||
{
|
|
||||||
hval ^= (uint32_t)*bp++;
|
|
||||||
hval *= HASH_FNV32_PRIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64_xorfold (uint64_t hash, int bits)
|
|
||||||
{
|
|
||||||
REQUIRE(bits <= 64);
|
|
||||||
|
|
||||||
bits = 64-bits;
|
|
||||||
|
|
||||||
uint64_t mask = ~0ULL>>bits;
|
|
||||||
for (int todo = 32; bits && todo; todo >>= 1)
|
|
||||||
if (bits >= todo)
|
|
||||||
{
|
|
||||||
hash = hash ^ hash>>todo;
|
|
||||||
bits-=todo;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash & mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32_xorfold (uint32_t hash, int bits)
|
|
||||||
{
|
|
||||||
REQUIRE (bits <= 32);
|
|
||||||
|
|
||||||
bits = 32-bits;
|
|
||||||
|
|
||||||
uint32_t mask = ~0ULL>>bits;
|
|
||||||
for (int todo = 16; bits && todo; todo >>= 1)
|
|
||||||
if (bits >= todo)
|
|
||||||
{
|
|
||||||
hash = hash ^ hash>>todo;
|
|
||||||
bits-=todo;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash & mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64_retry (uint64_t hash, uint64_t limit)
|
|
||||||
{
|
|
||||||
uint64_t retry_level= (UINT64_MAX / limit) * limit;
|
|
||||||
|
|
||||||
while (hash >= retry_level)
|
|
||||||
hash = (hash * HASH_FNV64_PRIME) + HASH_FNV64_BASE;
|
|
||||||
|
|
||||||
return hash % limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32_retry (uint64_t hash, uint32_t limit)
|
|
||||||
{
|
|
||||||
uint32_t retry_level= (UINT32_MAX / limit) * limit;
|
|
||||||
|
|
||||||
while (hash >= retry_level)
|
|
||||||
hash = (hash * HASH_FNV32_PRIME) + HASH_FNV32_BASE;
|
|
||||||
|
|
||||||
return hash % limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Local Variables:
|
|
||||||
// mode: C
|
|
||||||
// c-file-style: "gnu"
|
|
||||||
// indent-tabs-mode: nil
|
|
||||||
// End:
|
|
||||||
*/
|
|
||||||
|
|
@ -1,155 +0,0 @@
|
||||||
/*
|
|
||||||
HASH-FNV.h - FNV hash functions
|
|
||||||
|
|
||||||
original by chongo <Landon Curt Noll> /\oo/\
|
|
||||||
http://www.isthe.com/chongo/
|
|
||||||
adapted for Lumiera
|
|
||||||
2010, 2011 Christian Thaeter <ct@pipapo.org>
|
|
||||||
|
|
||||||
Please do not copyright this code. This code is in the public domain.
|
|
||||||
|
|
||||||
LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
||||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
|
||||||
EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
||||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
|
||||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
Share and Enjoy! :-)
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/** @file hash-fnv.h
|
|
||||||
** Fowler-Noll-Vo Hashes.
|
|
||||||
** FNV is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Phong Vo.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef HASH_FNV_H
|
|
||||||
#define HASH_FNV_H
|
|
||||||
|
|
||||||
#include <stdlib.h> /* for size_t */
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#define HASH_FNV64_BASE ((uint64_t)14695981039346656037ULL)
|
|
||||||
#define HASH_FNV32_BASE ((uint32_t)2166136261UL)
|
|
||||||
|
|
||||||
#define HASH_FNV64_PRIME ((uint64_t)1099511628211ULL)
|
|
||||||
#define HASH_FNV32_PRIME ((uint32_t)16777619UL)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FNV-1a 64 bit hash over a buffer.
|
|
||||||
* @param buf start of the buffer
|
|
||||||
* @param len size of the buffer
|
|
||||||
* @param hval previous hash value when incremental hashing or HASH_FNV64_BASE when starting a new hash
|
|
||||||
* @return new hash value
|
|
||||||
*/
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64a_buf (const void *buf, size_t len, uint64_t hval);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FNV-1a 64 bit hash over a zero terminated string.
|
|
||||||
* @param str start of the buffer
|
|
||||||
* @param len maximum size to be processed
|
|
||||||
* @param hval previous hash value when incremental hashing or HASH_FNV64_BASE when starting a new hash
|
|
||||||
* @return new hash value
|
|
||||||
*/
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64a_strn (const char* str, size_t len, uint64_t hval);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FNV-1a 32 bit hash over a buffer.
|
|
||||||
* @param buf start of the buffer
|
|
||||||
* @param len size of the buffer
|
|
||||||
* @param hval previous hash value when incremental hashing or HASH_FNV32_BASE when starting a new hash
|
|
||||||
* @return new hash value
|
|
||||||
*/
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32a_buf (const void *buf, size_t len, uint32_t hval);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FNV-1a 32 bit hash over a zero terminated string.
|
|
||||||
* @param str start of the buffer
|
|
||||||
* @param len maximum size to be processed
|
|
||||||
* @param hval previous hash value when incremental hashing or HASH_FNV32_BASE when starting a new hash
|
|
||||||
* @return new hash value
|
|
||||||
*/
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32a_strn (const char* str, size_t len, uint32_t hval);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reduce a hash value to n bits.
|
|
||||||
* Uses the xor folding method to stash a hash value together, this preserves unbiased hash distribution
|
|
||||||
* @param hash result from one of the 64 bit hash functions above
|
|
||||||
* @param bits number of significat bits for the result
|
|
||||||
* @result hashvalue with no more than 'bits' significant bits
|
|
||||||
*/
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64_xorfold (uint64_t hash, int bits);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reduce a hash value to n bits.
|
|
||||||
* Uses the xor folding method to stash a hash value together, this preserves unbiased hash distribution
|
|
||||||
* @param hash result from one of the 32 bit hash functions above
|
|
||||||
* @param bits number of significat bits for the result
|
|
||||||
* @result hashvalue with no more than 'bits' significant bits
|
|
||||||
*/
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32_xorfold (uint32_t hash, int bits);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reduce hash to be within 0 to limit-1.
|
|
||||||
* Uses the retry method to limit a hash value, this preserves unbiased hash distribution.
|
|
||||||
* @param hash result from one of the 64 bit hash functions above
|
|
||||||
* @param limit upper limit plus one for the result
|
|
||||||
* @result hashvalue in the range from 0 to limit-1
|
|
||||||
*/
|
|
||||||
uint64_t
|
|
||||||
hash_fnv64_retry (uint64_t hash, uint64_t limit);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reduce hash to be within 0 to limit-1.
|
|
||||||
* Uses the retry method to limit a hash value, this preserves unbiased hash distribution.
|
|
||||||
* @param hash result from one of the 32 bit hash functions above
|
|
||||||
* @param limit upper limit plus one for the result
|
|
||||||
* @result hashvalue in the range from 0 to limit-1
|
|
||||||
*/
|
|
||||||
uint32_t
|
|
||||||
hash_fnv32_retry (uint64_t hash, uint32_t limit);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
PLANNED? 128 bit and 256bit hashes
|
|
||||||
128 bit FNV_prime = 288 + 28 + 0x3b = 309485009821345068724781371
|
|
||||||
|
|
||||||
256 bit FNV_prime = 2168 + 28 + 0x63 = 374144419156711147060143317175368453031918731002211
|
|
||||||
|
|
||||||
128 bit offset_basis = 144066263297769815596495629667062367629
|
|
||||||
|
|
||||||
256 bit offset_basis =
|
|
||||||
100029257958052580907070968620625704837092796014241193945225284501741471925557
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Local Variables:
|
|
||||||
// mode: C
|
|
||||||
// c-file-style: "gnu"
|
|
||||||
// indent-tabs-mode: nil
|
|
||||||
// End:
|
|
||||||
*/
|
|
||||||
|
|
@ -42,6 +42,11 @@
|
||||||
** relying on rvalue references and variadic templates. However, we still need a
|
** relying on rvalue references and variadic templates. However, we still need a
|
||||||
** specialised factory template to allow for a _family of factory functions_ with
|
** specialised factory template to allow for a _family of factory functions_ with
|
||||||
** common configuration.
|
** common configuration.
|
||||||
|
** @todo 2025 ...and still not fully convinced this is the way to go;
|
||||||
|
** admittedly we did not get to a point yet where fabricating lots of elements
|
||||||
|
** poses any kind of challenge — up to now a dedicated factory function within a service
|
||||||
|
** was enough to handle this task. Yet this may change, once we have stream types,
|
||||||
|
** various kinds of assets (notably effects and processors) and lots of queries.
|
||||||
**
|
**
|
||||||
** @see multifact-test.cpp
|
** @see multifact-test.cpp
|
||||||
** @see multifact-singleton-test.cpp
|
** @see multifact-singleton-test.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
NOBUG-RESOURCE-HANDLE-CONTEXT.hpp - thread local stack to manage NoBug resource handles
|
|
||||||
|
|
||||||
Copyright (C)
|
|
||||||
2010, Hermann Vosseler <Ichthyostega@web.de>
|
|
||||||
|
|
||||||
**Lumiera** 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. See the file COPYING for further details.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @file nobug-resource-handle-context.hpp
|
|
||||||
** Thread-local stack of NoBug resource handles.
|
|
||||||
** This helper allows to access the resource handle in the nearest enclosing scope.
|
|
||||||
** The motivation for this approach was to avoid passing the resource handle over
|
|
||||||
** several intermediary function calls when using a scoped variable to control
|
|
||||||
** object monitor locking. Within this usage context, the necessity of passing
|
|
||||||
** a NoBug resource handle seems to be a cross-cutting concern, and not directly
|
|
||||||
** related to the core concern (controlling a mutex).
|
|
||||||
**
|
|
||||||
** @remarks as of 8/2011, this feature is not used anymore. In 12/2011, the concept
|
|
||||||
** of a diagnostic context stack was generalised. At that point, this header was
|
|
||||||
** created as an off-spin, now based on the generalised feature, to document this
|
|
||||||
** usage possibility, which might be required again at some point in the future.
|
|
||||||
**
|
|
||||||
** @see lib::DiagnosticContext
|
|
||||||
** @see diagnostic-context-test.hpp
|
|
||||||
**
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIB_NOBUG_RESOURCE_HANDLE_CONTEXT_H
|
|
||||||
#define LIB_NOBUG_RESOURCE_HANDLE_CONTEXT_H
|
|
||||||
|
|
||||||
|
|
||||||
#include "lib/error.hpp"
|
|
||||||
#include "lib/diagnostic-context.hpp"
|
|
||||||
|
|
||||||
#include <nobug.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef NOBUG_MODE_ALPHA ////////////////////////TODO don't we need the handle in BETA builds for resource logging?
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Diagnostic data frame to hold a NoBug resource handle.
|
|
||||||
* This way, code in nested function calls may pick up the nearest available handle.
|
|
||||||
* @warning relies on thread-local access; never use this within global data structures.
|
|
||||||
*/
|
|
||||||
class NobugResourceHandleContext
|
|
||||||
: DiagnosticContext<nobug_resource_user*>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#else /* not NOBUG_ALPHA */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disabled placeholder for the Diagnostic context, not used in release builds.
|
|
||||||
*/
|
|
||||||
class NobugResourceHandleContext
|
|
||||||
: util::NonCopyable
|
|
||||||
{
|
|
||||||
|
|
||||||
typedef nobug_resource_user* Handle;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
operator Handle () ///< payload: NoBug resource tracker user handle
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** accessing the innermost diagnostic context created */
|
|
||||||
static NobugResourceHandleContext&
|
|
||||||
access ()
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("how to disable DiagnosticContext with minimum overhead");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif /* NOBUG_ALPHA? */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace lib
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,295 +0,0 @@
|
||||||
/*
|
|
||||||
SIMPLE-ALLOCATOR.hpp - frontend for plain explicit allocations
|
|
||||||
|
|
||||||
Copyright (C)
|
|
||||||
2011, Hermann Vosseler <Ichthyostega@web.de>
|
|
||||||
|
|
||||||
**Lumiera** 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. See the file COPYING for further details.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/** @file simple-allocator.hpp
|
|
||||||
** Frontend and marker interface for allocating small objects explicitly.
|
|
||||||
** Contrary to the TypedAllocationManager, the SimpleAllocator doesn't provide any
|
|
||||||
** ref-counting or tracking facilities, nor does he support bulk de-allocation.
|
|
||||||
** Each object needs to be allocated and released by explicit call.
|
|
||||||
** The advantage over using std::allocator directly is the shortcut for (placement) construction,
|
|
||||||
** and -- of course -- the ability to exchange the memory model at one central location.
|
|
||||||
**
|
|
||||||
** SimpleAllocator instances will be defined for a specific collection of types; for each of those
|
|
||||||
** types, there will be an embedded dedicated custom allocator (currently as of 9/2011, just
|
|
||||||
** implemented as std::allocator<TY>). Objects of these preconfigured types can be constructed
|
|
||||||
** and destroyed through this allocator instance. Each call needs to be done explicitly, with
|
|
||||||
** the precise, concrete type to be created or destroyed. This is especially important for
|
|
||||||
** the releasing of objects: there is \em no support for any kind of virtual destruction.
|
|
||||||
**
|
|
||||||
** @see engine::BufferMetadata
|
|
||||||
** @see TypedAllocationManager (another more elaborate custom allocation scheme)
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIB_SIMPLE_ALLOCATOR_H
|
|
||||||
#define LIB_SIMPLE_ALLOCATOR_H
|
|
||||||
|
|
||||||
#include "lib/error.hpp"
|
|
||||||
#include "lib/meta/generator.hpp"
|
|
||||||
#include "lib/meta/typelist-util.hpp"
|
|
||||||
#include "lib/meta/util.hpp"
|
|
||||||
#include "lib/typed-counter.hpp"
|
|
||||||
#include "include/logging.h"
|
|
||||||
|
|
||||||
#include <boost/static_assert.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
|
||||||
|
|
||||||
using lib::meta::Types;
|
|
||||||
using lib::meta::IsInList;
|
|
||||||
using lib::meta::InstantiateForEach;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* === Policies for simple custom allocator === */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy: use just plain heap allocations
|
|
||||||
* @warning whenever you define a specialisation,
|
|
||||||
* _you_ are responsible for proper alignment
|
|
||||||
* @see TICKET #1204
|
|
||||||
*/
|
|
||||||
template<typename TY>
|
|
||||||
class CustomAllocator
|
|
||||||
: public std::allocator<TY>
|
|
||||||
{ };
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy: maintain explicit per type instance count
|
|
||||||
* @note this imposes additional locking
|
|
||||||
*/
|
|
||||||
struct UseInstantiationCounting
|
|
||||||
{
|
|
||||||
template<class XX>
|
|
||||||
size_t
|
|
||||||
allocationCount() const
|
|
||||||
{
|
|
||||||
return allocCnt_.get<XX>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class XX>
|
|
||||||
void
|
|
||||||
incrementCount()
|
|
||||||
{
|
|
||||||
allocCnt_.inc<XX>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class XX>
|
|
||||||
void
|
|
||||||
decrementCount()
|
|
||||||
{
|
|
||||||
allocCnt_.dec<XX>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
lib::TypedCounter allocCnt_;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy: no additional instantiation accounting
|
|
||||||
*/
|
|
||||||
struct NoInstantiationCount
|
|
||||||
{
|
|
||||||
template<class XX> size_t allocationCount() const { return 0; }
|
|
||||||
template<class XX> void incrementCount() { /* NOP */ }
|
|
||||||
template<class XX> void decrementCount() { /* NOP */ }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* === Allocator frontend === */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frontend for explicit allocations, using a custom allocator.
|
|
||||||
* This template is to be instantiated for the collection of types
|
|
||||||
* later to be allocated through this custom memory manager/model.
|
|
||||||
* It provides convenience shortcuts for placement-construction
|
|
||||||
* and releasing of target objects.
|
|
||||||
*
|
|
||||||
* @todo currently (as of 8/09) the low-level pooled allocator
|
|
||||||
* isn't implemented; instead we do just heap allocations.
|
|
||||||
* ////////////////////////////////////////////////////////////////////////////////////////////Ticket #835
|
|
||||||
*/
|
|
||||||
template<typename TYPES
|
|
||||||
,class COUNTER = NoInstantiationCount ///< Policy: support instance accounting?
|
|
||||||
>
|
|
||||||
class SimpleAllocator
|
|
||||||
: InstantiateForEach< typename TYPES::List // for each of those types...
|
|
||||||
, CustomAllocator // ...mix in the custom allocator
|
|
||||||
>
|
|
||||||
, COUNTER // ...Instantiation accounting policy
|
|
||||||
{
|
|
||||||
|
|
||||||
/** forward plain memory allocation */
|
|
||||||
template<class XX>
|
|
||||||
XX *
|
|
||||||
allocateSlot ()
|
|
||||||
{
|
|
||||||
TRACE (memory, "allocate «%s»", util::typeStr<XX>().c_str());
|
|
||||||
XX * newStorage = CustomAllocator<XX>::allocate (1);
|
|
||||||
COUNTER::template incrementCount<XX>();
|
|
||||||
return newStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class XX>
|
|
||||||
void
|
|
||||||
releaseSlot (XX* entry)
|
|
||||||
{
|
|
||||||
TRACE (memory, "release «%s»", util::typeStr<XX>().c_str());
|
|
||||||
CustomAllocator<XX>::deallocate (entry, 1);
|
|
||||||
COUNTER::template decrementCount<XX>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class XX>
|
|
||||||
void
|
|
||||||
___assertSupportedType()
|
|
||||||
{
|
|
||||||
typedef typename TYPES::List PreconfiguredTypes;
|
|
||||||
typedef IsInList<XX, PreconfiguredTypes> IsSupportedType;
|
|
||||||
|
|
||||||
BOOST_STATIC_ASSERT (IsSupportedType::value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public: /* ==== build objects with managed allocation ==== */
|
|
||||||
|
|
||||||
#define _EXCEPTION_SAFE_INVOKE(_CTOR_) \
|
|
||||||
\
|
|
||||||
___assertSupportedType<XX>(); \
|
|
||||||
XX* storage = allocateSlot<XX>(); \
|
|
||||||
try \
|
|
||||||
{ \
|
|
||||||
return (new(storage) _CTOR_ ); \
|
|
||||||
} \
|
|
||||||
catch(...) \
|
|
||||||
{ \
|
|
||||||
releaseSlot<XX>(storage); \
|
|
||||||
throw; \
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class XX>
|
|
||||||
XX* //_____________________
|
|
||||||
create () ///< invoke default ctor
|
|
||||||
{
|
|
||||||
_EXCEPTION_SAFE_INVOKE ( XX() )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class XX, typename P1>
|
|
||||||
XX* //___________________
|
|
||||||
create (P1& p1) ///< invoke 1-arg ctor
|
|
||||||
{
|
|
||||||
_EXCEPTION_SAFE_INVOKE ( XX (p1) )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class XX
|
|
||||||
, typename P1
|
|
||||||
, typename P2
|
|
||||||
>
|
|
||||||
XX* //___________________
|
|
||||||
create (P1& p1, P2& p2) ///< invoke 2-arg ctor
|
|
||||||
{
|
|
||||||
_EXCEPTION_SAFE_INVOKE ( XX (p1,p2) )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class XX
|
|
||||||
, typename P1
|
|
||||||
, typename P2
|
|
||||||
, typename P3
|
|
||||||
>
|
|
||||||
XX* //___________________
|
|
||||||
create (P1& p1, P2& p2, P3& p3) ///< invoke 3-arg ctor
|
|
||||||
{
|
|
||||||
_EXCEPTION_SAFE_INVOKE ( XX (p1,p2,p3) )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class XX
|
|
||||||
, typename P1
|
|
||||||
, typename P2
|
|
||||||
, typename P3
|
|
||||||
, typename P4
|
|
||||||
>
|
|
||||||
XX* //___________________
|
|
||||||
create (P1& p1, P2& p2, P3& p3, P4& p4) ///< invoke 4-arg ctor
|
|
||||||
{
|
|
||||||
_EXCEPTION_SAFE_INVOKE ( XX (p1,p2,p3,p4) )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class XX
|
|
||||||
, typename P1
|
|
||||||
, typename P2
|
|
||||||
, typename P3
|
|
||||||
, typename P4
|
|
||||||
, typename P5
|
|
||||||
>
|
|
||||||
XX* //___________________
|
|
||||||
create (P1& p1, P2& p2, P3& p3, P4& p4, P5& p5) ///< invoke 5-arg ctor
|
|
||||||
{
|
|
||||||
_EXCEPTION_SAFE_INVOKE ( XX (p1,p2,p3,p4,p5) )
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef _EXCEPTION_SAFE_INVOKE
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class XX>
|
|
||||||
void
|
|
||||||
destroy (XX* entry)
|
|
||||||
{
|
|
||||||
if (!entry) return;
|
|
||||||
___assertSupportedType<XX>();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
entry->~XX();
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
lumiera_err errorID = lumiera_error();
|
|
||||||
WARN (common_dbg, "dtor of «%s» failed: %s", util::typeStr(entry).c_str()
|
|
||||||
, errorID );
|
|
||||||
}
|
|
||||||
releaseSlot<XX> (entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** diagnostics */
|
|
||||||
template<class XX>
|
|
||||||
size_t
|
|
||||||
numSlots() const
|
|
||||||
{
|
|
||||||
return COUNTER::template allocationCount<XX>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace lib
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,143 +0,0 @@
|
||||||
/*
|
|
||||||
SUB-ID.hpp - extensible symbolic identifier
|
|
||||||
|
|
||||||
Copyright (C)
|
|
||||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
||||||
|
|
||||||
**Lumiera** 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. See the file COPYING for further details.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/** @file sub-id.hpp
|
|
||||||
** Extensible symbolic ID type.
|
|
||||||
** @remark this is a design sketch (from 9/2009) an not used anywhere as of 3/2017...
|
|
||||||
**
|
|
||||||
** My observation is that, during design, I did run again and again into a specific
|
|
||||||
** situation, which I then needed to circumvent in lack of a first class solution.
|
|
||||||
** Learning from that experiences, I start building this structured ID template.
|
|
||||||
** - it shall be an \em symbolic identifier, not an artificial ID
|
|
||||||
** - the basic value set should be limited and statically type safe.
|
|
||||||
** - possibility of structured adornments and variations
|
|
||||||
** - optionally concealing these extensions from the interface level
|
|
||||||
**
|
|
||||||
** The first attempt to build such an entity is based on standard techniques,
|
|
||||||
** disregarding performance and memory footprint considerations.
|
|
||||||
**
|
|
||||||
** @todo 1/2016 this idea seems very reasonable, and we should just make it
|
|
||||||
** robust and usable, along the lines pointed out by that draft
|
|
||||||
** - use std::tuple as storage
|
|
||||||
** - remove the `format-util` dependency (!) ////////////////////////////////TICKET #985
|
|
||||||
** - provide a hash implementation for real
|
|
||||||
** - extend to arbitrary number of sub-dimensions (variadic)
|
|
||||||
** - implement comparisons as you'd do for any algebraic type
|
|
||||||
** - provide a metaprogramming facility to get an id tuple
|
|
||||||
**
|
|
||||||
** @see SubID_test
|
|
||||||
** @see MultiFact
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIB_SUB_ID_H
|
|
||||||
#define LIB_SUB_ID_H
|
|
||||||
|
|
||||||
#include "lib/format-util.hpp"
|
|
||||||
|
|
||||||
//#include <functional>
|
|
||||||
#include <boost/functional/hash.hpp> /////TODO better push the hash implementation into a cpp file (and btw, do it more seriously!)
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
|
||||||
|
|
||||||
using boost::hash_value;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<typename I>
|
|
||||||
class SubId;
|
|
||||||
|
|
||||||
class SubID
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~SubID() { }
|
|
||||||
|
|
||||||
virtual operator string() const =0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
inline size_t
|
|
||||||
hash_value (SubID const& sID)
|
|
||||||
{
|
|
||||||
return hash_value (string (sID));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
operator== (SubID const& id1, SubID const& id2)
|
|
||||||
{
|
|
||||||
return (string (id1) == string (id2));
|
|
||||||
}
|
|
||||||
|
|
||||||
////////TODO a serious implementation should descend recursively, instead of relying on the string representation
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename I>
|
|
||||||
class SubId
|
|
||||||
: public SubID
|
|
||||||
{
|
|
||||||
I baseID_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SubId (I id)
|
|
||||||
: baseID_(id)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
operator string() const
|
|
||||||
{
|
|
||||||
using util::toString;
|
|
||||||
return toString (baseID_); // note: extension point
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename I, class SUZ>
|
|
||||||
class ExtendedSubId
|
|
||||||
: public SubId<I>
|
|
||||||
{
|
|
||||||
typedef SubId<I> _baID;
|
|
||||||
|
|
||||||
SUZ extID_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ExtendedSubId (I i, SUZ const& chain)
|
|
||||||
: _baID(i)
|
|
||||||
, extID_(chain)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
operator string() const
|
|
||||||
{
|
|
||||||
return _baID::operator string()
|
|
||||||
+ '.'
|
|
||||||
+ string (extID_);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace lib
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
vcall.h - helper macros for virtual (method) calls in C
|
|
||||||
|
|
||||||
Copyright (C) Lumiera.org
|
|
||||||
2010, Christian Thaeter <ct@pipapo.org>
|
|
||||||
|
|
||||||
**Lumiera** 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. See the file COPYING for further details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LUMIERA_VCALL_H
|
|
||||||
#define LUMIERA_VCALL_H
|
|
||||||
|
|
||||||
#include <nobug.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* This allows one to do polymorphic programming in C by referencing a vtable
|
|
||||||
* member which contains function pointers to a structure and then calling
|
|
||||||
* this 'virtual' functions through the VCALL macro.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO usage example, see btree.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* helper macro for calling vtable functions
|
|
||||||
* just adds syntacic sugar VCALL(obj, func, params...)
|
|
||||||
* translates to obj->vtable->func(obj, params...) plus some saftey checks
|
|
||||||
*/
|
|
||||||
#define LUMIERA_VCALL(self, function, ...) \
|
|
||||||
({ \
|
|
||||||
REQUIRE (self); \
|
|
||||||
REQUIRE (self->vtable->function); \
|
|
||||||
self->vtable->function (self, ## __VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#ifndef VCALL
|
|
||||||
#define VCALL LUMIERA_VCALL
|
|
||||||
#else
|
|
||||||
#error "WTF! someone defined VCALL!"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
// Local Variables:
|
|
||||||
// mode: C
|
|
||||||
// c-file-style: "gnu"
|
|
||||||
// indent-tabs-mode: nil
|
|
||||||
// End:
|
|
||||||
*/
|
|
||||||
|
|
@ -628,18 +628,6 @@ return: 0
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
TEST "extensible symbolic identifier" SubID_test <<END
|
|
||||||
out: ....RGB
|
|
||||||
out: id1=R.12
|
|
||||||
out: id2=G.13
|
|
||||||
out: verify...
|
|
||||||
out: Elements in hashtable: 3
|
|
||||||
out: verify...
|
|
||||||
out: Elements in hashtable: 5
|
|
||||||
return: 0
|
|
||||||
END
|
|
||||||
|
|
||||||
|
|
||||||
TEST "ownership of malloced data" UniqueMallocOwner_test <<END
|
TEST "ownership of malloced data" UniqueMallocOwner_test <<END
|
||||||
return: 0
|
return: 0
|
||||||
END
|
END
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,7 @@ PLANNED "StreamTypeLifecycle_test" StreamTypeLifecycle_test <<END
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
TEST "custom allocator(I)" SimpleAllocator_test <<END
|
TEST "typed allocation manager" TypedAllocationManager_test <<END
|
||||||
return: 0
|
|
||||||
END
|
|
||||||
|
|
||||||
|
|
||||||
TEST "custom allocator(II)" TypedAllocationManager_test <<END
|
|
||||||
return: 0
|
return: 0
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,6 @@ TESTING "Steam Layer config rules Test Suite" ./test-suite --group=query
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PLANNED "sub-extensible ID" SubID_test <<END
|
|
||||||
END
|
|
||||||
|
|
||||||
|
|
||||||
TEST "normalise ID" QueryUtils_test normaliseID <<END
|
TEST "normalise ID" QueryUtils_test normaliseID <<END
|
||||||
out-lit: ..original : a A AA dufte 1a _1 A_A BÄH White space §&Ω%€GΩ%€ar ☠☠☠ baäääääge!!!!! :
|
out-lit: ..original : a A AA dufte 1a _1 A_A BÄH White space §&Ω%€GΩ%€ar ☠☠☠ baäääääge!!!!! :
|
||||||
out-lit: normalised : a a aA dufte o1a o_1 a_A bH o white_space gar_bage :
|
out-lit: normalised : a a aA dufte o1a o_1 a_A bH o white_space gar_bage :
|
||||||
|
|
|
||||||
|
|
@ -1,161 +0,0 @@
|
||||||
/*
|
|
||||||
SimpleAllocator(Test) - check interface for simple custom allocations
|
|
||||||
|
|
||||||
Copyright (C)
|
|
||||||
2011, Hermann Vosseler <Ichthyostega@web.de>
|
|
||||||
|
|
||||||
**Lumiera** 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. See the file COPYING for further details.
|
|
||||||
|
|
||||||
* *****************************************************************/
|
|
||||||
|
|
||||||
/** @file simple-allocator-test.cpp
|
|
||||||
** unit test \ref SimpleAllocator_test
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "lib/test/run.hpp"
|
|
||||||
#include "lib/simple-allocator.hpp"
|
|
||||||
#include "lib/util.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
|
||||||
namespace test{
|
|
||||||
|
|
||||||
using util::isSameObject;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace { // test data and helpers...
|
|
||||||
|
|
||||||
long checksum_ = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Yet-another ctor/dtor-tracking test dummy object....
|
|
||||||
*/
|
|
||||||
template<uint siz>
|
|
||||||
class DummyObj
|
|
||||||
{
|
|
||||||
char crap_[siz];
|
|
||||||
|
|
||||||
public:
|
|
||||||
DummyObj()
|
|
||||||
{
|
|
||||||
REQUIRE (siz);
|
|
||||||
for (uint i=0; i<siz; ++i)
|
|
||||||
checksum_ += (crap_[i] = rani(128));
|
|
||||||
}
|
|
||||||
|
|
||||||
DummyObj (DummyObj const& o)
|
|
||||||
{
|
|
||||||
REQUIRE (siz);
|
|
||||||
for (uint i=0; i<siz; ++i)
|
|
||||||
checksum_ += (crap_[i] = o.crap_[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
~DummyObj()
|
|
||||||
{
|
|
||||||
for (uint i=0; i<siz; ++i)
|
|
||||||
checksum_ -= crap_[i];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef Types<DummyObj<1>,DummyObj<23>,string> SupportedTypes;
|
|
||||||
typedef SimpleAllocator<SupportedTypes, UseInstantiationCounting> TestAllocator;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************************//**
|
|
||||||
* @test cover the basic operations of a custom allocator, delegating to mpool.
|
|
||||||
* The SimpleAllocator doesn't provide any ref-counting or tracking facilities,
|
|
||||||
* nor does he support bulk de-allocation. The advantage over using std::allocator
|
|
||||||
* directly is the shortcut for (placement) construction, and -- of course -- the
|
|
||||||
* ability to exchange the memory model at one central location.
|
|
||||||
*
|
|
||||||
* @todo as of 9/11 we do heap allocation, but we should use mpool -- see also Ticket #835
|
|
||||||
*
|
|
||||||
* @see engine::BufferMetadata
|
|
||||||
* @see TypedAllocationManager_test
|
|
||||||
*/
|
|
||||||
class SimpleAllocator_test : public Test
|
|
||||||
{
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
run (Arg)
|
|
||||||
{
|
|
||||||
CHECK (0 == checksum_);
|
|
||||||
seedRand();
|
|
||||||
|
|
||||||
TestAllocator allocator;
|
|
||||||
|
|
||||||
typedef string * PS;
|
|
||||||
typedef DummyObj<1> * PD1;
|
|
||||||
typedef DummyObj<23> * PD23;
|
|
||||||
CHECK (sizeof(DummyObj<1>) != sizeof(DummyObj<23>));
|
|
||||||
|
|
||||||
PD1 pD11 = allocator.create<DummyObj<1>>();
|
|
||||||
PD1 pD12 = allocator.create<DummyObj<1>>();
|
|
||||||
PD23 pD21 = allocator.create<DummyObj<23>>();
|
|
||||||
PD23 pD22 = allocator.create<DummyObj<23>>();
|
|
||||||
PS pS11 = allocator.create<string> ("Lumiera");
|
|
||||||
PS pS12 = allocator.create<string> ("the paradox");
|
|
||||||
|
|
||||||
CHECK (pD11);
|
|
||||||
CHECK (pD12);
|
|
||||||
CHECK (pD21);
|
|
||||||
CHECK (pD22);
|
|
||||||
CHECK (pS11);
|
|
||||||
CHECK (pS12);
|
|
||||||
CHECK (!isSameObject (*pD11, *pD12));
|
|
||||||
CHECK (!isSameObject (*pD11, *pD21));
|
|
||||||
CHECK (!isSameObject (*pD11, *pD22));
|
|
||||||
CHECK (!isSameObject (*pD11, *pS11));
|
|
||||||
CHECK (!isSameObject (*pD11, *pS12));
|
|
||||||
CHECK (!isSameObject (*pD12, *pD21));
|
|
||||||
CHECK (!isSameObject (*pD12, *pD22));
|
|
||||||
CHECK (!isSameObject (*pD12, *pS11));
|
|
||||||
CHECK (!isSameObject (*pD12, *pS12));
|
|
||||||
CHECK (!isSameObject (*pD21, *pD22));
|
|
||||||
CHECK (!isSameObject (*pD21, *pS11));
|
|
||||||
CHECK (!isSameObject (*pD21, *pS12));
|
|
||||||
CHECK (!isSameObject (*pD22, *pS11));
|
|
||||||
CHECK (!isSameObject (*pD22, *pS12));
|
|
||||||
CHECK (!isSameObject (*pS11, *pS12));
|
|
||||||
|
|
||||||
CHECK (*pS11 == "Lumiera");
|
|
||||||
CHECK (*pS12 == "the paradox");
|
|
||||||
|
|
||||||
PD23 pDxx = allocator.create<DummyObj<23>> (*pD21);
|
|
||||||
PS pSxx = allocator.create<string> (*pS12);
|
|
||||||
|
|
||||||
CHECK (*pS12 == *pSxx);
|
|
||||||
CHECK (!isSameObject (*pS12, *pSxx));
|
|
||||||
|
|
||||||
allocator.destroy (pD11);
|
|
||||||
allocator.destroy (pD12);
|
|
||||||
allocator.destroy (pD21);
|
|
||||||
allocator.destroy (pD22);
|
|
||||||
allocator.destroy (pS11);
|
|
||||||
allocator.destroy (pS12);
|
|
||||||
allocator.destroy (pDxx);
|
|
||||||
allocator.destroy (pSxx);
|
|
||||||
|
|
||||||
CHECK (0 == allocator.numSlots<DummyObj<1>>());
|
|
||||||
CHECK (0 == allocator.numSlots<DummyObj<23>>());
|
|
||||||
CHECK (0 == allocator.numSlots<string>());
|
|
||||||
CHECK (0 == checksum_);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/** Register this test class... */
|
|
||||||
LAUNCHER (SimpleAllocator_test, "unit common");
|
|
||||||
|
|
||||||
|
|
||||||
}} // namespace lib::test
|
|
||||||
|
|
@ -1,178 +0,0 @@
|
||||||
/*
|
|
||||||
SubID(Test) - exploring possible properties of an extensible symbolic identifier
|
|
||||||
|
|
||||||
Copyright (C)
|
|
||||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
||||||
|
|
||||||
**Lumiera** 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. See the file COPYING for further details.
|
|
||||||
|
|
||||||
* *****************************************************************/
|
|
||||||
|
|
||||||
/** @file sub-id-test.cpp
|
|
||||||
** unit test \ref SubID_test
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "lib/test/run.hpp"
|
|
||||||
#include "lib/util.hpp"
|
|
||||||
#include "lib/util-foreach.hpp"
|
|
||||||
#include "lib/format-cout.hpp"
|
|
||||||
|
|
||||||
#include "lib/sub-id.hpp"
|
|
||||||
|
|
||||||
#include <boost/functional/hash.hpp>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
|
||||||
namespace test{
|
|
||||||
|
|
||||||
using util::for_each;
|
|
||||||
using std::bind;
|
|
||||||
using std::placeholders::_1;
|
|
||||||
using boost::hash;
|
|
||||||
using std::vector;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace { // test data
|
|
||||||
|
|
||||||
enum Colour { R,G,B };
|
|
||||||
|
|
||||||
|
|
||||||
inline string
|
|
||||||
toString (Colour c) ///< make the enum printable
|
|
||||||
{
|
|
||||||
static string sym("RGB");
|
|
||||||
return sym.substr(c,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************//**
|
|
||||||
* @test for now (9/09) this is a playground for shaping a vague design idea
|
|
||||||
* - base types and casts
|
|
||||||
* - exploring some extensions
|
|
||||||
* - use this ID as Hash-Map key
|
|
||||||
*
|
|
||||||
* @see lib::SubID
|
|
||||||
*/
|
|
||||||
class SubID_test : public Test
|
|
||||||
{
|
|
||||||
|
|
||||||
virtual void
|
|
||||||
run (Arg)
|
|
||||||
{
|
|
||||||
checkBaseType();
|
|
||||||
checkExtension();
|
|
||||||
checkSubIDHash();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
checkBaseType ()
|
|
||||||
{
|
|
||||||
typedef SubId<Colour> CID;
|
|
||||||
CID c1 (R);
|
|
||||||
CID c2 (G);
|
|
||||||
CID c3 (B);
|
|
||||||
|
|
||||||
cout << "...." << c1 << c2 << c3 << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
checkExtension ()
|
|
||||||
{
|
|
||||||
typedef SubId<uint> UID;
|
|
||||||
|
|
||||||
typedef ExtendedSubId<Colour, UID> CUID;
|
|
||||||
|
|
||||||
SubID const& id1 = CUID(R, 12);
|
|
||||||
SubID const& id2 = CUID(G, 13);
|
|
||||||
|
|
||||||
cout << "id1=" << id1 << endl;
|
|
||||||
cout << "id2=" << id2 << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
checkSubIDHash()
|
|
||||||
{
|
|
||||||
typedef SubId<Colour> CID;
|
|
||||||
typedef SubId<uint> UID;
|
|
||||||
typedef ExtendedSubId<Colour, UID> CUID;
|
|
||||||
|
|
||||||
vector<CID> simpleIDs;
|
|
||||||
simpleIDs.push_back(CID(R));
|
|
||||||
simpleIDs.push_back(CID(R));
|
|
||||||
simpleIDs.push_back(CID(G));
|
|
||||||
simpleIDs.push_back(CID(B));
|
|
||||||
|
|
||||||
vector<CUID> extendedIDs;
|
|
||||||
extendedIDs.push_back(CUID(R,22));
|
|
||||||
extendedIDs.push_back(CUID(R,22)); // note the duplicates get dropped
|
|
||||||
extendedIDs.push_back(CUID(R,23));
|
|
||||||
extendedIDs.push_back(CUID(R,24));
|
|
||||||
extendedIDs.push_back(CUID(G,24));
|
|
||||||
extendedIDs.push_back(CUID(B,25));
|
|
||||||
|
|
||||||
buildHashtable<CID> (simpleIDs);
|
|
||||||
buildHashtable<CUID> (extendedIDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class KEY>
|
|
||||||
struct HashTable
|
|
||||||
: std::unordered_map<KEY, string, hash<KEY>>
|
|
||||||
{
|
|
||||||
void
|
|
||||||
add (KEY key)
|
|
||||||
{
|
|
||||||
(*this)[key] = string(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
verify (KEY key)
|
|
||||||
{
|
|
||||||
cout << "verify....." << key << endl;
|
|
||||||
CHECK (string(key) == (*this)[key]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<class KEY>
|
|
||||||
void
|
|
||||||
buildHashtable (vector<KEY> keys)
|
|
||||||
{
|
|
||||||
|
|
||||||
typedef HashTable<KEY> HTab;
|
|
||||||
HTab tab;
|
|
||||||
|
|
||||||
for_each (keys, bind (&HTab::add, ref(tab), _1 ));
|
|
||||||
for_each (keys, bind (&HTab::verify, ref(tab), _1 ));
|
|
||||||
|
|
||||||
cout << "Elements in hashtable: " << tab.size() << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/** Register this test class... */
|
|
||||||
LAUNCHER (SubID_test, "unit common");
|
|
||||||
|
|
||||||
|
|
||||||
}} // namespace lib::test
|
|
||||||
|
|
@ -163776,8 +163776,7 @@ Since then others have made contributions, see the log for the history.</font></
|
||||||
unique_ptr kann das ja auc
|
unique_ptr kann das ja auc
|
||||||
</p>
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html></richcontent>
|
||||||
</richcontent>
|
|
||||||
<icon BUILTIN="yes"/>
|
<icon BUILTIN="yes"/>
|
||||||
<node COLOR="#435e98" CREATED="1748709096713" ID="ID_1603400780" MODIFIED="1748711086783" TEXT="dann copy-and-swap">
|
<node COLOR="#435e98" CREATED="1748709096713" ID="ID_1603400780" MODIFIED="1748711086783" TEXT="dann copy-and-swap">
|
||||||
<arrowlink COLOR="#8198b2" DESTINATION="ID_165954046" ENDARROW="Default" ENDINCLINATION="511;33;" ID="Arrow_ID_1516296474" STARTARROW="None" STARTINCLINATION="331;-41;"/>
|
<arrowlink COLOR="#8198b2" DESTINATION="ID_165954046" ENDARROW="Default" ENDINCLINATION="511;33;" ID="Arrow_ID_1516296474" STARTARROW="None" STARTINCLINATION="331;-41;"/>
|
||||||
|
|
@ -163805,6 +163804,37 @@ Since then others have made contributions, see the log for the history.</font></
|
||||||
</node>
|
</node>
|
||||||
<node BACKGROUND_COLOR="#c8b6c1" COLOR="#435e98" CREATED="1748712767350" ID="ID_1069989891" MODIFIED="1748712793537" TEXT="tot ��"/>
|
<node BACKGROUND_COLOR="#c8b6c1" COLOR="#435e98" CREATED="1748712767350" ID="ID_1069989891" MODIFIED="1748712793537" TEXT="tot ��"/>
|
||||||
</node>
|
</node>
|
||||||
|
<node COLOR="#5b280f" CREATED="1748730829818" ID="ID_700236683" MODIFIED="1748730848701" TEXT="nicht verwendet ... schnell weg damit">
|
||||||
|
<icon BUILTIN="button_cancel"/>
|
||||||
|
<node CREATED="1748730811995" ID="ID_1675553345" MODIFIED="1748730820630" TEXT="nobug-resource-handle-context"/>
|
||||||
|
<node CREATED="1748730821812" ID="ID_1395653066" MODIFIED="1748730826587" TEXT="simple-allocator"/>
|
||||||
|
<node CREATED="1748731113312" ID="ID_1142890094" MODIFIED="1748731115709" TEXT="Sub-ID">
|
||||||
|
<node CREATED="1748731116748" ID="ID_434973605" MODIFIED="1748731124619" TEXT="ja die Idee ist in der Tat sehr relevant"/>
|
||||||
|
<node CREATED="1748731125255" ID="ID_1963832206" MODIFIED="1748731133648" TEXT="wir brauchen strukturierte, algebraische IDs"/>
|
||||||
|
<node CREATED="1748731134567" ID="ID_1264506394" MODIFIED="1748731197197" TEXT="aber wenn schon, dann auch tatsächlich ernsthaft implementiert">
|
||||||
|
<richcontent TYPE="NOTE"><html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
ein Müll-Header mit einem Dummy-Test, der seit > 10 Jahren herumliegt, und alle wichtigen Probleme nicht löst ...
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>dann kann man auch gleich von Null anfangen</i>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</richcontent>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
|
<node CREATED="1748731241722" ID="ID_1013782064" MODIFIED="1748731245961" TEXT="vcall.h">
|
||||||
|
<node CREATED="1748731246885" HGAP="27" ID="ID_189593518" MODIFIED="1748731258996" TEXT="nice try" VSHIFT="4">
|
||||||
|
<font NAME="SansSerif" SIZE="11"/>
|
||||||
|
<icon BUILTIN="ksmiletris"/>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue