00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00054 #ifndef PROC_INTERFACE_ASSET_H
00055 #define PROC_INTERFACE_ASSET_H
00056
00057
00058 #include "proc/asset/category.hpp"
00059 #include "common/error.hpp"
00060 #include "common/p.hpp"
00061
00062 #include <boost/type_traits/is_base_of.hpp>
00063 #include <boost/operators.hpp>
00064 #include <boost/noncopyable.hpp>
00065
00066 #include <cstddef>
00067 #include <string>
00068 #include <vector>
00069 #include <set>
00070
00071
00072 using std::string;
00073 using std::vector;
00074 using std::set;
00075
00076
00077
00078 namespace asset
00079 {
00080
00081 using std::size_t;
00082 using std::tr1::shared_ptr;
00083 using std::tr1::static_pointer_cast;
00084
00085 using lumiera::P;
00086
00087
00100 template<class KIND>
00101 class ID
00102 {
00103 public:
00104 const size_t hash;
00105 ID (size_t id) : hash(id) {}
00106 ID (const KIND& asset) : hash(asset.getID()) {}
00107 operator size_t() const { return hash; }
00108 };
00109
00110 class DB;
00111 class Asset;
00112 class AssetManager;
00113 typedef const ID<Asset>& IDA;
00114 typedef P<Asset> PAsset;
00115 typedef P<const Asset> PcAsset;
00116
00117
00118
00119
00120
00139 class Asset
00140 : boost::totally_ordered1< Asset,
00141 boost::noncopyable>
00142 {
00143 public:
00144
00149 struct Ident
00150 : boost::totally_ordered<Ident>
00151 {
00155 string name;
00156
00160 asset::Category category;
00161
00167 const string org;
00168
00175 const uint version;
00176
00177
00178 Ident (const string& n,
00179 const Category& cat,
00180 const string& o = "lumi",
00181 const uint ver=1);
00182
00183
00184 int compare (const Ident& other) const;
00185
00187 bool operator== (const Ident& oi) const { return compare (oi) ==0; }
00188 bool operator< (const Ident& oi) const { return compare (oi) < 0; }
00189
00190 operator string () const;
00191 };
00192
00193
00194
00195
00196 public:
00197 const Ident ident;
00198
00199 virtual const ID<Asset>& getID() const { return id; }
00200
00201
00202 bool operator== (const Asset& oa) const { return ident == oa.ident; }
00203 bool operator< (const Asset& oa) const { return ident < oa.ident; }
00204
00205 virtual operator string () const;
00206
00207
00208
00209 protected:
00210 const ID<Asset> id;
00211
00215 set<string> groups;
00216
00218 const string shortDesc;
00219
00222 const string longDesc;
00223
00224 vector<PAsset> parents;
00225 vector<PAsset> dependants;
00226
00227 bool enabled;
00228
00229
00230
00231 protected:
00236 Asset (const Ident& idi);
00237 virtual ~Asset() = 0;
00238
00249 virtual void unlink ();
00250
00253 virtual void unlink (IDA target);
00254
00257 void defineDependency (PAsset parent);
00258 void defineDependency (Asset& parent);
00259
00260 friend class AssetManager;
00261 friend class DB;
00262
00263 private:
00264 void unregister (PAsset& other);
00265
00266
00267
00268
00269 public:
00273 const vector<PAsset>& getParents () const { return parents; }
00274
00279 const vector<PAsset>& getDependant () const { return dependants; }
00280
00284 bool isActive () const;
00285
00292 bool enable (bool on=true) throw(lumiera::error::State);
00293
00294
00295 };
00296
00297
00298
00299
00300
00301
00308 inline int
00309 Asset::Ident::compare (const Asset::Ident& oi) const
00310 {
00311 int res;
00312 if (0 != (res=category.compare (oi.category))) return res;
00313 if (0 != (res=org.compare (oi.org))) return res;
00314 return name.compare (oi.name);
00315 }
00316
00317
00319 template<class A>
00320 inline const PcAsset
00321 pAsset (const shared_ptr<A>& subPtr)
00322 {
00323 return static_pointer_cast<const Asset,A> (subPtr);
00324 }
00325
00326
00328 template <class X>
00329 struct is_pAsset : boost::false_type {};
00330
00331 template <class A>
00332 struct is_pAsset<shared_ptr<A> >
00333 : boost::is_base_of<Asset, A> {};
00334
00335
00337 inline string str (const PcAsset& a)
00338 {
00339 if (a)
00340 return string (*a.get());
00341 else
00342 return "Asset(NULL)";
00343 }
00344
00345
00346
00347 }
00348
00349
00350
00351 namespace proc_interface
00352 {
00353 using asset::Asset;
00354 using asset::Category;
00355 using asset::ID;
00356 using asset::IDA;
00357 using asset::PAsset;
00358 }
00359
00360 #endif