~ubuntu-branches/ubuntu/precise/libmusicbrainz/precise-updates

« back to all changes in this revision

Viewing changes to src/Medium.cc

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-02-01 17:18:10 UTC
  • Revision ID: package-import@ubuntu.com-20120201171810-jzz90w51dx6shdr1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* --------------------------------------------------------------------------
 
2
 
 
3
   libmusicbrainz4 - Client library to access MusicBrainz
 
4
 
 
5
   Copyright (C) 2011 Andrew Hawkins
 
6
 
 
7
   This file is part of libmusicbrainz4.
 
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
   libmusicbrainz4 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: Medium.cc 13259 2011-08-10 12:02:50Z adhawkins $
 
22
 
 
23
----------------------------------------------------------------------------*/
 
24
 
 
25
#include "musicbrainz4/Medium.h"
 
26
 
 
27
#include "musicbrainz4/Disc.h"
 
28
#include "musicbrainz4/DiscList.h"
 
29
#include "musicbrainz4/Track.h"
 
30
#include "musicbrainz4/TrackList.h"
 
31
 
 
32
class MusicBrainz4::CMediumPrivate
 
33
{
 
34
        public:
 
35
                CMediumPrivate()
 
36
                :       m_Position(0),
 
37
                        m_DiscList(0),
 
38
                        m_TrackList(0)
 
39
                {
 
40
                }
 
41
 
 
42
                std::string m_Title;
 
43
                int m_Position;
 
44
                std::string m_Format;
 
45
                CDiscList *m_DiscList;
 
46
                CTrackList *m_TrackList;
 
47
};
 
48
 
 
49
MusicBrainz4::CMedium::CMedium(const XMLNode& Node)
 
50
:       CEntity(),
 
51
        m_d(new CMediumPrivate)
 
52
{
 
53
        if (!Node.isEmpty())
 
54
        {
 
55
                //std::cout << "Medium node: " << std::endl << Node.createXMLString(true) << std::endl;
 
56
 
 
57
                Parse(Node);
 
58
        }
 
59
}
 
60
 
 
61
MusicBrainz4::CMedium::CMedium(const CMedium& Other)
 
62
:       CEntity(),
 
63
        m_d(new CMediumPrivate)
 
64
{
 
65
        *this=Other;
 
66
}
 
67
 
 
68
MusicBrainz4::CMedium& MusicBrainz4::CMedium::operator =(const CMedium& Other)
 
69
{
 
70
        if (this!=&Other)
 
71
        {
 
72
                Cleanup();
 
73
 
 
74
                CEntity::operator =(Other);
 
75
 
 
76
                m_d->m_Title=Other.m_d->m_Title;
 
77
                m_d->m_Position=Other.m_d->m_Position;
 
78
                m_d->m_Format=Other.m_d->m_Format;
 
79
 
 
80
                if (Other.m_d->m_DiscList)
 
81
                        m_d->m_DiscList=new CDiscList(*Other.m_d->m_DiscList);
 
82
 
 
83
                if (Other.m_d->m_TrackList)
 
84
                        m_d->m_TrackList=new CTrackList(*Other.m_d->m_TrackList);
 
85
        }
 
86
 
 
87
        return *this;
 
88
}
 
89
 
 
90
MusicBrainz4::CMedium::~CMedium()
 
91
{
 
92
        Cleanup();
 
93
 
 
94
        delete m_d;
 
95
}
 
96
 
 
97
void MusicBrainz4::CMedium::Cleanup()
 
98
{
 
99
        delete m_d->m_DiscList;
 
100
        m_d->m_DiscList=0;
 
101
 
 
102
        delete m_d->m_TrackList;
 
103
        m_d->m_TrackList=0;
 
104
}
 
105
 
 
106
MusicBrainz4::CMedium *MusicBrainz4::CMedium::Clone()
 
107
{
 
108
        return new CMedium(*this);
 
109
}
 
