Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
asset.hpp
Go to the documentation of this file.
1 /*
2  ASSET.hpp - Superinterface: bookkeeping view of "things" present in the session
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
55 #ifndef PROC_INTERFACE_ASSET_H
56 #define PROC_INTERFACE_ASSET_H
57 
58 
59 #include "lib/error.hpp"
60 #include "lib/nocopy.hpp"
61 #include "include/logging.h"
62 #include "proc/asset/category.hpp"
63 #include "lib/hash-value.h"
64 #include "lib/p.hpp"
65 
66 #include <boost/type_traits/is_base_of.hpp>
67 #include <boost/operators.hpp>
68 
69 #include <cstddef>
70 #include <string>
71 #include <vector>
72 #include <set>
73 
74 
75 using std::string;
76 using std::vector;
77 using std::set;
78 
79 
80 namespace proc {
81 namespace asset {
82 
83  namespace error = lumiera::error;
84 
85  using std::size_t;
86  using std::shared_ptr;
87  using std::static_pointer_cast;
88 
89  using lib::HashVal;
90 
91 
92 
105  template<class KIND>
106  class ID
107  {
109  public:
110  ID (HashVal id) : hash_(id) {}
111  ID (const KIND& asset) : hash_(asset.getID()) {}
112  operator HashVal() const { return hash_; }
113 
114  static ID INVALID;
115  };
116 
117  class DB;
118  class Asset;
120  typedef const ID<Asset>& IDA;
123 
124 
125 
126 
127 
146  class Asset
147  : public boost::totally_ordered1< Asset
148  , util::NonCopyable >
149  {
150  public:
151 
156  struct Ident
157  : boost::totally_ordered<Ident>
158  {
162  string name;
163 
168 
174  const string org;
175 
182  const uint version;
183 
184 
185  Ident (const string& n,
186  const Category& cat,
187  const string& o = "lumi",
188  const uint ver=1);
189 
190 
191  int compare (Ident const& other) const;
192 
194  bool operator== (Ident const& oi) const { return compare (oi) ==0; }
195  bool operator< (Ident const& oi) const { return compare (oi) < 0; }
196 
197  operator string () const;
198 
199  bool isValid() const;
200  };
201 
202 
203  /* ===== Asset ID and Datafields ===== */
204 
205  public:
206  const Ident ident;
207 
208  virtual const ID<Asset>& getID() const { return id; }
209 
210 
211  bool operator== (Asset const& oa) const { return ident == oa.ident; }
212  bool operator< (Asset const& oa) const { return ident < oa.ident; }
213 
214  virtual operator string () const;
215 
216 
217 
218  protected:
219  const ID<Asset> id;
220 
224  set<string> groups;
225 
227  const string shortDesc;
228 
231  const string longDesc;
232 
233  vector<PAsset> parents;
234  vector<PAsset> dependants;
235 
236  bool enabled;
237 
238 
239 
240  protected:
245  Asset (const Ident& idi);
246  virtual ~Asset() = 0;
247 
259  virtual void unlink ();
260 
263  virtual void unlink (IDA target);
264 
267  void defineDependency (PAsset parent);
268  void defineDependency (Asset& parent);
269 
270  friend class AssetManager;
271  friend class DB;
272 
273  private:
274  void unregister (PAsset& other);
275 
276 
277 
278 
279  public:
283  const vector<PAsset>& getParents () const { return parents; }
284 
289  const vector<PAsset>& getDependant () const { return dependants; }
290 
294  bool isActive () const;
295 
302  bool enable (bool on=true) throw(lumiera::error::State);
303 
304 
305  };
306 
307 
308 
309 
310  /* ====== ordering of Assets and Asset-Pointers ====== */
311 
318  inline int
319  Asset::Ident::compare (Asset::Ident const& oi) const
320  {
321  int res;
322  if (0 != (res=category.compare (oi.category))) return res;
323  if (0 != (res=org.compare (oi.org))) return res;
324  return name.compare (oi.name);
325  }
326 
327 
329  template<class A>
330  inline const PcAsset
331  pAsset (shared_ptr<A> const& subPtr)
332  {
333  return static_pointer_cast<const Asset,A> (subPtr);
334  }
335 
336 
338  template <class X>
339  struct is_pAsset : boost::false_type {};
340 
341  template <class A>
343  : boost::is_base_of<Asset, A> {};
344 
345 
347  template<class KIND>
349 
350 
351 }} // namespace proc::asset
352 
353 
354 
355 namespace proc_interface {
356 
357  using proc::asset::Asset;
358  using proc::asset::Category;
359  using proc::asset::ID;
360  using proc::asset::IDA;
361  using proc::asset::PAsset;
362 }
363 
364 #endif
ID(HashVal id)
Definition: asset.hpp:110
const uint version
version number of the thing or concept represented by this asset.
Definition: asset.hpp:182
Ident(const string &n, const Category &cat, const string &o="lumi", const uint ver=1)
Definition: asset.cpp:56
virtual const ID< Asset > & getID() const
Definition: asset.hpp:208
type trait for detecting a shared-ptr-to-asset
Definition: asset.hpp:339
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:162
const PcAsset pAsset(shared_ptr< A > const &subPtr)
promote subtype-ptr to PAsset, e.g.
Definition: asset.hpp:331
bool isActive() const
weather this asset is switched on and consequently included in the fixture and participates in render...
Definition: asset.cpp:128
const string shortDesc
user visible Name-ID.
Definition: asset.hpp:227
Facade for the Asset subsystem.
void unregister(PAsset &other)
Definition: asset.cpp:160
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
The asset subsystem of the Proc-Layer.
Definition: id-scheme.hpp:64
lib::P< const Asset > PcAsset
Definition: asset.hpp:122
bool operator<(Asset const &oa) const
Definition: asset.hpp:212
const string longDesc
user visible qualification of the thing, unit or concept represented by this asset.
Definition: asset.hpp:231
static ID INVALID
marker constant denoting a NIL asset
Definition: asset.hpp:114
const vector< PAsset > & getDependant() const
All the other assets requiring this asset to be functional.
Definition: asset.hpp:289
bool operator==(Asset const &oa) const
Definition: asset.hpp:211
Customised refcounting smart pointer.
bool operator<(Ident const &oi) const
Definition: asset.hpp:195
This header is for including and configuring NoBug.
const Ident ident
Asset identification tuple.
Definition: asset.hpp:206
const ID< Asset > id
Asset primary key.
Definition: asset.hpp:219
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:167
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:146
virtual void unlink()
release all links to other Asset objects held internally.
Definition: asset.cpp:174
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:156
bool enable(bool on=true)
change the enabled status of this asset.
Definition: asset.cpp:143
Mix-Ins to allow or prohibit various degrees of copying and cloning.
lib::P< Asset > PAsset
Definition: asset.hpp:121
bool isValid() const
Definition: asset.cpp:102
const ID< Asset > & IDA
Definition: asset.hpp:119
LumieraError< LERR_(STATE)> State
Definition: error.hpp:214
vector< PAsset > parents
Definition: asset.hpp:233
Tree like classification of Assets.
Definition: category.hpp:75
const vector< PAsset > & getParents() const
List of entities this asset depends on or requires to be functional.
Definition: asset.hpp:283
HashVal hash_
Definition: asset.hpp:108
Lumiera error handling (C++ interface).
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition: asset.hpp:106
virtual ~Asset()=0
Definition: asset.cpp:75
Lumiera public interface.
void defineDependency(PAsset parent)
establish a connection between this and the given parent asset, denoting we are in some way dependent...
Definition: asset.cpp:193
Asset(const Ident &idi)
Asset is a Interface class; usually, objects of concrete subclasses are created via specialised Facto...
Definition: asset.cpp:67
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
bool operator==(Ident const &oi) const
Definition: asset.hpp:194
int compare(Ident const &other) const
ordering of Assets is based on the ordering of Ident tuples, which are supposed to be unique...
Definition: asset.hpp:319
set< string > groups
additional classification, selections or departments this asset belongs to.
Definition: asset.hpp:224
Definition of Asset categorisation.
const string org
origin or authorship id.
Definition: asset.hpp:174
Implementation of the registry holding all Asset instances known to the Asset Manager subsystem...
Definition: db.hpp:98
vector< PAsset > dependants
Definition: asset.hpp:234
lib::idi::BareEntryID const & ID
Definition: id-scheme.hpp:81
ID(const KIND &asset)
Definition: asset.hpp:111