00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 #ifndef ASSET_STRUCTFACTORYIMPL_H
00034 #define ASSET_STRUCTFACTORYIMPL_H
00035
00036
00037 #include "proc/mobject/session.hpp"
00038 #include "common/configrules.hpp"
00039 #include "lib/error.hpp"
00040 #include "lib/util.hpp"
00041
00042 #include <boost/format.hpp>
00043
00044 using boost::format;
00045
00046 using mobject::Session;
00047
00048 using util::isnil;
00049 using util::contains;
00050 using asset::Query;
00051 using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY;
00052 using lumiera::query::extractID;
00053
00054 namespace asset
00055 {
00056
00057
00058 template<class STRU>
00059 struct Traits
00060 {
00061 static Symbol namePrefix;
00062 static Symbol catFolder;
00063 static Symbol idSymbol;
00064 };
00065
00066 template<> Symbol Traits<Track>::namePrefix = "track";
00067 template<> Symbol Traits<Track>::catFolder = "tracks";
00068 template<> Symbol Traits<Track>::idSymbol = "track";
00069
00070 template<> Symbol Traits<Pipe>::namePrefix = "pipe";
00071 template<> Symbol Traits<Pipe>::catFolder = "pipes";
00072 template<> Symbol Traits<Pipe>::idSymbol = "pipe";
00073
00074 template<> Symbol Traits<const ProcPatt>::namePrefix = "patt";
00075 template<> Symbol Traits<const ProcPatt>::catFolder = "build-templates";
00076 template<> Symbol Traits<const ProcPatt>::idSymbol = "procPatt";
00077
00078
00079
00080
00086 class StructFactoryImpl
00087 {
00088
00092 template<class STRU>
00093 const Asset::Ident
00094 createIdent (const Query<STRU>& query)
00095 {
00096 string name (query);
00097 string nameID = extractID (Traits<STRU>::idSymbol, query);
00098 if (isnil (nameID))
00099 {
00100
00101
00102 static int i=0;
00103 static format namePattern ("%s.%d");
00104 static format predPattern ("%s(%s), ");
00105 nameID = str(namePattern % Traits<STRU>::namePrefix % (++i) );
00106 name.insert(0,
00107 str(predPattern % Traits<STRU>::idSymbol % nameID ));
00108 }
00109 ENSURE (!isnil (name));
00110 ENSURE (!isnil (nameID));
00111 ENSURE (contains (name, nameID));
00112
00113 Category cat (STRUCT, Traits<STRU>::catFolder);
00114 return Asset::Ident (name, cat );
00115 }
00116
00117
00118
00119
00120
00121
00123 StructFactory& recursive_create_;
00124
00125 public:
00126 StructFactoryImpl (StructFactory& interface)
00127 : recursive_create_(interface)
00128 { }
00129
00130
00131
00135 template<class STRU>
00136 STRU* fabricate (const Query<STRU>& caps)
00137 {
00138 throw lumiera::error::Config ( str(format("The following Query could not be resolved: %s.") % caps.asKey())
00139 , LUMIERA_ERROR_CAPABILITY_QUERY );
00140 }
00141
00142 };
00143
00144
00145
00146
00147 template<>
00148 Track*
00149 StructFactoryImpl::fabricate (const Query<Track>& caps)
00150 {
00151 TODO ("actually extract properties/capabilities from the query...");
00152 TODO ("make sure AssetManager detects dublicates (currently 4/08 it doesn't)");
00153 return new Track (createIdent (caps));
00154 }
00155
00156 template<>
00157 const ProcPatt*
00158 StructFactoryImpl::fabricate (const Query<const ProcPatt>& caps)
00159 {
00160 TODO ("actually extract properties/capabilities from the query...");
00161 return new ProcPatt (createIdent (caps));
00162 }
00163
00164 template<>
00165 Pipe*
00166 StructFactoryImpl::fabricate (const Query<Pipe>& caps)
00167 {
00168 const Asset::Ident idi (createIdent (caps));
00169 string pipeID = extractID ("pipe", idi.name);
00170 string streamID = extractID ("stream", caps);
00171 if (isnil (streamID)) streamID = "default";
00172 PProcPatt processingPattern = Session::current->defaults (Query<const ProcPatt>("stream("+streamID+")"));
00173 return new Pipe( idi
00174 , processingPattern
00175 , pipeID
00176 );
00177 }
00178
00179
00180
00181
00182 }
00183 #endif