2007-09-02 18:48:22 +02:00
|
|
|
/*
|
|
|
|
|
CATEGORY.hpp - tree like classification of Assets
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-03-10 04:25:03 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
#ifndef PROC_ASSET_CATEGORY_H
|
|
|
|
|
#define PROC_ASSET_CATEGORY_H
|
2007-09-02 18:48:22 +02:00
|
|
|
|
2009-09-24 23:02:40 +02:00
|
|
|
#include "lib/symbol.hpp"
|
2014-08-17 08:03:21 +02:00
|
|
|
#include "lib/hash-standard.hpp"
|
2009-09-24 23:02:40 +02:00
|
|
|
|
2007-09-07 23:24:13 +02:00
|
|
|
#include <string>
|
|
|
|
|
#include <boost/functional/hash.hpp>
|
|
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
namespace proc {
|
2009-05-24 05:14:11 +02:00
|
|
|
namespace asset {
|
2010-03-29 03:27:47 +02:00
|
|
|
|
2009-09-24 23:02:40 +02:00
|
|
|
using lib::Literal;
|
2009-05-24 05:14:11 +02:00
|
|
|
|
2007-09-07 23:24:13 +02:00
|
|
|
using std::string;
|
|
|
|
|
using std::ostream;
|
|
|
|
|
|
2010-03-29 03:27:47 +02:00
|
|
|
/**
|
2009-05-24 05:14:11 +02:00
|
|
|
* top-level distinction of different Kinds of Assets.
|
|
|
|
|
* For convenience, this classification is slightly denormalised,
|
|
|
|
|
* as AUDIO, and VIDEO are both asset::Media objects, EFFECT and CODEC
|
|
|
|
|
* are asset::Proc objects, while STRUCT and META refer directly to
|
|
|
|
|
* the corresponding Interfaces asset::Struct and asset::Meta.
|
|
|
|
|
*/
|
|
|
|
|
enum Kind
|
|
|
|
|
{ AUDIO
|
|
|
|
|
, VIDEO
|
|
|
|
|
, EFFECT
|
|
|
|
|
, CODEC
|
|
|
|
|
, STRUCT
|
|
|
|
|
, META
|
|
|
|
|
};
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
/************************************************************************************//**
|
2007-09-07 23:24:13 +02:00
|
|
|
* Tree like classification of Assets.
|
2009-05-24 05:14:11 +02:00
|
|
|
* By virtue of the Category, Assets can be organised in nested bins (folders).
|
2007-09-07 23:24:13 +02:00
|
|
|
* This includes the distinction of different kinds of Assets, like Audio, Video, Effects...
|
|
|
|
|
*
|
2009-05-24 05:14:11 +02:00
|
|
|
* @todo could be far more elaborate. could be a singleton like centralised tree, while
|
|
|
|
|
* just holding references to Category nodes in the individual Asset. At the moment,
|
|
|
|
|
* we just use the most simplistic implementation and handle Category objects
|
2007-09-07 23:24:13 +02:00
|
|
|
* using value semantics.
|
2007-09-02 18:48:22 +02:00
|
|
|
*/
|
|
|
|
|
class Category
|
2007-09-07 23:24:13 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Kind kind_;
|
|
|
|
|
string path_;
|
|
|
|
|
|
|
|
|
|
public:
|
2009-09-24 23:02:40 +02:00
|
|
|
Category (const Kind root, Literal subfolder ="")
|
2007-09-07 23:24:13 +02:00
|
|
|
: kind_(root), path_(subfolder) {};
|
|
|
|
|
|
2009-05-24 05:14:11 +02:00
|
|
|
bool operator== (Category const& other) const { return kind_== other.kind_ && path_== other.path_; }
|
|
|
|
|
bool operator!= (Category const& other) const { return kind_!= other.kind_ || path_!= other.path_; }
|
|
|
|
|
|
|
|
|
|
bool hasKind (Kind refKind) const { return kind_ == refKind; }
|
|
|
|
|
bool isWithin (Category const&) const;
|
|
|
|
|
void setPath (string const& newpath) { this->path_ = newpath; }
|
2007-09-10 06:45:36 +02:00
|
|
|
|
2007-09-07 23:24:13 +02:00
|
|
|
|
|
|
|
|
operator string () const;
|
2009-05-24 05:14:11 +02:00
|
|
|
|
2010-03-29 03:27:47 +02:00
|
|
|
friend size_t hash_value (Category const&);
|
2009-05-24 05:14:11 +02:00
|
|
|
|
2007-09-17 05:47:22 +02:00
|
|
|
|
2009-05-24 05:14:11 +02:00
|
|
|
int
|
|
|
|
|
compare (Category const& co) const
|
2007-09-17 05:47:22 +02:00
|
|
|
{
|
|
|
|
|
int res = int(kind_) - int(co.kind_);
|
2007-09-19 03:55:45 +02:00
|
|
|
if (0 != res)
|
2007-09-17 05:47:22 +02:00
|
|
|
return res;
|
|
|
|
|
else
|
|
|
|
|
return path_.compare (co.path_);
|
|
|
|
|
}
|
2009-05-24 05:14:11 +02:00
|
|
|
|
2007-09-07 23:24:13 +02:00
|
|
|
};
|
2009-05-24 05:14:11 +02:00
|
|
|
|
2010-03-29 03:27:47 +02:00
|
|
|
|
|
|
|
|
inline size_t
|
|
|
|
|
hash_value (Category const& cat)
|
|
|
|
|
{
|
|
|
|
|
size_t hash = 0;
|
|
|
|
|
boost::hash_combine(hash, cat.kind_);
|
|
|
|
|
boost::hash_combine(hash, cat.path_);
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
2009-05-24 05:14:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
}} // namespace proc::asset
|
2007-09-02 18:48:22 +02:00
|
|
|
#endif
|