~ci-train-bot/media-hub/media-hub-ubuntu-yakkety-1823

« back to all changes in this revision

Viewing changes to src/com/ubuntu/music/track.cpp

  • Committer: Thomas Voß
  • Date: 2013-08-13 14:07:37 UTC
  • Revision ID: thomas.voss@canonical.com-20130813140737-ke081xhuotug54hd
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3,
 
6
 * as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 
17
 */
 
18
 
 
19
#include "com/ubuntu/music/track.h"
 
20
 
 
21
#include <map>
 
22
 
 
23
namespace music = com::ubuntu::music;
 
24
 
 
25
const music::Track::MetaData::KeyType& music::Track::MetaData::track_id_key()
 
26
{
 
27
    static const KeyType key = "test";
 
28
    return key;
 
29
}
 
30
 
 
31
struct music::Track::MetaData::Private
 
32
{
 
33
    std::map<music::Track::MetaData::KeyType, music::Track::MetaData::ValueType> lut; 
 
34
 
 
35
    bool operator==(const Private& rhs) const
 
36
    {
 
37
        return lut == rhs.lut;
 
38
    }
 
39
};
 
40
 
 
41
music::Track::MetaData::MetaData(const music::Track::MetaData& rhs) : d(new Private(*rhs.d))
 
42
{
 
43
}
 
44
 
 
45
music::Track::MetaData::~MetaData()
 
46
{
 
47
}
 
48
 
 
49
music::Track::MetaData& music::Track::MetaData::operator=(const music::Track::MetaData& rhs)
 
50
{
 
51
    *d = *rhs.d;
 
52
    return *this;
 
53
}
 
54
 
 
55
bool music::Track::MetaData::operator==(const music::Track::MetaData& rhs) const
 
56
{
 
57
    return *d == *rhs.d;
 
58
}
 
59
        
 
60
bool music::Track::MetaData::has_value_for_key(const music::Track::MetaData::KeyType& key) const
 
61
{
 
62
    return d->lut.count(key) > 0;
 
63
}
 
64
 
 
65
const music::Track::MetaData::ValueType& music::Track::MetaData::value_for_key(
 
66
    const music::Track::MetaData::KeyType& key) const
 
67
{
 
68
    return d->lut.at(key);
 
69
}
 
70
 
 
71
void music::Track::MetaData::for_each(
 
72
    const std::function<void(const music::Track::MetaData::KeyType&, const music::Track::MetaData::ValueType&)>& f)
 
73
{
 
74
    for (auto p : d->lut)
 
75
    {
 
76
        f(p.first, p.second);
 
77
    }
 
78
}
 
79
 
 
80
music::Track::MetaData::MetaData() : d(new Private())
 
81
{
 
82
}
 
83
        
 
84
struct music::Track::Private
 
85
{
 
86
    Private(const MetaData& meta_data,
 
87
            const Track::UriType& uri) : meta_data(meta_data),
 
88
                                         uri(uri)
 
89
    {
 
90
    }
 
91
 
 
92
    bool operator==(const Private& rhs) const
 
93
    {
 
94
        return
 
95
                meta_data == rhs.meta_data &&
 
96
                uri == rhs.uri;
 
97
    }
 
98
 
 
99
    MetaData meta_data;
 
100
    Track::UriType uri;
 
101
};
 
102
 
 
103
music::Track::Track(const music::Track& rhs) : d(new Private(*rhs.d))
 
104
{
 
105
}
 
106
 
 
107
music::Track::~Track()
 
108
{
 
109
}
 
110
 
 
111
music::Track& music::Track::operator=(const music::Track& rhs)
 
112
{
 
113
    *d = *rhs.d;
 
114
    return *this;
 
115
}
 
116
 
 
117
bool music::Track::operator==(const music::Track& rhs) const
 
118
{
 
119
    return *d == *rhs.d;
 
120
}
 
121
 
 
122
const music::Track::UriType& music::Track::uri() const
 
123
{
 
124
    return d->uri;
 
125
}
 
126
 
 
127
const music::Track::MetaData& music::Track::meta_data() const
 
128
{
 
129
    return d->meta_data;
 
130
}
 
131
 
 
132
music::Connection music::Track::on_meta_data_changed(const std::function<void(const music::Track::MetaData&)>& f)
 
133
{
 
134
    (void) f;
 
135
    return Connection(nullptr);
 
136
}
 
137
    
 
138
music::Track::Track(const music::Track::UriType& uri, const music::Track::MetaData& meta_data) : d(new Private(meta_data, uri))
 
139
{
 
140
}