110
 
 
111
bool MusicBrainz4::CMedium::ParseAttribute(const std::string& Name, const std::string& /*Value*/)
 
112
{
 
113
        bool RetVal=true;
 
114
 
 
115
        std::cerr << "Unrecognised medium attribute: '" << Name << "'" << std::endl;
 
116
        RetVal=false;
 
117
 
 
118
        return RetVal;
 
119
}
 
120
 
 
121
bool MusicBrainz4::CMedium::ParseElement(const XMLNode& Node)
 
122
{
 
123
        bool RetVal=true;
 
124
 
 
125
        std::string NodeName=Node.getName();
 
126
 
 
127
        if ("title"==NodeName)
 
128
        {
 
129
                RetVal=ProcessItem(Node,m_d->m_Title);
 
130
        }
 
131
        else if ("position"==NodeName)
 
132
        {
 
133
                RetVal=ProcessItem(Node,m_d->m_Position);
 
134
        }
 
135
        else if ("format"==NodeName)
 
136
        {
 
137
                RetVal=ProcessItem(Node,m_d->m_Format);
 
138
        }
 
139
        else if ("disc-list"==NodeName)
 
140
        {
 
141
                RetVal=ProcessItem(Node,m_d->m_DiscList);
 
142
        }
 
143
        else if ("track-list"==NodeName)
 
144
        {
 
145
                RetVal=ProcessItem(Node,m_d->m_TrackList);
 
146
        }
 
147
        else
 
148
        {
 
149
                std::cerr << "Unrecognised medium element: '" << NodeName << "'" << std::endl;
 
150
                RetVal=false;
 
151
        }
 
152
 
 
153
        return RetVal;
 
154
}
 
155
 
 
156
std::string MusicBrainz4::CMedium::GetElementName()
 
157
{
 
158
        return "medium";
 
159
}
 
160
 
 
161
std::string MusicBrainz4::CMedium::Title() const
 
162
{
 
163
        return m_d->m_Title;
 
164
}
 
165
 
 
166
int MusicBrainz4::CMedium::Position() const
 
167
{
 
168
        return m_d->m_Position;
 
169
}
 
170
 
 
171
std::string MusicBrainz4::CMedium::Format() const
 
172
{
 
173
        return m_d->m_Format;
 
174
}
 
175
 
 
176
MusicBrainz4::CDiscList *MusicBrainz4::CMedium::DiscList() const
 
177
{
 
178
        return m_d->m_DiscList;
 
179
}
 
180
 
 
181
MusicBrainz4::CTrackList *MusicBrainz4::CMedium::TrackList() const
 
182
{
 
183
        return m_d->m_TrackList;
 
184
}
 
185
 
 
186
bool MusicBrainz4::CMedium::ContainsDiscID(const std::string& DiscID) const
 
187
{
 
188
        bool RetVal=false;
 
189
 
 
190
        if (m_d->m_DiscList)
 
191
        {
 
192
                for (int count=0;!RetVal && count<m_d->m_DiscList->NumItems();count++)
 
193
                {
 
194
                        CDisc *Disc=m_d->m_DiscList->Item(count);
 
195
 
 
196
                        if (Disc->ID()==DiscID)
 
197
                                RetVal=true;
 
198
                }
 
199
        }
 
200
 
 
201
        return RetVal;
 
202
}
 
203
 
 
204
std::ostream& MusicBrainz4::CMedium::Serialise(std::ostream& os) const
 
205
{
 
206
        os << "Medium:" << std::endl;
 
207
 
 
208
        CEntity::Serialise(os);
 
209
 
 
210
        os << "\tTitle:    " << Title() << std::endl;
 
211
        os << "\tPosition: " << Position() << std::endl;
 
212
        os << "\tFormat:   " << Format() << std::endl;
 
213
 
 
214
        if (DiscList())
 
215
                os << *DiscList() << std::endl;
 
216
 
 
217
        if (TrackList())
 
218
                os << *TrackList() << std::endl;
 
219
 
 
220
        return os;
 
221
}