Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
asset.cpp
Go to the documentation of this file.
1 /*
2  Asset - 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 
23 
29 #include "proc/asset.hpp"
30 #include "proc/assetmanager.hpp"
31 #include "lib/format-string.hpp"
32 #include "lib/util-foreach.hpp"
33 #include "lib/util.hpp"
34 
35 #include <functional>
36 #include <string>
37 
38 
39 using std::function;
40 using std::placeholders::_1;
41 using std::bind;
42 using util::contains;
43 using util::removeall;
44 using util::for_each;
45 using util::and_all;
46 using util::isnil;
47 using util::cStr;
48 using util::_Fmt;
49 
50 
51 namespace proc {
52 namespace asset {
53 
54 
55 
56  Asset::Ident::Ident(const string& n, const Category& cat, const string& o, const uint ver)
57  : name(util::sanitise (n))
58  , category(cat)
59  , org(o)
60  , version(ver)
61  { }
62 
63 
67  Asset::Asset (Ident const& idi)
68  : ident(idi)
69  , id(AssetManager::reg (this, idi))
70  , enabled(true)
71  {
72  TRACE (asset_mem, "ctor Asset(id=%zu) : adr=%p %s", size_t(id), this, cStr(this->ident) );
73  }
74 
76  {
77  TRACE (asset_mem, "dtor Asset(id=%zu) : adr=%p", size_t(id), this );
78  }
79 
80 
81  Asset::Ident::operator string () const
82  {
83  return string (_Fmt("(%2%:%3%.%1% v%4%)")
84  % name
85  % category
86  % org
87  % version);
88  }
89 
90 
91  Asset::operator string () const
92  {
93  return string (_Fmt("Asset(%2%:%3%.%1% v%4%)")
94  % ident.name
95  % ident.category
96  % ident.org
97  % ident.version);
98  }
99 
100 
101  bool
103  {
104  return not isnil (name)
105  and not isnil (org)
106  and version <= 1000000;
107  }
108 
109 
110 
111 
112  function<bool(const PAsset&)> check_isActive
113  = bind ( &Asset::isActive
114  , bind (&PAsset::get, _1 )
115  );
116 
117  bool
118  all_parents_enabled (const vector<PAsset>& parents)
119  {
120  return and_all (parents, check_isActive);
121  }
122 
127  bool
129  {
130  return this->enabled
132  }
133 
134 
135  void
136  propagate_down (PAsset child, bool on)
137  {
138  child->enable(on);
139  }
140 
142  bool
144  {
145  if (on == this->enabled)
146  return true;
147  if (on and not all_parents_enabled (parents))
148  return false;
149 
150  // can indeed to do the toggle...
151  this->enabled = on;
152  for_each (dependants, &propagate_down, _1 ,on);
153  return true;
154  }
155 
156 
157 
158 
159  void
161  {
162  other->unlink (this->id);
163  }
164 
173  void
175  {
176  function<void(PAsset&)> forget_me = bind(&Asset::unregister, this, _1);
177 
178  for_each (parents, forget_me);
179  dependants.clear();
180  }
181 
183  void
185  {
186  PAsset asset (AssetManager::instance().getAsset (target));
187  removeall (dependants,asset);
188  removeall (parents,asset);
189  }
190 
191 
192  void
194  {
195  PAsset p_this (AssetManager::wrap(*this));
196  REQUIRE (!contains (parent->dependants, p_this));
197  REQUIRE (!contains (this->parents, parent));
198  parents.push_back (parent);
199  parent->dependants.push_back(p_this);
200  }
201 
202  void
204  {
205  PAsset p_parent (AssetManager::wrap(parent));
206  ASSERT (p_parent);
207  defineDependency (p_parent);
208  }
209 
210 
211 }} // namespace proc::asset
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
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:162
function< bool(const PAsset &)> check_isActive
Definition: asset.cpp:113
Proc-Layer Interface: Asset Lookup and Organisation.
bool isActive() const
weather this asset is switched on and consequently included in the fixture and participates in render...
Definition: asset.cpp:128
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
static lib::P< KIND > wrap(const KIND &asset)
retrieve the registered smart-ptr for any asset
The asset subsystem of the Proc-Layer.
Definition: id-scheme.hpp:64
Front-end for printf-style string template interpolation.
const Ident ident
Asset identification tuple.
Definition: asset.hpp:206
A front-end for using printf-style formatting.
bool all_parents_enabled(const vector< PAsset > &parents)
Definition: asset.cpp:118
const ID< Asset > id
Asset primary key.
Definition: asset.hpp:219
const char * cStr(string const &org)
convenience shortcut: conversion to c-String via string.
Definition: util.hpp:380
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
TRACE(test,"inserted %d", data)
SEQ::iterator removeall(SEQ &coll, typename SEQ::value_type &val)
shortcut for removing all copies of an Element in any sequential collection
Definition: util.hpp:272
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:156
Derived specific exceptions within Lumiera's exception hierarchy.
Definition: error.hpp:196
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
bool enable(bool on=true)
change the enabled status of this asset.
Definition: asset.cpp:143
void propagate_down(PAsset child, bool on)
Definition: asset.cpp:136
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition: util.hpp:205
bool isValid() const
Definition: asset.cpp:102
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
vector< PAsset > parents
Definition: asset.hpp:233
Proc-Layer Interface: Assets.
Tree like classification of Assets.
Definition: category.hpp:75
bool and_all(IT i, IT end, FUN predicate)
All quantification: check if all elements of a collection satisfy the given predicate.
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
string sanitise(string const &org)
produce an identifier based on the given string.
Definition: util.cpp:57
virtual ~Asset()=0
Definition: asset.cpp:75
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
TAR * get() const
Definition: p.hpp:96
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
Perform operations "for each element" of a collection.
const string org
origin or authorship id.
Definition: asset.hpp:174
vector< PAsset > dependants
Definition: asset.hpp:234