Lumiera  0.pre.03
»edityourfreedom«
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 
107  template<class KIND>
108  class ID
109  {
111  public:
112  ID (HashVal id) : hash_(id) {}
113  ID (const KIND& asset) : hash_(asset.getID()) {}
114  operator HashVal() const { return hash_; }
115 
116  static ID INVALID;
117  };
118 
119  class DB;
120  class Asset;
122  typedef const ID<Asset>& IDA;
125 
126 
127 
128 
129 
148  class Asset
149  : public boost::totally_ordered1< Asset
150  , util::NonCopyable >
151  {
152  public:
153 
158  struct Ident
159  : boost::totally_ordered<Ident>
160  {
164  string name;
165 
170 
176  const string org;
177 
184  const uint version;
185 
186 
187  Ident (const string& n,
188  const Category& cat,
189  const string& o = "lumi",
190  const uint ver=1);
191 
192 
193  int compare (Ident const& other) const;
194 
196  bool operator== (Ident const& oi) const { return compare (oi) ==0; }
197  bool operator< (Ident const& oi) const { return compare (oi) < 0; }
198 
199  operator string () const;
200 
201  bool isValid() const;
202  };
203 
204 
205  /* ===== Asset ID and Datafields ===== */
206 
207  public:
208  const Ident ident;
209 
210  virtual const ID<Asset>& getID() const { return id; }
211 
212 
213  bool operator== (Asset const& oa) const { return ident == oa.ident; }
214  bool operator< (Asset const& oa) const { return ident < oa.ident; }
215 
216  virtual operator string () const;
217 
218 
219 
220  protected:
221  const ID<Asset> id;
222 
226  set<string> groups;
227 
229  const string shortDesc;
230 
233  const string longDesc;
234 
235  vector<PAsset> parents;
236  vector<PAsset> dependants;
237 
238  bool enabled;
239 
240 
241 
242  protected:
247  Asset (const Ident& idi);
248  virtual ~Asset() = 0;
249 
261  virtual void unlink ();
262 
265  virtual void unlink (IDA target);
266 
269  void defineDependency (PAsset parent);
270  void defineDependency (Asset& parent);
271 
272  friend class AssetManager;
273  friend class DB;
274 
275  private:
276  void unregister (PAsset& other);
277 
278 
279 
280 
281  public:
285  const vector<PAsset>& getParents () const { return parents; }
286 
291  const vector<PAsset>& getDependant () const { return dependants; }
292 
296  bool isActive () const;
297 
304  bool enable (bool on=true);
305 
306 
307  };
308 
309 
310 
311 
312  /* ====== ordering of Assets and Asset-Pointers ====== */
313 
320  inline int
322  {
323  int res;
324  if (0 != (res=category.compare (oi.category))) return res;
325  if (0 != (res=org.compare (oi.org))) return res;
326  return name.compare (oi.name);
327  }
328 
329 
331  template<class A>
332  inline const PcAsset
333  pAsset (shared_ptr<A> const& subPtr)
334  {
335  return static_pointer_cast<const Asset,A> (subPtr);
336  }
337 
338 
340  template <class X>
341  struct is_pAsset : boost::false_type {};
342 
343  template <class A>
345  : boost::is_base_of<Asset, A> {};
346 
347 
349  template<class KIND>
351 
352 
353 }} // namespace proc::asset
354 
355 
356 
357 namespace proc_interface {
358 
359  using proc::asset::Asset;
360  using proc::asset::Category;
361  using proc::asset::ID;
362  using proc::asset::IDA;
363  using proc::asset::PAsset;
364 }
365 
366 #endif
ID(HashVal id)
Definition: asset.hpp:112
virtual const ID< Asset > & getID() const
Definition: asset.hpp:210
const uint version
version number of the thing or concept represented by this asset.
Definition: asset.hpp:184
type trait for detecting a shared-ptr-to-asset
Definition: asset.hpp:341
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:164
const PcAsset pAsset(shared_ptr< A > const &subPtr)
promote subtype-ptr to PAsset, e.g.
Definition: asset.hpp:333
ChPredicate isValid(is_alnum() or is_any_of("-_.+$'()@"))
characters to be retained
const string shortDesc
user visible Name-ID.
Definition: asset.hpp:229
Facade for the Asset subsystem.
The asset subsystem of the Proc-Layer.
Definition: id-scheme.hpp:64
lib::P< const Asset > PcAsset
Definition: asset.hpp:124
const string longDesc
user visible qualification of the thing, unit or concept represented by this asset.
Definition: asset.hpp:233
static ID INVALID
marker constant denoting a NIL asset
Definition: asset.hpp:116
Customised refcounting smart pointer.
This header is for including and configuring NoBug.
const Ident ident
Asset identification tuple.
Definition: asset.hpp:208
const ID< Asset > id
Asset primary key.
Definition: asset.hpp:221
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:169
const vector< PAsset > & getParents() const
List of entities this asset depends on or requires to be functional.
Definition: asset.hpp:285
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:148
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:158
Mix-Ins to allow or prohibit various degrees of copying and cloning.
lib::P< Asset > PAsset
Definition: asset.hpp:123
const ID< Asset > & IDA
Definition: asset.hpp:121
bool operator==(Job const &left, Job const &right)
Definition: job.h:292
vector< PAsset > parents
Definition: asset.hpp:235
Tree like classification of Assets.
Definition: category.hpp:75
const vector< PAsset > & getDependant() const
All the other assets requiring this asset to be functional.
Definition: asset.hpp:291
bool operator<(Goal::QueryID const &id1, Goal::QueryID const &id2)
Definition: query.hpp:198
HashVal hash_
Definition: asset.hpp:110
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:108
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
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:321
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
set< string > groups
additional classification, selections or departments this asset belongs to.
Definition: asset.hpp:226
Definition of Asset categorisation.
const string org
origin or authorship id.
Definition: asset.hpp:176
Implementation of the registry holding all Asset instances known to the Asset Manager subsystem...
Definition: db.hpp:98
vector< PAsset > dependants
Definition: asset.hpp:236
lib::idi::BareEntryID const & ID
Definition: id-scheme.hpp:87
ID(const KIND &asset)
Definition: asset.hpp:113