Metadata.h 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015-2018 Hugo Beauzée-Luyssen, Videolabs, VideoLAN
 *
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#pragma once

#include "medialibrary/IMetadata.h"
#include "medialibrary/IMedia.h"
#include "Types.h"

namespace medialibrary
{

namespace sqlite
{
class Connection;
}

37
class Metadata
38 39
{
public:
40 41 42 43
    struct Table
    {
        static const std::string Name;
    };
44
    Metadata( MediaLibraryPtr ml, IMetadata::EntityType entityType );
45 46 47 48 49 50 51

    // We have to "lazy init" this object since during containing object creation,
    // we might not know the ID yet (for instance. when instantiating the
    // metadata object during the creation of a new Media)
    void init( int64_t entityId, uint32_t nbMeta );
    bool isReady() const;

52 53 54
    IMetadata& get( uint32_t type ) const;
    bool set( uint32_t type, const std::string& value );
    bool set( uint32_t type, int64_t value );
55
    bool unset( uint32_t type );
56 57

    static void unset( sqlite::Connection* dbConn, IMetadata::EntityType entityType, uint32_t type );
58 59 60 61

    static void createTable( sqlite::Connection* connection );

private:
62
    class Record : public IMetadata
63 64 65
    {
    public:
        virtual ~Record() = default;
66 67
        Record( uint32_t t, std::string v );
        Record( uint32_t t );
68 69 70
        virtual bool isSet() const override;
        virtual int64_t integer() const override;
        virtual const std::string& str() const override;
71
        void unset();
72 73 74
        void set( const std::string& value );

    private:
75
        const uint32_t m_type;
76 77 78
        std::string m_value;
        bool m_isSet;

79
        friend Metadata;
80 81 82 83
    };

private:
    MediaLibraryPtr m_ml;
84
    IMetadata::EntityType m_entityType;
85 86 87 88 89 90
    uint32_t m_nbMeta;
    int64_t m_entityId;
    mutable std::vector<Record> m_records;
};

}