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

« back to all changes in this revision

Viewing changes to src/tag/TagBuilder.hxx

  • 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
#ifndef MPD_TAG_BUILDER_HXX
 
21
#define MPD_TAG_BUILDER_HXX
 
22
 
 
23
#include "TagType.h"
 
24
#include "Compiler.h"
 
25
 
 
26
#include <vector>
 
27
 
 
28
#include <stddef.h>
 
29
 
 
30
struct TagItem;
 
31
struct Tag;
 
32
 
 
33
/**
 
34
 * A class that constructs #Tag objects.
 
35
 */
 
36
class TagBuilder {
 
37
        /**
 
38
         * The duration of the song (in seconds).  A value of zero
 
39
         * means that the length is unknown.  If the duration is
 
40
         * really between zero and one second, you should round up to
 
41
         * 1.
 
42
         */
 
43
        int time;
 
44
 
 
45
        /**
 
46
         * Does this file have an embedded playlist (e.g. embedded CUE
 
47
         * sheet)?
 
48
         */
 
49
        bool has_playlist;
 
50
 
 
51
        /** an array of tag items */
 
52
        std::vector<TagItem *> items;
 
53
 
 
54
public:
 
55
        /**
 
56
         * Create an empty tag.
 
57
         */
 
58
        TagBuilder()
 
59
                :time(-1), has_playlist(false) {}
 
60
 
 
61
        ~TagBuilder() {
 
62
                Clear();
 
63
        }
 
64
 
 
65
        TagBuilder(const TagBuilder &other) = delete;
 
66
        TagBuilder &operator=(const TagBuilder &other) = delete;
 
67
 
 
68
        /**
 
69
         * Returns true if the tag contains no items.  This ignores the "time"
 
70
         * attribute.
 
71
         */
 
72
        bool IsEmpty() const {
 
73
                return items.empty();
 
74
        }
 
75
 
 
76
        /**
 
77
         * Returns true if the object contains any information.
 
78
         */
 
79
        gcc_pure
 
80
        bool IsDefined() const {
 
81
                return time >= 0 || has_playlist || !IsEmpty();
 
82
        }
 
83
 
 
84
        void Clear();
 
85
 
 
86
        /**
 
87
         * Move this object to the given #Tag instance.  This object
 
88
         * is empty afterwards.
 
89
         */
 
90
        void Commit(Tag &tag);
 
91
 
 
92
        /**
 
93
         * Create a new #Tag instance from data in this object.  The
 
94
         * returned object is owned by the caller.  This object is
 
95
         * empty afterwards.
 
96
         */
 
97
        Tag *Commit();
 
98
 
 
99
        void SetTime(int _time) {
 
100
                time = _time;
 
101
        }
 
102
 
 
103
        void SetHasPlaylist(bool _has_playlist) {
 
104
                has_playlist = _has_playlist;
 
105
        }
 
106
 
 
107
        void Reserve(unsigned n) {
 
108
                items.reserve(n);
 
109
        }
 
110
 
 
111
        /**
 
112
         * Appends a new tag item.
 
113
         *
 
114
         * @param type the type of the new tag item
 
115
         * @param value the value of the tag item (not null-terminated)
 
116
         * @param len the length of #value
 
117
         */
 
118
        gcc_nonnull_all
 
119
        void AddItem(TagType type, const char *value, size_t length);
 
120
 
 
121
        /**
 
122
         * Appends a new tag item.
 
123
         *
 
124
         * @param type the type of the new tag item
 
125
         * @param value the value of the tag item (null-terminated)
 
126
         */
 
127
        gcc_nonnull_all
 
128
        void AddItem(TagType type, const char *value);
 
129
 
 
130
private:
 
131
        gcc_nonnull_all
 
132
        void AddItemInternal(TagType type, const char *value, size_t length);
 
133
};
 
134
 
 
135
#endif