first attempt to implement buffer metadata...
...leading to refactoring
This commit is contained in:
parent
3acf804988
commit
7ea9afd1bb
2 changed files with 117 additions and 117 deletions
|
|
@ -78,6 +78,8 @@ namespace engine {
|
||||||
BLOCKED
|
BLOCKED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const LocalKey UNSPECIFIC = 0;
|
const LocalKey UNSPECIFIC = 0;
|
||||||
|
|
||||||
struct TypeHandler
|
struct TypeHandler
|
||||||
|
|
@ -101,134 +103,54 @@ namespace engine {
|
||||||
};
|
};
|
||||||
|
|
||||||
const TypeHandler RAW_BUFFER;
|
const TypeHandler RAW_BUFFER;
|
||||||
|
|
||||||
|
|
||||||
|
/* === Implementation === */
|
||||||
|
|
||||||
|
namespace metadata {
|
||||||
class Metadata
|
|
||||||
: boost::noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Entry
|
|
||||||
{
|
|
||||||
HashVal parent_;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Entry (HashVal parent) : parent_(parent) { }
|
|
||||||
~Entry () { }
|
|
||||||
|
|
||||||
public:
|
|
||||||
HashVal parentKey() const { return parent_;}
|
|
||||||
|
|
||||||
virtual BufferState state() const =0;
|
|
||||||
virtual const void* access() const =0;
|
|
||||||
virtual Entry& mark (BufferState newState) =0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Metadata (Literal implementationID)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
HashVal
|
|
||||||
key ( size_t storageSize
|
|
||||||
, TypeHandler instanceFunc =RAW_BUFFER
|
|
||||||
, LocalKey specifics =UNSPECIFIC)
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("combine the distinguishing properties into a single hash");
|
|
||||||
}
|
|
||||||
|
|
||||||
HashVal
|
|
||||||
key (HashVal parentKey, TypeHandler instanceFunc)
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("create sub-type key");
|
|
||||||
}
|
|
||||||
|
|
||||||
HashVal
|
|
||||||
key (HashVal parentKey, LocalKey specifics)
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("create sub-type key");
|
|
||||||
}
|
|
||||||
|
|
||||||
HashVal
|
|
||||||
key (HashVal parentKey, const void* concreteBuffer)
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("create sub-object key for concrete buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
Entry&
|
|
||||||
get (HashVal key)
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("access, possibly create metadata records");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
isKnown (HashVal key) const
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("diagnostics: known record?");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
isLocked (HashVal key) const
|
|
||||||
{
|
|
||||||
UNIMPLEMENTED ("diagnostics: actually locked buffer instance record?");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* == memory management == */
|
|
||||||
|
|
||||||
Entry& markLocked (HashVal parentKey, const void* buffer);
|
|
||||||
void release (HashVal key);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* === Implementation === */
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
using error::LUMIERA_ERROR_LIFECYCLE;
|
using error::LUMIERA_ERROR_LIFECYCLE;
|
||||||
using error::LUMIERA_ERROR_BOTTOM_VALUE;
|
using error::LUMIERA_ERROR_BOTTOM_VALUE;
|
||||||
|
|
||||||
|
|
||||||
class TypeEntry
|
class Key
|
||||||
: public Metadata::Entry
|
|
||||||
{
|
{
|
||||||
virtual BufferState
|
HashVal parent_;
|
||||||
state() const
|
HashVal hashID_;
|
||||||
{
|
|
||||||
return NIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const void*
|
size_t storageSize_;
|
||||||
access() const
|
TypeHandler instanceFunc_;
|
||||||
{
|
LocalKey specifics_;
|
||||||
throw error::Logic ("This metadata entry is still abstract. "
|
|
||||||
"It can't be associated with a concrete buffer. "
|
|
||||||
"You need to invoke markLocked (buffer)."
|
|
||||||
, LUMIERA_ERROR_LIFECYCLE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Entry&
|
public:
|
||||||
mark (BufferState newState)
|
Key (HashVal familyID, size_t storageSize)
|
||||||
{
|
: parent_(0)
|
||||||
if (newState != NIL)
|
, hashID_(familyID)
|
||||||
throw error::Logic ("This metadata entry is still abstract. "
|
, storageSize_(storageSize)
|
||||||
"The only possible state transition is to markLocked (buffer)."
|
, instanceFunc_(RAW_BUFFER)
|
||||||
, LUMIERA_ERROR_LIFECYCLE
|
, specifics_(UNSPECIFIC)
|
||||||
);
|
{ }
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Key (Key const& parent)
|
||||||
|
: parent_(parent.hashID_)
|
||||||
|
, hashID_(0)
|
||||||
|
, storageSize_(parent.storageSize_)
|
||||||
|
, instanceFunc_(parent.instanceFunc_)
|
||||||
|
, specifics_(parent.specifics_)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
HashVal parentKey() const { return parent_;}
|
||||||
|
operator HashVal() const { return hashID_;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BufferEntry
|
class Entry
|
||||||
: public Metadata::Entry
|
: public Key
|
||||||
{
|
{
|
||||||
BufferState state_;
|
BufferState state_;
|
||||||
const void* buffer_;
|
const void* buffer_;
|
||||||
|
|
||||||
|
public:
|
||||||
virtual BufferState
|
virtual BufferState
|
||||||
state() const
|
state() const
|
||||||
{
|
{
|
||||||
|
|
@ -297,6 +219,84 @@ namespace engine {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Metadata
|
||||||
|
: boost::noncopyable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef metadata::Key Key;
|
||||||
|
typedef metadata::Entry Entry;
|
||||||
|
|
||||||
|
|
||||||
|
Metadata (Literal implementationID)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
Key
|
||||||
|
key ( size_t storageSize
|
||||||
|
, TypeHandler instanceFunc =RAW_BUFFER
|
||||||
|
, LocalKey specifics =UNSPECIFIC)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("combine the distinguishing properties into a single hash");
|
||||||
|
}
|
||||||
|
|
||||||
|
Key
|
||||||
|
key (HashVal parentKey, TypeHandler instanceFunc)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("create sub-type key");
|
||||||
|
}
|
||||||
|
|
||||||
|
Key
|
||||||
|
key (HashVal parentKey, LocalKey specifics)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("create sub-type key");
|
||||||
|
}
|
||||||
|
|
||||||
|
Key
|
||||||
|
key (HashVal parentKey, const void* concreteBuffer)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("create sub-object key for concrete buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
Key const&
|
||||||
|
get (HashVal hashID)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("access the plain key entry");
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry&
|
||||||
|
get (Key key)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("access, possibly create metadata records");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
isKnown (HashVal key) const
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("diagnostics: known record?");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
isLocked (HashVal key) const
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED ("diagnostics: actually locked buffer instance record?");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* == memory management == */
|
||||||
|
|
||||||
|
Entry& markLocked (HashVal parentKey, const void* buffer);
|
||||||
|
void release (HashVal key);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
Metadata::Entry&
|
Metadata::Entry&
|
||||||
Metadata::markLocked (HashVal parentKey, const void* buffer)
|
Metadata::markLocked (HashVal parentKey, const void* buffer)
|
||||||
|
|
@ -304,13 +304,13 @@ namespace engine {
|
||||||
UNIMPLEMENTED ("transition to locked state");
|
UNIMPLEMENTED ("transition to locked state");
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
throw error::Fatal ("Attempt to lock for a NULL buffer. Allocation floundered?"
|
throw error::Fatal ("Attempt to lock for a NULL buffer. Allocation floundered?"
|
||||||
, LUMIERA_ERROR_BOTTOM_VALUE);
|
, error::LUMIERA_ERROR_BOTTOM_VALUE);
|
||||||
|
|
||||||
HashVal newKey = this->key (parentKey, buffer);
|
Key newKey = this->key (parentKey, buffer);
|
||||||
if (isLocked(newKey))
|
if (isLocked(newKey))
|
||||||
throw error::Logic ("Attempt to lock a slot for a new buffer, "
|
throw error::Logic ("Attempt to lock a slot for a new buffer, "
|
||||||
"while actually the old buffer is still locked."
|
"while actually the old buffer is still locked."
|
||||||
, LUMIERA_ERROR_LIFECYCLE );
|
, error::LUMIERA_ERROR_LIFECYCLE );
|
||||||
|
|
||||||
return this->get(newKey);
|
return this->get(newKey);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,11 +110,11 @@ namespace test {
|
||||||
void
|
void
|
||||||
verifyBasicProperties()
|
verifyBasicProperties()
|
||||||
{
|
{
|
||||||
HashVal key = meta_->key(SIZE_A);
|
Metadata::Key key = meta_->key(SIZE_A);
|
||||||
CHECK (key);
|
CHECK (key);
|
||||||
|
|
||||||
HashVal key1 = meta_->key(SIZE_A);
|
Metadata::Key key1 = meta_->key(SIZE_A);
|
||||||
HashVal key2 = meta_->key(SIZE_B);
|
Metadata::Key key2 = meta_->key(SIZE_B);
|
||||||
CHECK (key1);
|
CHECK (key1);
|
||||||
CHECK (key2);
|
CHECK (key2);
|
||||||
CHECK (key == key1);
|
CHECK (key == key1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue