Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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)
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
14
20#include "steam/asset.hpp"
22#include "lib/format-string.hpp"
23#include "lib/util-foreach.hpp"
24#include "lib/util.hpp"
25
26#include <functional>
27#include <string>
28
29
30using std::function;
31using std::placeholders::_1;
32using std::bind;
33using util::contains;
34using util::removeall;
35using util::for_each;
36using util::and_all;
37using util::isnil;
38using util::_Fmt;
39
40
41namespace steam {
42namespace asset {
43
44
45
46 Asset::Ident::Ident(const string& n, const Category& cat, const string& o, const uint ver)
47 : name(util::sanitise (n))
48 , category(cat)
49 , org(o)
50 , version(ver)
51 { }
52
53
57 Asset::Asset (Ident const& idi)
58 : ident(idi)
59 , id(AssetManager::reg (this, idi))
60 , enabled(true)
61 {
62 TRACE (asset_mem, "ctor Asset(id=%zu) : adr=%p %s", size_t(id), this, cStr(this->ident) );
63 }
64
66 {
67 TRACE (asset_mem, "dtor Asset(id=%zu) : adr=%p", size_t(id), this );
68 }
69
70
71 Asset::Ident::operator string () const
72 {
73 return string (_Fmt("(%2%:%3%.%1% v%4%)")
74 % name
75 % category
76 % org
77 % version);
78 }
79
80
81 Asset::operator string () const
82 {
83 return string (_Fmt("Asset(%2%:%3%.%1% v%4%)")
84 % ident.name
85 % ident.category
86 % ident.org
87 % ident.version);
88 }
89
90
91 bool
93 {
94 return not isnil (name)
95 and not isnil (org)
96 and version <= 1000000;
97 }
98
99
100
101
102 function<bool(const PAsset&)> check_isActive
103 = bind ( &Asset::isActive
104 , bind (&PAsset::get, _1 )
105 );
106
107 bool
108 all_parents_enabled (const vector<PAsset>& parents)
109 {
110 return and_all (parents, check_isActive);
111 }
112
117 bool
119 {
120 return this->enabled
122 }
123
124
125 void
126 propagate_down (PAsset child, bool on)
127 {
128 child->enable(on);
129 }
130
132 bool
134 {
135 if (on == this->enabled)
136 return true;
137 if (on and not all_parents_enabled (parents))
138 return false;
139
140 // can indeed to do the toggle...
141 this->enabled = on;
142 for_each (dependants, &propagate_down, _1 ,on);
143 return true;
144 }
145
146
147
148
149 void
151 {
152 other->unlink (this->id);
153 }
154
163 void
165 {
166 function<void(PAsset&)> forget_me = bind(&Asset::unregister, this, _1);
167
168 for_each (parents, forget_me);
169 dependants.clear();
170 }
171
173 void
175 {
176 PAsset asset (AssetManager::instance().getAsset (target));
177 removeall (dependants,asset);
178 removeall (parents,asset);
179 }
180
181
182 void
184 {
185 PAsset p_this (AssetManager::wrap(*this));
186 REQUIRE (!contains (parent->dependants, p_this));
187 REQUIRE (!contains (this->parents, parent));
188 parents.push_back (parent);
189 parent->dependants.push_back(p_this);
190 }
191
192 void
194 {
195 PAsset p_parent (AssetManager::wrap(parent));
196 ASSERT (p_parent);
197 defineDependency (p_parent);
198 }
199
200
201}} // namespace steam::asset
Steam-Layer Interface: Assets.
Steam-Layer Interface: Asset Lookup and Organisation.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
TAR * get() const
Definition p.hpp:94
Facade for the Asset subsystem.
static lib::P< KIND > wrap(const KIND &asset)
retrieve the registered smart-ptr for any asset
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
Superinterface describing especially bookkeeping properties.
Definition asset.hpp:139
const Ident ident
Asset identification tuple.
Definition asset.hpp:197
void defineDependency(PAsset parent)
establish a connection between this and the given parent asset, denoting we are in some way dependent...
Definition asset.cpp:183
vector< PAsset > parents
Definition asset.hpp:224
void unregister(PAsset &other)
Definition asset.cpp:150
bool isActive() const
weather this asset is switched on and consequently included in the fixture and participates in render...
Definition asset.cpp:118
bool enable(bool on=true)
change the enabled status of this asset.
Definition asset.cpp:133
vector< PAsset > dependants
Definition asset.hpp:225
const ID< Asset > id
Asset primary key.
Definition asset.hpp:210
virtual ~Asset()=0
Definition asset.cpp:65
virtual void unlink()
release all links to other Asset objects held internally.
Definition asset.cpp:164
Asset(const Ident &idi)
Asset is a Interface class; usually, objects of concrete subclasses are created via specialised Facto...
Definition asset.cpp:57
Tree like classification of Assets.
Definition category.hpp:68
A front-end for using printf-style formatting.
Front-end for printf-style string template interpolation.
unsigned int uint
Definition integral.hpp:29
The asset subsystem of the Steam-Layer.
bool all_parents_enabled(const vector< PAsset > &parents)
Definition asset.cpp:108
void propagate_down(PAsset child, bool on)
Definition asset.cpp:126
function< bool(const PAsset &)> check_isActive
Definition asset.cpp:103
Steam-Layer implementation namespace root.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
bool and_all(IT i, IT end, FUN predicate)
All quantification: check if all elements of a collection satisfy the given predicate.
SEQ::iterator removeall(SEQ &coll, typename SEQ::value_type const &val)
shortcut for removing all copies of an Element in any sequential collection
Definition util.hpp:306
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
bool isnil(lib::time::Duration const &dur)
a POD comprised of all the information sufficiently identifying any given Asset.
Definition asset.hpp:147
string name
element ID, comprehensible but sanitised.
Definition asset.hpp:151
const uint version
version number of the thing or concept represented by this asset.
Definition asset.hpp:171
const string org
origin or authorship id.
Definition asset.hpp:163
Ident(string const &n, Category const &cat, string const &o="lumi", const uint ver=1)
Definition asset.cpp:46
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition symbol.hpp:60
Perform operations "for each element" of a collection.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...