Lumiera  0.pre.03
»edit your freedom«
category.hpp
Go to the documentation of this file.
1 /*
2  CATEGORY.hpp - tree like classification of Assets
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 #ifndef STEAM_ASSET_CATEGORY_H
30 #define STEAM_ASSET_CATEGORY_H
31 
32 #include "lib/symbol.hpp"
33 #include "lib/hash-standard.hpp"
34 
35 #include <string>
36 #include <boost/functional/hash.hpp>
37 
38 
39 
40 namespace steam {
41 namespace asset {
42 
43  using lib::Literal;
44 
45  using std::string;
46  using std::ostream;
47 
55  enum Kind
56  { AUDIO
57  , VIDEO
58  , EFFECT
59  , CODEC
60  , STRUCT
61  , META
62  };
63 
64  /************************************************************************************/
75  class Category
76  {
77 
78  Kind kind_;
79  string path_;
80 
81  public:
82  Category (const Kind root, Literal subfolder ="")
83  : kind_(root), path_(subfolder) {};
84 
85  bool operator== (Category const& other) const { return kind_== other.kind_ && path_== other.path_; }
86  bool operator!= (Category const& other) const { return kind_!= other.kind_ || path_!= other.path_; }
87 
88  bool hasKind (Kind refKind) const { return kind_ == refKind; }
89  bool isWithin (Category const&) const;
90  void setPath (string const& newpath) { this->path_ = newpath; }
91 
92 
93  operator string () const;
94 
95  friend size_t hash_value (Category const&);
96 
97 
98  int
99  compare (Category const& co) const
100  {
101  int res = int(kind_) - int(co.kind_);
102  if (0 != res)
103  return res;
104  else
105  return path_.compare (co.path_);
106  }
107 
108  };
109 
110 
111  inline size_t
112  hash_value (Category const& cat)
113  {
114  size_t hash = 0;
115  boost::hash_combine(hash, cat.kind_);
116  boost::hash_combine(hash, cat.path_);
117  return hash;
118  }
119 
120 
121 
122 }} // namespace steam::asset
123 #endif
bool isWithin(Category const &) const
hierarchical inclusion test.
Definition: category.cpp:69
Tree like classification of Assets.
Definition: category.hpp:75
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Steam-Layer implementation namespace root.
Marker types to indicate a literal string and a Symbol.
Helper to use a single extension point for specialised hash functions.
Kind
top-level distinction of different Kinds of Assets.
Definition: category.hpp:55
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:44