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

« back to all changes in this revision

Viewing changes to src/FreeDBDisc.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: FreeDBDisc.cc 13259 2011-08-10 12:02:50Z adhawkins $
 
22
 
 
23
----------------------------------------------------------------------------*/
 
24
 
 
25
#include "musicbrainz4/FreeDBDisc.h"
 
26
 
 
27
#include "musicbrainz4/NonMBTrackList.h"
 
28
#include "musicbrainz4/NonMBTrack.h"
 
29
 
 
30
class MusicBrainz4::CFreeDBDiscPrivate
 
31
{
 
32
        public:
 
33
                CFreeDBDiscPrivate()
 
34
                :       m_NonMBTrackList(0)
 
35
                {
 
36
                }
 
37
 
 
38
                std::string m_ID;
 
39
                std::string m_Title;
 
40
                std::string m_Artist;
 
41
                std::string m_Category;
 
42
                std::string m_Year;
 
43
                CNonMBTrackList *m_NonMBTrackList;
 
44
};
 
45
 
 
46
MusicBrainz4::CFreeDBDisc::CFreeDBDisc(const XMLNode& Node)
 
47
:       CEntity(),
 
48
        m_d(new CFreeDBDiscPrivate)
 
49
{
 
50
        if (!Node.isEmpty())
 
51
        {
 
52
                //std::cout << "FreeDBDisc node: " << std::endl << Node.createXMLString(true) << std::endl;
 
53
 
 
54
                Parse(Node);
 
55
        }
 
56
}
 
57
 
 
58
MusicBrainz4::CFreeDBDisc::CFreeDBDisc(const CFreeDBDisc& Other)
 
59
:       CEntity(),
 
60
        m_d(new CFreeDBDiscPrivate)
 
61
{
 
62
        *this=Other;
 
63
}
 
64
 
 
65
MusicBrainz4::CFreeDBDisc& MusicBrainz4::CFreeDBDisc::operator =(const CFreeDBDisc& Other)
 
66
{
 
67
        if (this!=&Other)
 
68
        {
 
69
                Cleanup();
 
70
 
 
71
                CEntity::operator =(Other);
 
72
 
 
73
                m_d->m_ID=Other.m_d->m_ID;
 
74
                m_d->m_Title=Other.m_d->m_Title;
 
75
                m_d->m_Artist=Other.m_d->m_Artist;
 
76
                m_d->m_Category=Other.m_d->m_Category;
 
77
                m_d->m_Year=Other.m_d->m_Year;
 
78
 
 
79
                if (Other.m_d->m_NonMBTrackList)
 
80
                        m_d->m_NonMBTrackList=new CNonMBTrackList(*Other.m_d->m_NonMBTrackList);
 
81
        }
 
82
 
 
83
        return *this;
 
84
}
 
85
 
 
86
MusicBrainz4::CFreeDBDisc::~CFreeDBDisc()
 
87
{
 
88
        Cleanup();
 
89
 
 
90
        delete m_d;
 
91
}
 
92
 
 
93
void MusicBrainz4::CFreeDBDisc::Cleanup()
 
94
{
 
95
        delete m_d->m_NonMBTrackList;
 
96
        m_d->m_NonMBTrackList=0;
 
97
}
 
98
 
 
99
MusicBrainz4::CFreeDBDisc *MusicBrainz4::CFreeDBDisc::Clone()
 
100
{
 
101
        return new CFreeDBDisc(*this);
 
102
}
 
103
 
 
104
bool MusicBrainz4::CFreeDBDisc::ParseAttribute(const std::string& Name, const std::string& Value)
 
105
{
 
106
        bool RetVal=true;
 
107
 
 
108
 
 
109
        if ("id"==Name)
 
110
                m_d->m_ID=Value;
 
111
        else
 
112
        {
 
113
                std::cerr << "Unrecognised freedb disc attribute: '" << Name << "'" << std::endl;
 
114
                RetVal=false;
 
115
        }
 
116
 
 
117
        return RetVal;
 
118
}
 
119
 
 
120
bool MusicBrainz4::CFreeDBDisc::ParseElement(const XMLNode& Node)
 
121
{
 
122
        bool RetVal=true;
 
123
 
 
124
        std::string NodeName=Node.getName();
 
125
 
 
126
        if ("title"==NodeName)
 
127
        {
 
128
                RetVal=ProcessItem(Node,m_d->m_Title);
 
129
        }
 
130
        else if ("artist"==NodeName)
 
131
        {
 
132
                RetVal=ProcessItem(Node,m_d->m_Artist);
 
133
        }
 
134
        else if ("category"==NodeName)
 
135
        {
 
136
                RetVal=ProcessItem(Node,m_d->m_Category);
 
137
        }
 
138
        else if ("year"==NodeName)
 
139
        {
 
140
                RetVal=ProcessItem(Node,m_d->m_Year);
 
141
        }
 
142
        else if ("nonmb-track-list"==NodeName)
 
143
        {
 
144
                RetVal=ProcessItem(Node,m_d->m_NonMBTrackList);
 
145
        }
 
146
        else
 
147
        {
 
148
                std::cerr << "Unrecognised freedb disc element: '" << NodeName << "'" << std::endl;
 
149
                RetVal=false;
 
150
        }
 
151
 
 
152
        return RetVal;
 
153
}
 
154
 
 
155
std::string MusicBrainz4::CFreeDBDisc::GetElementName()
 
156
{
 
157
        return "freedb-disc";
 
158
}
 
159
 
 
160
std::string MusicBrainz4::CFreeDBDisc::ID() const
 
161
{
 
162
        return m_d->m_ID;
 
163
}
 
164
 
 
165
std::string MusicBrainz4::CFreeDBDisc::Title() const
 
166
{
 
167
        return m_d->m_Title;
 
168
}
 
169
 
 
170
std::string MusicBrainz4::CFreeDBDisc::Artist() const
 
171
{
 
172
        return m_d->m_Artist;
 
173
}
 
174
 
 
175
std::string MusicBrainz4::CFreeDBDisc::Category() const
 
176
{
 
177
        return m_d->m_Category;
 
178
}
 
179
 
 
180
std::string MusicBrainz4::CFreeDBDisc::Year() const
 
181
{
 
182
        return m_d->m_Year;
 
183
}
 
184
 
 
185
MusicBrainz4::CNonMBTrackList *MusicBrainz4::CFreeDBDisc::NonMBTrackList() const
 
186
{
 
187
        return m_d->m_NonMBTrackList;
 
188
}
 
189
 
 
190
std::ostream& MusicBrainz4::CFreeDBDisc::Serialise(std::ostream& os) const
 
191
{
 
192
        os << "FreeDBDisc:" << std::endl;
 
193
 
 
194
        CEntity::Serialise(os);
 
195
 
 
196
        os << "\tID:       " << ID() << std::endl;
 
197
        os << "\tTitle:    " << Title() << std::endl;
 
198
        os << "\tArtist:   " << Artist() << std::endl;
 
199
        os << "\tCategory: " << Category() << std::endl;
 
200
        os << "\tYear:     " << Year() << std::endl;
 
201
 
 
202
        if (NonMBTrackList())
 
203
                os << *NonMBTrackList() << std::endl;
 
204
 
 
205
        return os;
 
206
}