Label.h 1.33 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1 2 3 4 5 6
#ifndef LABEL_H
#define LABEL_H

#include <sqlite3.h>
#include <string>

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
7
class File;
8
class Label;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
9

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
10 11 12 13 14 15 16 17 18
#include "ILabel.h"
#include "Cache.h"

namespace policy
{
struct LabelTable
{
    static const std::string Name;
    static const std::string CacheColumn;
19
    static unsigned int Label::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
20
};
21 22 23 24

struct LabelCachePolicy
{
    typedef std::string KeyType;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
25
    static const std::string& key(const std::shared_ptr<ILabel> self );
26 27 28
    static std::string key( sqlite3_stmt* stmt );
};

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
29 30
}

31
class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, policy::LabelCachePolicy>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
32
{
33 34
    private:
        typedef Cache<Label, ILabel, policy::LabelTable, policy::LabelCachePolicy> _Cache;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
35
    public:
36
        Label( DBConnection dbConnection, sqlite3_stmt* stmt);
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
37
        Label( const std::string& name );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
38 39

    public:
40
        virtual unsigned int id() const;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
41
        virtual const std::string& name();
42
        virtual bool files( std::vector<FilePtr>& files );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
43

44 45
        static LabelPtr create( DBConnection dbConnection, const std::string& name );
        static bool createTable( DBConnection dbConnection );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
46
    private:
47
        DBConnection m_dbConnection;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
48 49
        unsigned int m_id;
        std::string m_name;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
50 51

        friend class Cache<Label, ILabel, policy::LabelTable>;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
52
        friend struct policy::LabelTable;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
53 54 55
};

#endif // LABEL_H