Label.h 1.26 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 19
#include "ILabel.h"
#include "Cache.h"

namespace policy
{
struct LabelTable
{
    static const std::string Name;
    static const std::string CacheColumn;
};
20 21 22 23

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

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

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

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

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

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

#endif // LABEL_H