00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "proc/mobject/session/defsmanager.hpp"
00025 #include "proc/mobject/session/defsregistry.hpp"
00026 #include "common/configrules.hpp"
00027 #include "lib/error.hpp"
00028
00029 #include <boost/format.hpp>
00030
00031 using boost::format;
00032
00033 using lumiera::ConfigRules;
00034 using lumiera::query::QueryHandler;
00035 using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY;
00036
00037
00038 namespace mobject {
00039 namespace session {
00040
00041 using lumiera::P;
00042
00043
00044
00046 DefsManager::DefsManager () throw()
00047 : defsRegistry(new DefsRegistry)
00048 {
00049 TODO ("setup basic defaults of the session");
00050 }
00051
00052
00053
00056 DefsManager::~DefsManager() {}
00057
00058
00059
00060 template<class TAR>
00061 P<TAR>
00062 DefsManager::search (const Query<TAR>& capabilities)
00063 {
00064 P<TAR> res;
00065 QueryHandler<TAR>& typeHandler = ConfigRules::instance();
00066 for (DefsRegistry::Iter<TAR> i = defsRegistry->candidates(capabilities);
00067 res = *i ; ++i )
00068 {
00069 typeHandler.resolve (res, capabilities);
00070 if (res)
00071 return res;
00072 }
00073 return res;
00074 }
00075
00076
00077 template<class TAR>
00078 P<TAR>
00079 DefsManager::create (const Query<TAR>& capabilities)
00080 {
00081 P<TAR> res;
00082 QueryHandler<TAR>& typeHandler = ConfigRules::instance();
00083 typeHandler.resolve (res, capabilities);
00084 if (res)
00085 defsRegistry->put (res, capabilities);
00086 return res;
00087 }
00088
00089
00090 template<class TAR>
00091 bool
00092 DefsManager::define (const P<TAR>& defaultObj, const Query<TAR>& capabilities)
00093 {
00094 P<TAR> candidate (defaultObj);
00095 QueryHandler<TAR>& typeHandler = ConfigRules::instance();
00096 typeHandler.resolve (candidate, capabilities);
00097 if (!candidate)
00098 return false;
00099 else
00100 return defsRegistry->put (candidate, capabilities);
00101 }
00102
00103
00104 template<class TAR>
00105 bool
00106 DefsManager::forget (const P<TAR>& defaultObj)
00107 {
00108 return defsRegistry->forget (defaultObj);
00109 }
00110
00111
00112 template<class TAR>
00113 P<TAR>
00114 DefsManager::operator() (const Query<TAR>& capabilities)
00115 {
00116 P<TAR> res (search (capabilities));
00117 if (res)
00118 return res;
00119 else
00120 res = create (capabilities);
00121
00122 if (!res)
00123 throw lumiera::error::Config ( str(format("The following Query could not be resolved: %s.")
00124 % capabilities.asKey())
00125 , LUMIERA_ERROR_CAPABILITY_QUERY );
00126 else
00127 return res;
00128 }
00129
00130 }
00131
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 #include "proc/asset/procpatt.hpp"
00141 #include "proc/asset/pipe.hpp"
00142 #include "proc/asset/track.hpp"
00143 #include "proc/mobject/session/track.hpp"
00144
00145 namespace mobject
00146 {
00147 namespace session
00148 {
00149
00150 using asset::Pipe;
00151 using asset::PPipe;
00152 using asset::ProcPatt;
00153 using asset::PProcPatt;
00154
00155 using mobject::session::Track;
00156 using mobject::session::TrackAsset;
00157 using mobject::session::PTrack;
00158 using mobject::session::PTrackAsset;
00159
00160 template PPipe DefsManager::operator() (const Query<Pipe>&);
00161 template PProcPatt DefsManager::operator() (const Query<const ProcPatt>&);
00162 template PTrack DefsManager::operator() (const Query<Track>&);
00163 template PTrackAsset DefsManager::operator() (const Query<TrackAsset>&);
00164
00165 template bool DefsManager::define (const PPipe&, const Query<Pipe>&);
00166 template bool DefsManager::forget (const PPipe&);
00167
00168 }
00169
00170 }
00171