Label.h 1.13 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 24 25 26 27

struct LabelCachePolicy
{
    typedef std::string KeyType;
    static const std::string& key( const std::shared_ptr<Label> self );
    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
{
    public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
33

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
34
        Label(sqlite3* dbConnection, sqlite3_stmt* stmt);
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
35
        Label( const std::string& name );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
36 37

    public:
38
        virtual unsigned int id() const;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
39
        virtual const std::string& name();
40
        virtual std::vector<FilePtr>& files();
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
41
        bool insert( sqlite3* dbConnection );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
42 43 44 45 46 47

        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
48 49 50
        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
51 52 53
};

#endif // LABEL_H