Lumiera  0.pre.03
»edit your freedom«
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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
46 #ifndef STEAM_INTERFACE_ASSET_H
47 #define STEAM_INTERFACE_ASSET_H
48 
49 
50 #include "lib/error.hpp"
51 #include "lib/nocopy.hpp"
52 #include "include/logging.h"
53 #include "steam/asset/category.hpp"
54 #include "lib/hash-value.h"
55 #include "lib/p.hpp"
56 
57 #include <boost/type_traits/is_base_of.hpp>
58 #include <boost/operators.hpp>
59 
60 #include <cstddef>
61 #include <string>
62 #include <vector>
63 #include <set>
64 
65 
66 using std::string;
67 using std::vector;
68 using std::set;
69 
70 
71 namespace steam {
72 namespace asset {
73 
74  namespace error = lumiera::error;
75 
76  using std::size_t;
77  using std::shared_ptr;
78  using std::static_pointer_cast;
79 
80  using lib::HashVal;
81 
82 
83 
98  template<class KIND>
99  class ID
100  {
101  HashVal hash_;
102  public:
103  ID (HashVal id) : hash_(id) {}
104  ID (const KIND& asset) : hash_(asset.getID()) {}
105  operator HashVal() const { return hash_; }
106 
107  static ID INVALID;
108  };
109 
110  class DB;
111  class Asset;
112  class AssetManager;
113  typedef const ID<Asset>& IDA;
114  typedef lib::P<Asset> PAsset;
116 
117 
118 
119 
120 
139  class Asset
140  : public boost::totally_ordered1< Asset
141  , util::NonCopyable >
142  {
143  public:
144 
149  struct Ident
150  : boost::totally_ordered<Ident>
151  {
155  string name;
156 
161 
167  const string org;
168 
175  const uint version;
176 
177 
178  Ident (const string& n,
179  const Category& cat,
180  const string& o = "lumi",
181  const uint ver=1);
182 
183 
184  int compare (Ident const& other) const;
185 
187  bool operator== (Ident const& oi) const { return compare (oi) ==0; }
188  bool operator< (Ident const& oi) const { return compare (oi) < 0; }
189 
190  operator string () const;
191 
192  bool isValid() const;
193  };
194 
195 
196  /* ===== Asset ID and Datafields ===== */
197 
198  public:
199  const Ident ident;
200 
201  virtual const ID<Asset>& getID() const { return id; }
202 
203 
204  bool operator== (Asset const& oa) const { return ident == oa.ident; }
205  bool operator< (Asset const& oa) const { return ident < oa.ident; }
206 
207  virtual operator string () const;
208 
209 
210 
211  protected:
212  const ID<Asset> id;
213 
217  set<string> groups;
218 
220  const string shortDesc;
221 
224  const string longDesc;
225 
226  vector<PAsset> parents;
227  vector<PAsset> dependants;
228 
229  bool enabled;
230 
231 
232 
233  protected:
238  Asset (const Ident& idi);
239  virtual ~Asset() = 0;
240 
252  virtual void unlink ();
253 
256  virtual void unlink (IDA target);
257 
260  void defineDependency (PAsset parent);
261  void defineDependency (Asset& parent);
262 
263  friend class AssetManager;
264  friend class DB;
265 
266  private:
267  void unregister (PAsset& other);
268 
269 
270 
271 
272  public:
276  const vector<PAsset>& getParents () const { return parents; }
277 
282  const vector<PAsset>& getDependant () const { return dependants; }
283 
287  bool isActive () const;
288 
295  bool enable (bool on=true);
296 
297 
298  };
299 
300 
301 
302 
303  /* ====== ordering of Assets and Asset-Pointers ====== */
304 
311  inline int
313  {
314  int res;
315  if (0 != (res=category.compare (oi.category))) return res;
316  if (0 != (res=org.compare (oi.org))) return res;
317  return name.compare (oi.name);
318  }
319 
320 
322  template<class A>
323  inline const PcAsset
324  pAsset (shared_ptr<A> const& subPtr)
325  {
326  return static_pointer_cast<const Asset,A> (subPtr);
327  }
328 
329 
331  template <class X>
332  struct is_pAsset : boost::false_type {};
333 
334  template <class A>
336  : boost::is_base_of<Asset, A> {};
337 
338 
340  template<class KIND>
342 
343 
344 }} // namespace steam::asset
345 
346 
347 
348 namespace proc_interface {
349 
350  using steam::asset::Asset;
352  using steam::asset::ID;
353  using steam::asset::IDA;
354  using steam::asset::PAsset;
355 }
356 
357 #endif
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:155
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:312
Tree like classification of Assets.
Definition: category.hpp:66
const Ident ident
Asset identification tuple.
Definition: asset.hpp:199
Customised refcounting smart pointer.
Facade for the Asset subsystem.
This header is for including and configuring NoBug.
Steam-Layer implementation namespace root.
const PcAsset pAsset(shared_ptr< A > const &subPtr)
promote subtype-ptr to PAsset, e.g.
Definition: asset.hpp:324
const ID< Asset > id
Asset primary key.
Definition: asset.hpp:212
Implementation of the registry holding all Asset instances known to the Asset Manager subsystem...
Definition: db.hpp:89
Mix-Ins to allow or prohibit various degrees of copying and cloning.
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:149
const vector< PAsset > & getDependant() const
All the other assets requiring this asset to be functional.
Definition: asset.hpp:282
type trait for detecting a shared-ptr-to-asset
Definition: asset.hpp:332
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:139
set< string > groups
additional classification, selections or departments this asset belongs to.
Definition: asset.hpp:217
const string longDesc
user visible qualification of the thing, unit or concept represented by this asset.
Definition: asset.hpp:224
static ID INVALID
marker constant denoting a NIL asset
Definition: asset.hpp:107
Lumiera error handling (C++ interface).
const vector< PAsset > & getParents() const
List of entities this asset depends on or requires to be functional.
Definition: asset.hpp:276
Hash value types and utilities.
const string org
origin or authorship id.
Definition: asset.hpp:167
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:52
const string shortDesc
user visible Name-ID.
Definition: asset.hpp:220
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
const uint version
version number of the thing or concept represented by this asset.
Definition: asset.hpp:175
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:160
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35
Definition of Asset categorisation.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition: asset.hpp:99