~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/tag/TagBuilder.cxx

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include "TagBuilder.hxx"
 
22
#include "TagSettings.h"
 
23
#include "TagPool.hxx"
 
24
#include "TagString.hxx"
 
25
#include "Tag.hxx"
 
26
 
 
27
#include <glib.h>
 
28
 
 
29
#include <assert.h>
 
30
#include <string.h>
 
31
 
 
32
void
 
33
TagBuilder::Clear()
 
34
{
 
35
        time = -1;
 
36
        has_playlist = false;
 
37
 
 
38
        tag_pool_lock.lock();
 
39
        for (auto i : items)
 
40
                tag_pool_put_item(i);
 
41
        tag_pool_lock.unlock();
 
42
 
 
43
        items.clear();
 
44
}
 
45
 
 
46
void
 
47
TagBuilder::Commit(Tag &tag)
 
48
{
 
49
        tag.Clear();
 
50
 
 
51
        tag.time = time;
 
52
        tag.has_playlist = has_playlist;
 
53
 
 
54
        /* move all TagItem pointers to the new Tag object without
 
55
           touching the TagPool reference counters; the
 
56
           vector::clear() call is important to detach them from this
 
57
           object */
 
58
        const unsigned n_items = items.size();
 
59
        tag.num_items = n_items;
 
60
        tag.items = g_new(TagItem *, n_items);
 
61
        std::copy_n(items.begin(), n_items, tag.items);
 
62
        items.clear();
 
63
 
 
64
        /* now ensure that this object is fresh (will not delete any
 
65
           items because we've already moved them out) */
 
66
        Clear();
 
67
}
 
68
 
 
69
Tag *
 
70
TagBuilder::Commit()
 
71
{
 
72
        Tag *tag = new Tag();
 
73
        Commit(*tag);
 
74
        return tag;
 
75
}
 
76
 
 
77
inline void
 
78
TagBuilder::AddItemInternal(TagType type, const char *value, size_t length)
 
79
{
 
80
        assert(value != nullptr);
 
81
        assert(length > 0);
 
82
 
 
83
        char *p = FixTagString(value, length);
 
84
        if (p != nullptr) {
 
85
                value = p;
 
86
                length = strlen(value);
 
87
        }
 
88
 
 
89
        tag_pool_lock.lock();
 
90
        auto i = tag_pool_get_item(type, value, length);
 
91
        tag_pool_lock.unlock();
 
92
 
 
93
        g_free(p);
 
94
 
 
95
        items.push_back(i);
 
96
}
 
97
 
 
98
void
 
99
TagBuilder::AddItem(TagType type, const char *value, size_t length)
 
100
{
 
101
        assert(value != nullptr);
 
102
 
 
103
        if (length == 0 || ignore_tag_items[type])
 
104
                return;
 
105
 
 
106
        AddItemInternal(type, value, length);
 
107
}
 
108
 
 
109
void
 
110
TagBuilder::AddItem(TagType type, const char *value)
 
111
{
 
112
        assert(value != nullptr);
 
113
 
 
114
        AddItem(type, value, strlen(value));
 
115
}