WIP towards a asset::Struct naming scheme
This commit is contained in:
parent
34b14a226e
commit
ea0416881e
9 changed files with 143 additions and 70 deletions
|
|
@ -26,10 +26,18 @@
|
|||
#include "nobugcfg.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <map>
|
||||
|
||||
using std::map;
|
||||
using boost::regex;
|
||||
using boost::smatch;
|
||||
using boost::regex_search;
|
||||
using boost::algorithm::is_upper;
|
||||
using boost::algorithm::is_alpha;
|
||||
|
||||
using util::contains;
|
||||
|
||||
|
||||
namespace cinelerra
|
||||
{
|
||||
|
|
@ -48,6 +56,35 @@ namespace cinelerra
|
|||
if (is_upper() (first))
|
||||
id[0] = std::tolower (first);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace // Implementation details
|
||||
{
|
||||
map<Symbol, regex> regexTable;
|
||||
}
|
||||
|
||||
/** (preliminary) helper: instead of really parsing and evaluating the terms,
|
||||
* just do a regular expression match to extract the literal argument
|
||||
* behind the given predicate symbol. e.g calling
|
||||
* queryID ("stream", "id(abc), stream(mpeg)")
|
||||
* yields "mpeg"
|
||||
*/
|
||||
const string
|
||||
extractID (Symbol sym, const string& termString)
|
||||
{
|
||||
|
||||
if (!contains (regexTable, sym))
|
||||
regexTable[sym] = regex (string(sym)+="\\(\\s*([\\w_\\.\\-]+)\\s*\\)");
|
||||
|
||||
smatch match;
|
||||
if (regex_search (termString, match, regexTable[sym]))
|
||||
return string (match[1]);
|
||||
else
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
} // namespace query
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@
|
|||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
|
||||
namespace cinelerra
|
||||
{
|
||||
using std::string;
|
||||
using boost::format;
|
||||
|
||||
/* ==== comon definitions for rule based queries ==== */
|
||||
|
||||
|
|
@ -47,7 +49,9 @@ namespace cinelerra
|
|||
class Query : public std::string
|
||||
{
|
||||
public:
|
||||
Query (const string& predicate="") : string(predicate) {}
|
||||
explicit Query (const string& predicate="") : string(predicate) {}
|
||||
explicit Query (format& pattern) : string(str(pattern)) {}
|
||||
|
||||
|
||||
const string asKey() const
|
||||
{
|
||||
|
|
@ -65,6 +69,9 @@ namespace cinelerra
|
|||
*/
|
||||
void normalizeID (string& id);
|
||||
|
||||
const string extractID (Symbol, const string& termString);
|
||||
|
||||
|
||||
|
||||
} // namespace query
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,14 @@ namespace cinelerra
|
|||
Ptr obj = Struct::create (query);
|
||||
return AnyPair(query.asKey(), obj);
|
||||
}
|
||||
|
||||
/** shortcut for simply accessing a table entry */
|
||||
template<class STRU, class PTAB>
|
||||
any&
|
||||
item (PTAB& table, const string& query)
|
||||
{
|
||||
return (*table)[Query<STRU>(query).asKey()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -82,8 +90,16 @@ namespace cinelerra
|
|||
INFO (config, "creating mock answers for some config queries...");
|
||||
isInit_ = true; // allow re-entrance
|
||||
|
||||
typedef const ProcPatt cPP;
|
||||
|
||||
// for baiscpipetest.cpp ---------
|
||||
answer_->insert (entry_Struct<const ProcPatt> ("stream(teststream)"));
|
||||
answer_->insert (entry_Struct<cPP> ("stream(video)"));
|
||||
answer_->insert (entry_Struct<cPP> ("stream(teststream)"));
|
||||
item<cPP> (answer_, "stream(default)") = item<cPP> (answer_,"stream(video)"); //TODO killme
|
||||
|
||||
answer_->insert (entry_Struct<Pipe> ("pipe(master), stream(video)"));
|
||||
item<Pipe> (answer_, "pipe(default)") = item<Pipe>(answer_,"pipe(master), stream(video)"); //TODO killme
|
||||
TODO ("remove the default entries!!! DefaultsManager should find them automatically");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,35 +22,30 @@
|
|||
|
||||
|
||||
#include "proc/asset/pipe.hpp"
|
||||
#include "common/util.hpp"
|
||||
|
||||
using util::isnil;
|
||||
|
||||
namespace asset
|
||||
{
|
||||
|
||||
namespace // Pipe Asset implementation details
|
||||
{
|
||||
/** @internal derive a sensible asset ident tuple when creating
|
||||
* a pipe asset based on a query
|
||||
* @todo define the actual naming scheme of struct assets
|
||||
*/
|
||||
const Asset::Ident
|
||||
createPipeIdent (PProcPatt& wiring, string& id, wstring& shortD, wstring& longD)
|
||||
{
|
||||
string name ("pipe-" + id); // TODO something sensible here; append number, sanitize etc.
|
||||
TODO ("Implement pipe name scheme!!");
|
||||
Category category (STRUCT,"pipes");
|
||||
return Asset::Ident (name, category );
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
Pipe::Pipe (PProcPatt& wiring, string pipeID, wstring shortDesc, wstring longDesc)
|
||||
: Struct (createPipeIdent (wiring,pipeID,shortDesc,longDesc)),
|
||||
Pipe::Pipe ( const Asset::Ident& idi
|
||||
, PProcPatt& wiring
|
||||
, const string& pipeID
|
||||
, wstring shortName
|
||||
, wstring longName
|
||||
)
|
||||
: Struct (idi),
|
||||
pipeID_ (pipeID),
|
||||
wiringTemplate(wiring),
|
||||
shortDesc (shortDesc),
|
||||
longDesc (longDesc)
|
||||
shortDesc (shortName),
|
||||
longDesc (longName)
|
||||
{
|
||||
|
||||
REQUIRE (!isnil (pipeID));
|
||||
if (isnil (shortDesc))
|
||||
shortDesc = wstring (pipeID.begin(), pipeID.end());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace asset
|
|||
*/
|
||||
class Pipe : public Struct
|
||||
{
|
||||
string pipeID_;
|
||||
const string pipeID_;
|
||||
PProcPatt wiringTemplate;
|
||||
|
||||
public:
|
||||
|
|
@ -66,7 +66,7 @@ namespace asset
|
|||
|
||||
|
||||
protected:
|
||||
Pipe (PProcPatt& wiring, string pipeID="", wstring shortDesc =wstring(), wstring longDesc =wstring()) ;
|
||||
Pipe (const Asset::Ident&, PProcPatt& wiring, const string& pipeID, wstring shortName =wstring(), wstring longName =wstring()) ;
|
||||
friend class StructFactory;
|
||||
friend class StructFactoryImpl;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "proc/asset/procpatt.hpp"
|
||||
#include "proc/asset/track.hpp"
|
||||
#include "proc/asset/pipe.hpp"
|
||||
#include "proc/mobject/session.hpp"
|
||||
#include "common/configrules.hpp"
|
||||
|
||||
#include "proc/asset/structfactoryimpl.hpp"
|
||||
|
|
@ -34,18 +33,16 @@
|
|||
#include "common/util.hpp"
|
||||
#include "nobugcfg.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
using boost::regex;
|
||||
using boost::smatch;
|
||||
using boost::regex_search;
|
||||
using boost::format;
|
||||
|
||||
using mobject::Session;
|
||||
using cinelerra::Symbol;
|
||||
using cinelerra::query::normalizeID;
|
||||
|
||||
using cinelerra::ConfigRules;
|
||||
using cinelerra::query::QueryHandler;
|
||||
using cinelerra::ConfigRules;
|
||||
|
||||
using util::contains;
|
||||
|
||||
|
||||
namespace asset
|
||||
|
|
@ -53,11 +50,6 @@ namespace asset
|
|||
|
||||
/****** NOTE: not really implemented yet. What follows is partially a hack to build simple tests *******/
|
||||
|
||||
namespace // Implementation details
|
||||
{
|
||||
regex streamID_pattern("stream\\(\\s*(\\w+)\\s*\\)");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** query the currently defined properties of this
|
||||
|
|
@ -65,12 +57,15 @@ namespace asset
|
|||
const string
|
||||
Struct::queryStreamID() const
|
||||
{
|
||||
smatch match;
|
||||
|
||||
if (regex_search (this->ident.name, match, streamID_pattern))
|
||||
return string (match[1]);
|
||||
else
|
||||
return "";
|
||||
return cinelerra::query::extractID ("stream", this->ident.name);
|
||||
}
|
||||
|
||||
/** query the currently defined properties of this
|
||||
structural asset for a stream-ID predicate */
|
||||
const string
|
||||
Struct::queryPipeID() const
|
||||
{
|
||||
return cinelerra::query::extractID ("pipe", this->ident.name);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -126,8 +121,8 @@ namespace asset
|
|||
{
|
||||
normalizeID (pipeID);
|
||||
normalizeID (streamID);
|
||||
PProcPatt processingPattern = Session::current->defaults (Query<const ProcPatt>("stream("+streamID+")"));
|
||||
Pipe* pP = new Pipe (processingPattern, pipeID);
|
||||
static format descriptor("pipe(%s), stream(%s).");
|
||||
Pipe* pP = impl_->fabricate (Query<Pipe> (descriptor % pipeID % streamID));
|
||||
return AssetManager::instance().wrap (*pP);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ namespace asset
|
|||
}
|
||||
|
||||
const string queryStreamID() const;
|
||||
const string queryPipeID() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -34,16 +34,22 @@
|
|||
#define ASSET_STRUCTFACTORYIMPL_H
|
||||
|
||||
|
||||
#include "proc/mobject/session.hpp"
|
||||
#include "common/configrules.hpp"
|
||||
#include "common/error.hpp"
|
||||
#include "common/util.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
using boost::format;
|
||||
|
||||
using mobject::Session;
|
||||
|
||||
using util::isnil;
|
||||
using util::contains;
|
||||
using asset::Query;
|
||||
using cinelerra::query::CINELERRA_ERROR_CAPABILITY_QUERY;
|
||||
|
||||
using cinelerra::query::extractID;
|
||||
|
||||
namespace asset
|
||||
{
|
||||
|
|
@ -54,16 +60,20 @@ namespace asset
|
|||
{
|
||||
static Symbol namePrefix;
|
||||
static Symbol catFolder;
|
||||
static Symbol idSymbol;
|
||||
};
|
||||
|
||||
template<> Symbol Traits<Track>::namePrefix = "track-";
|
||||
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>::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>::namePrefix = "patt";
|
||||
template<> Symbol Traits<const ProcPatt>::catFolder = "build-templates";
|
||||
template<> Symbol Traits<const ProcPatt>::idSymbol = "procPatt";
|
||||
|
||||
|
||||
|
||||
|
|
@ -78,30 +88,32 @@ namespace asset
|
|||
|
||||
/** @internal derive a sensible asset ident tuple when creating
|
||||
* structural asset instances based on a capability query
|
||||
* @todo define the actual naming scheme of struct assets
|
||||
*/
|
||||
template<class STRU>
|
||||
const Asset::Ident
|
||||
createIdent (const Query<STRU>& query)
|
||||
{
|
||||
static int i=0;
|
||||
static format namePattern ("%s%d-%s"); // TODO finally just use the capability string as name??
|
||||
string name = str(namePattern % Traits<STRU>::namePrefix % (++i) % query);
|
||||
TODO ("struct asset naming scheme??");
|
||||
string name (query);
|
||||
string nameID = extractID (Traits<STRU>::idSymbol, query);
|
||||
if (isnil (nameID))
|
||||
{
|
||||
// no name-ID contained in the query...
|
||||
// so we'll create a new one
|
||||
static int i=0;
|
||||
static format namePattern ("%s.%d");
|
||||
static format predPattern ("%s(%s), ");
|
||||
nameID = str(namePattern % Traits<STRU>::namePrefix % (++i) );
|
||||
name.insert(0,
|
||||
str(predPattern % Traits<STRU>::idSymbol % nameID ));
|
||||
}
|
||||
ENSURE (!isnil (name));
|
||||
ENSURE (!isnil (nameID));
|
||||
ENSURE (contains (name, nameID));
|
||||
|
||||
Category cat (STRUCT, Traits<STRU>::catFolder);
|
||||
return Asset::Ident (name, cat );
|
||||
}
|
||||
|
||||
typedef std::pair<string,string> PipeIDs;
|
||||
|
||||
PipeIDs
|
||||
createPipeIdent (const Query<Pipe>& query)
|
||||
{
|
||||
string name (Traits<Pipe>::namePrefix + query); // TODO get some more sensible dummy values
|
||||
TODO ("pipe naming scheme??");
|
||||
TODO ("actually extract the pipe stream type from the query...");
|
||||
return PipeIDs (name, "data"); // dummy stream type
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -153,8 +165,15 @@ namespace asset
|
|||
Pipe*
|
||||
StructFactoryImpl::fabricate (const Query<Pipe>& caps)
|
||||
{
|
||||
PipeIDs ids (createPipeIdent (caps));
|
||||
return recursive_create_ (ids.first, ids.second).get();
|
||||
const Asset::Ident idi (createIdent (caps));
|
||||
string pipeID = extractID ("pipe", idi.name);
|
||||
string streamID = extractID ("stream", caps);
|
||||
if (isnil (streamID)) streamID = "default";
|
||||
PProcPatt processingPattern = Session::current->defaults (Query<const ProcPatt>("stream("+streamID+")"));
|
||||
return new Pipe( idi
|
||||
, processingPattern
|
||||
, pipeID
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,11 +65,12 @@ namespace asset
|
|||
{
|
||||
virtual void run(Arg arg)
|
||||
{
|
||||
string pipeID = isnil(arg)? "blackHole" : arg[1];
|
||||
string pipeID = isnil(arg)? "Black Hole" : arg[1];
|
||||
string streamID = 2>arg.size()? "teststream" : arg[2] ;
|
||||
|
||||
createExplicit (pipeID,streamID);
|
||||
create_or_ref (pipeID);
|
||||
create_using_default ();
|
||||
dependProcPatt (pipeID);
|
||||
}
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ namespace asset
|
|||
{
|
||||
string pID_sane (pID);
|
||||
normalizeID (pID_sane);
|
||||
ASSERT (pID_sane != pID);
|
||||
|
||||
PPipe thePipe = asset::Struct::create (pID,sID);
|
||||
|
||||
|
|
@ -118,6 +120,7 @@ namespace asset
|
|||
ASSERT (c1 == c2);
|
||||
|
||||
PPipe pipe3 = Pipe::query ("pipe("+pID2+")");
|
||||
//////////////////////////////////////////////////////////////TODO: er macht eine Neue, anstatt die Bestehende zu finden
|
||||
ASSERT (pipe3 == pipe2);
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +133,7 @@ namespace asset
|
|||
ASSERT (pipe1 == Session::current->defaults (Query<Pipe>()));
|
||||
ASSERT (pipe1->ident.category.hasKind(VIDEO));
|
||||
ASSERT (pipe1->getProcPatt());
|
||||
PProcPatt popa = Session::current->defaults (Query<ProcPatt>("pipe()"));
|
||||
PProcPatt popa = Session::current->defaults (Query<const ProcPatt>("pipe(default)"));
|
||||
ASSERT (popa == pipe1->getProcPatt());
|
||||
|
||||
// several variants to query for "the default pipe"
|
||||
|
|
@ -138,14 +141,14 @@ namespace asset
|
|||
ASSERT (pipe2 == pipe1);
|
||||
pipe2 = asset::Struct::create (Query<Pipe> ());
|
||||
ASSERT (pipe2 == pipe1);
|
||||
pipe2 = asset::Struct::create (Query<Pipe> ("pipe()"));
|
||||
pipe2 = asset::Struct::create (Query<Pipe> ("pipe(default)"));
|
||||
ASSERT (pipe2 == pipe1);
|
||||
|
||||
string sID = popa->queryStreamID(); // sort of a "default stream type"
|
||||
PPipe pipe3 = Pipe::query ("stream("+sID+")");
|
||||
ASSERT (pipe3);
|
||||
ASSERT (pipe3->getProcPatt()->queryStreamID() == sID);
|
||||
ASSERT (pipe3->getProcPatt() == Session::current->defaults (Query<ProcPatt>("stream("+sID+")")));
|
||||
ASSERT (pipe3->getProcPatt() == Session::current->defaults (Query<const ProcPatt>("stream("+sID+")")));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue