~ubuntu-branches/debian/sid/libmusicbrainz5/sid

« back to all changes in this revision

Viewing changes to src/Medium.cc

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-06-01 19:17:52 UTC
  • Revision ID: package-import@ubuntu.com-20120601191752-kqnn25aopdlc4drf
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* --------------------------------------------------------------------------
 
2
 
 
3
   libmusicbrainz5 - Client library to access MusicBrainz
 
4
 
 
5
   Copyright (C) 2012 Andrew Hawkins
 
6
 
 
7
   This file is part of libmusicbrainz5.
 
8
 
 
9
   This library is free software; you can redistribute it and/or
 
10
   modify it under the terms of v2 of the GNU Lesser General Public
 
11
   License as published by the Free Software Foundation.
 
12
 
 
13
   libmusicbrainz5 is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
   Lesser General Public License for more details.
 
17
 
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
     $Id$
 
22
 
 
23
----------------------------------------------------------------------------*/
 
24
 
 
25
#include "config.h"
 
26
#include "musicbrainz5/defines.h"
 
27
 
 
28
#include "musicbrainz5/Medium.h"
 
29
 
 
30
#include "musicbrainz5/Disc.h"
 
31
#include "musicbrainz5/DiscList.h"
 
32
#include "musicbrainz5/Track.h"
 
33
#include "musicbrainz5/TrackList.h"
 
34
 
 
35
class MusicBrainz5::CMediumPrivate
 
36
{
 
37
        public:
 
38
                CMediumPrivate()
 
39
                :       m_Position(0),
 
40
                        m_DiscList(0),
 
41
                        m_TrackList(0)
 
42
                {
 
43
                }
 
44
 
 
45
                std::string m_Title;
 
46
                int m_Position;
 
47
                std::string m_Format;
 
48
                CDiscList *m_DiscList;
 
49
                CTrackList *m_TrackList;
 
50
};
 
51
 
 
52
MusicBrainz5::CMedium::CMedium(const XMLNode& Node)
 
53
:       CEntity(),
 
54
        m_d(new CMediumPrivate)
 
55
{
 
56
        if (!Node.isEmpty())
 
57
        {
 
58
                //std::cout << "Medium node: " << std::endl << Node.createXMLString(true) << std::endl;
 
59
 
 
60
                Parse(Node);
 
61
        }
 
62
}
 
63
 
 
64
MusicBrainz5::CMedium::CMedium(const CMedium& Other)
 
65
:       CEntity(),
 
66
        m_d(new CMediumPrivate)
 
67
{
 
68
        *this=Other;
 
69
}
 
70
 
 
71
MusicBrainz5::CMedium& MusicBrainz5::CMedium::operator =(const CMedium& Other)
 
72
{
 
73
        if (this!=&Other)
 
74
        {
 
75
                Cleanup();
 
76
 
 
77
                CEntity::operator =(Other);
 
78
 
 
79
                m_d->m_Title=Other.m_d->m_Title;
 
80
                m_d->m_Position=Other.m_d->m_Position;
 
81
                m_d->m_Format=Other.m_d->m_Format;
 
82
 
 
83
                if (Other.m_d->m_DiscList)
 
84
                        m_d->m_DiscList=new CDiscList(*Other.m_d->m_DiscList);
 
85
 
 
86
                if (Other.m_d->m_TrackList)
 
87
                        m_d->m_TrackList=new CTrackList(*Other.m_d->m_TrackList);
 
88
        }
 
89
 
 
90
        return *this;
 
91
}
 
92
 
 
93
MusicBrainz5::CMedium::~CMedium()
 
94
{
 
95
        Cleanup();
 
96
 
 
97
        delete m_d;
 
98
}
 
99
 
 
100
void MusicBrainz5::CMedium::Cleanup()
 
101
{
 
102
        delete m_d->m_DiscList;
 
103
        m_d->m_DiscList=0;
 
104
 
 
105
        delete m_d->m_TrackList;
 
106
        m_d->m_TrackList=0;
 
107
}
 
108
 
 
109
MusicBrainz5::CMedium *MusicBrainz5::CMedium::Clone()
 
110
{
 
111
        return new CMedium(*this);
 
112
}
 
113
 
 
114
void MusicBrainz5::CMedium::ParseAttribute(const std::string& Name, const std::string& /*Value*/)
 
115
{
 
116
        std::cerr << "Unrecognised medium attribute: '" << Name << "'" << std::endl;
 
117
}
 
118
 
 
119
void MusicBrainz5::CMedium::ParseElement(const XMLNode& Node)
 
120
{
 
121
        std::string NodeName=Node.getName();
 
122
 
 
123
        if ("title"==NodeName)
 
124
        {
 
125
                ProcessItem(Node,m_d->m_Title);
 
126
        }
 
127
        else if ("position"==NodeName)
 
128
        {
 
129
                ProcessItem(Node,m_d->m_Position);
 
130
        }
 
131
        else if ("format"==NodeName)
 
132
        {
 
133
                ProcessItem(Node,m_d->m_Format);
 
134
        }
 
135
        else if ("disc-list"==NodeName)
 
136
        {
 
137
                ProcessItem(Node,m_d->m_DiscList);
 
138
        }
 
139
        else if ("track-list"==NodeName)
 
140
        {
 
141
                ProcessItem(Node,m_d->m_TrackList);
 
142
        }
 
143
        else
 
144
        {
 
145
                std::cerr << "Unrecognised medium element: '" << NodeName << "'" << std::endl;
 
146
        }
 
147
}
 
148
 
 
149
std::string MusicBrainz5::CMedium::GetElementName()
 
150
{
 
151
        return "medium";
 
152
}
 
153
 
 
154
std::string MusicBrainz5::CMedium::Title() const
 
155
{
 
156
        return m_d->m_Title;
 
157
}
 
158
 
 
159
int MusicBrainz5::CMedium::Position() const
 
160
{
 
161
        return m_d->m_Position;
 
162
}
 
163
 
 
164
std::string MusicBrainz5::CMedium::Format() const
 
165
{
 
166
        return m_d->m_Format;
 
167
}
 
168
 
 
169
MusicBrainz5::CDiscList *MusicBrainz5::CMedium::DiscList() const
 
170
{
 
171
        return m_d->m_DiscList;
 
172
}
 
173
 
 
174
MusicBrainz5::CTrackList *MusicBrainz5::CMedium::TrackList() const
 
175
{
 
176
        return m_d->m_TrackList;
 
177
}
 
178
 
 
179
bool MusicBrainz5::CMedium::ContainsDiscID(const std::string& DiscID) const
 
180
{
 
181
        bool RetVal=false;
 
182
 
 
183
        if (m_d->m_DiscList)
 
184
        {
 
185
                for (int count=0;!RetVal && count<m_d->m_DiscList->NumItems();count++)
 
186
                {
 
187
                        CDisc *Disc=m_d->m_DiscList->Item(count);
 
188
 
 
189
                        if (Disc->ID()==DiscID)
 
190
                                RetVal=true;
 
191
                }
 
192
        }
 
193
 
 
194
        return RetVal;
 
195
}
 
196
 
 
197
std::ostream& MusicBrainz5::CMedium::Serialise(std::ostream& os) const
 
198
{
 
199
        os << "Medium:" << std::endl;
 
200
 
 
201
        CEntity::Serialise(os);
 
202
 
 
203
        os << "\tTitle:    " << Title() << std::endl;
 
204
        os << "\tPosition: " << Position() << std::endl;
 
205
        os << "\tFormat:   " << Format() << std::endl;
 
206
 
 
207
        if (DiscList())
 
208
                os << *DiscList() << std::endl;
 
209
 
 
210
        if (TrackList())
 
211
                os << *TrackList() << std::endl;
 
212
 
 
213
        return os;
 
214
}