WIP parts of the EntryID implementation, refactor struct asset name generation

This commit is contained in:
Fischlurch 2010-03-24 05:00:06 +01:00
parent 2131488afb
commit 07146ad373
4 changed files with 238 additions and 42 deletions

View file

@ -44,21 +44,123 @@
#include "proc/asset.hpp"
#include "proc/asset/struct-scheme.hpp"
#include "lib/hash-indexed.hpp"
#include "lib/util.hpp"
#include <string>
namespace asset {
using std::string;
namespace idi {
using lib::hash::LuidH;
typedef size_t HashVal;
/** build up a hash value, packaged as LUID.
* @param sym symbolic ID-string to be hashed
* @param seed (optional) hash value to combine with the sym.
* @note This is a half baked preliminary solution. The issue here
* is that LUID has a fixed size of 128bit, whereas the hash values
* of the std library (and boost) have the smaller and platform dependent
* type of \c size_t. This hack here assumes that size_t corresponds to void*,
* which is correct for i386 and AMD64. LUID provides a hook for embedding a
* void* (setting the trailing bits to zero). Finally we reinterpret the
* char[] of the LUID as a LuidH class, which is ugly, but granted to work.
* @todo several unsolved design problems. How to deal with std hash values in
* conjunction with LUID. How to create a LuidH instance, if not generating
* a new random value
*/
inline LuidH
buildHash (string const& sym, HashVal seed =0)
{
boost::hash_combine(seed, sym);
lumiera_uid tmpLUID;
lumiera_uid_set_ptr (&tmpLUID, reinterpret_cast<void*> (&seed));
return reinterpret_cast<LuidH> (tmpLUID);
}
}
/**
* type erased baseclass
* for building a combined hash and symbolic ID.
*/
class BareEntryID
{
typedef lib::hash::LuidH LuidH;
string symbol_;
LuidH hash_;
public:
explicit
BareEntryID (string const& symbolID, HashVal seed =0) /////////////TODO couldn't this be protected?
: symbol_(util::sanitise(symbolID))
, hash_(buildHash (symbol_, seed))
{ }
bool
isValid() const
{
return bool(hash_);
}
string const&
getSym() const
{
return symbol_;
}
LuidH const&
getHash() const
{
return hash_;
}
};
/**
* thin ID with blah
*
* @see mobject::session::Track
*/
template<class KIND>
class ID
template<class TY>
class EntryID
: public BareEntryID
{
public:
EntryID()
: BareEntryID (idi::generateSymbolID<TY>(), getTypeHash())
{ }
explicit
EntryID (string const& symbolID)
: BareEntryID (symbolID, getTypeHash<TY>())
{ }
/** generate an Asset identification tuple
* based on this EntryID's symbolic ID and type information.
* The remaining fields are filled in with hardwired defaults.
*/
Asset::Ident
getIdent() const
{
Category cat (STRUCT, idi::StructTraits<TY>::catFolder);
return Asset::Ident (name, cat);
}
static idi::HashVal
getTypeHash()
{
Category cat (STRUCT, idi::StructTraits<TY>::catFolder);
return hash_value (cat);
}
};

View file

@ -45,6 +45,8 @@
#include "proc/asset/track.hpp"
#include "proc/asset/pipe.hpp"
#include "proc/asset/struct-scheme.hpp"
#include "lib/symbol.hpp"
#include "lib/error.hpp"
#include "lib/util.hpp"
@ -65,36 +67,9 @@ using lumiera::query::extractID;
namespace asset {
using idi::StructTraits;
namespace { // structural asset ID scheme ///////////////////////////////////////////////////////////TICKET #565
template<class STRU>
struct Traits
{
static Symbol namePrefix;
static Symbol catFolder;
static Symbol idSymbol;
};
template<> Symbol Traits<Track>::namePrefix = "track";
template<> Symbol Traits<Track>::catFolder = "tracks";
template<> Symbol Traits<Track>::idSymbol = "track";
template<> Symbol Traits<Pipe>::namePrefix = "pipe";
template<> Symbol Traits<Pipe>::catFolder = "pipes";
template<> Symbol Traits<Pipe>::idSymbol = "pipe";
template<> Symbol Traits<const ProcPatt>::namePrefix = "patt";
template<> Symbol Traits<const ProcPatt>::catFolder = "build-templates";
template<> Symbol Traits<const ProcPatt>::idSymbol = "procPatt";
template<> Symbol Traits<Timeline>::namePrefix = "tL";
template<> Symbol Traits<Timeline>::catFolder = "timelines";
template<> Symbol Traits<Timeline>::idSymbol = "timeline";
template<> Symbol Traits<Sequence>::namePrefix = "seq";
template<> Symbol Traits<Sequence>::catFolder = "sequences";
template<> Symbol Traits<Sequence>::idSymbol = "sequence";
namespace {
Symbol genericIdSymbol ("id");
@ -102,6 +77,7 @@ namespace asset {
/**
* Implementation details, especially concerning how configuration
* queries are resolved and when to create new objects automatically.
@ -122,7 +98,7 @@ namespace asset {
// does the query somehow specify the desired name-ID?
string nameID = extractID (genericIdSymbol, query);
if (isnil (nameID))
nameID = extractID (Traits<STRU>::idSymbol, query);
nameID = extractID (StructTraits<STRU>::idSymbol, query);
if (isnil (nameID))
{
// no name-ID contained in the query...
@ -130,15 +106,15 @@ namespace asset {
static int i=0;
static format namePattern ("%s.%d");
static format predPattern ("%s(%s), ");
nameID = str(namePattern % Traits<STRU>::namePrefix % (++i) );
nameID = str(namePattern % StructTraits<STRU>::namePrefix % (++i) );
name.insert(0,
str(predPattern % Traits<STRU>::idSymbol % nameID ));
str(predPattern % StructTraits<STRU>::idSymbol % nameID ));
}
ENSURE (!isnil (name));
ENSURE (!isnil (nameID));
ENSURE (contains (name, nameID));
Category cat (STRUCT, Traits<STRU>::catFolder);
Category cat (STRUCT, StructTraits<STRU>::catFolder);
return Asset::Ident (name, cat ); ///////////////////////TICKET #565 the ID field should be just the ID, the query should go into a dedicated "capabilities" field.
}

View file

@ -0,0 +1,118 @@
/*
STRUCT-SCHEME.hpp - naming and designation scheme for structural assets
Copyright (C) Lumiera.org
2010, 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 struct-scheme.hpp
** Naming and labelling scheme for structural assets.
** Preconfigured traits data for the relevant types encountered in
** Lumiera's session data model.
**
** @see struct-factory-impl.hpp
** @see entry-id.hpp
**
*/
#ifndef ASSET_STRUCT_SCHEME_H
#define ASSET_STRUCT_SCHEME_H
//#include "proc/mobject/session.hpp"
//#include "proc/mobject/mobject.hpp"
#include "lib/symbol.hpp"
//#include "lib/error.hpp"
//#include "lib/util.hpp"
//#include <boost/format.hpp>
#include <boost/format.hpp>
using boost::format;
/////////////////////////////////////////////////////////TODO needs to be pushed down into a *.cpp
//using mobject::Session;
//using mobject::MObject;
using lib::Symbol;
//using util::isnil;
//using util::contains;
//using asset::Query;
//using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY;
//using lumiera::query::extractID;
namespace asset{
class Track;
class Pipe;
class ProcPatt;
class Timeline;
class Sequence;
namespace idi {
// structural asset ID scheme ///////////////////////////////////////////////////////////TICKET #565
template<class STRU>
struct StructTraits
{
static Symbol namePrefix;
static Symbol catFolder;
static Symbol idSymbol;
};
template<> Symbol Traits<Track>::namePrefix = "track";
template<> Symbol Traits<Track>::catFolder = "tracks";
template<> Symbol Traits<Track>::idSymbol = "track";
template<> Symbol Traits<Pipe>::namePrefix = "pipe";
template<> Symbol Traits<Pipe>::catFolder = "pipes";
template<> Symbol Traits<Pipe>::idSymbol = "pipe";
template<> Symbol Traits<const ProcPatt>::namePrefix = "patt";
template<> Symbol Traits<const ProcPatt>::catFolder = "build-templates";
template<> Symbol Traits<const ProcPatt>::idSymbol = "procPatt";
template<> Symbol Traits<Timeline>::namePrefix = "tL";
template<> Symbol Traits<Timeline>::catFolder = "timelines";
template<> Symbol Traits<Timeline>::idSymbol = "timeline";
template<> Symbol Traits<Sequence>::namePrefix = "seq";
template<> Symbol Traits<Sequence>::catFolder = "sequences";
template<> Symbol Traits<Sequence>::idSymbol = "sequence";
template<class STRU>
inline string
generateSymbolID()
{
static uint i=0;
static format namePattern ("%s.%02d");
/////////////////////////////////////////////////////////TODO needs to be pushed down into a *.cpp
return str(namePattern % StructTraits<STRU>::namePrefix % (++i) );
}
}} // namespace asset::idi
#endif

View file

@ -46,7 +46,7 @@ using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
namespace asset{
namespace test {
namespace { // Test data...
namespace { // Test definitions...
struct Dummy { };
@ -90,9 +90,9 @@ namespace test {
DummyID dID1;
DummyID dID2("strange");
DummyID dID3;
CHECK (dID1);
CHECK (dID2);
CHECK (dID3);
CHECK (dID1.isValid());
CHECK (dID2.isValid());
CHECK (dID3.isValid());
CHECK (dID1 != dID2); CHECK (dID2 != dID1);
CHECK (dID2 != dID3); CHECK (dID3 != dID2);
CHECK (dID1 != dID3); CHECK (dID3 != dID1);
@ -100,9 +100,9 @@ namespace test {
TrackID tID1;
TrackID tID2;
TrackID tID3("special");
CHECK (tID1);
CHECK (tID2);
CHECK (tID3);
CHECK (tID1.isValid());
CHECK (tID2.isValid());
CHECK (tID3.isValid());
CHECK (tID1 != tID2); CHECK (tID2 != tID1);
CHECK (tID2 != tID3); CHECK (tID3 != tID2);
CHECK (tID1 != tID3); CHECK (tID3 != tID1);