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

« back to all changes in this revision

Viewing changes to src/Rating.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/Rating.h"
 
29
 
 
30
class MusicBrainz5::CRatingPrivate
 
31
{
 
32
        public:
 
33
                CRatingPrivate()
 
34
                :       m_VotesCount(0),
 
35
                        m_Rating(0.0)
 
36
                {
 
37
                }
 
38
 
 
39
                int m_VotesCount;
 
40
                double m_Rating;
 
41
};
 
42
 
 
43
MusicBrainz5::CRating::CRating(const XMLNode& Node)
 
44
:       CEntity(),
 
45
        m_d(new CRatingPrivate)
 
46
{
 
47
        if (!Node.isEmpty())
 
48
        {
 
49
                //std::cout << "Rating node: " << std::endl << Node.createXMLString(true) << std::endl;
 
50
 
 
51
                Parse(Node);
 
52
 
 
53
                if (Node.getText())
 
54
                {
 
55
                        ProcessItem(Node,m_d->m_Rating);
 
56
                }
 
57
        }
 
58
}
 
59
 
 
60
MusicBrainz5::CRating::CRating(const CRating& Other)
 
61
:       CEntity(),
 
62
        m_d(new CRatingPrivate)
 
63
{
 
64
        *this=Other;
 
65
}
 
66
 
 
67
MusicBrainz5::CRating& MusicBrainz5::CRating::operator =(const CRating& Other)
 
68
{
 
69
        if (this!=&Other)
 
70
        {
 
71
                CEntity::operator =(Other);
 
72
 
 
73
                m_d->m_VotesCount=Other.m_d->m_VotesCount;
 
74
                m_d->m_Rating=Other.m_d->m_Rating;
 
75
        }
 
76
 
 
77
        return *this;
 
78
}
 
79
 
 
80
MusicBrainz5::CRating::~CRating()
 
81
{
 
82
        delete m_d;
 
83
}
 
84
 
 
85
MusicBrainz5::CRating *MusicBrainz5::CRating::Clone()
 
86
{
 
87
        return new CRating(*this);
 
88
}
 
89
 
 
90
void MusicBrainz5::CRating::ParseAttribute(const std::string& Name, const std::string& Value)
 
91
{
 
92
        if ("votes-count"==Name)
 
93
        {
 
94
                ProcessItem(Value,m_d->m_VotesCount);
 
95
        }
 
96
        else
 
97
        {
 
98
                std::cerr << "Unrecognised rating attribute: '" << Name << "'" << std::endl;
 
99
        }
 
100
}
 
101
 
 
102
void MusicBrainz5::CRating::ParseElement(const XMLNode& Node)
 
103
{
 
104
        std::string NodeName=Node.getName();
 
105
 
 
106
        std::cerr << "Unrecognised rating attribute: '" << NodeName << "'" << std::endl;
 
107
}
 
108
 
 
109
std::string MusicBrainz5::CRating::GetElementName()
 
110
{
 
111
        return "rating";
 
112
}
 
113
 
 
114
int MusicBrainz5::CRating::VotesCount() const
 
115
{
 
116
        return m_d->m_VotesCount;
 
117
}
 
118
 
 
119
double MusicBrainz5::CRating::Rating() const
 
120
{
 
121
        return m_d->m_Rating;
 
122
}
 
123
 
 
124
std::ostream& MusicBrainz5::CRating::Serialise(std::ostream& os) const
 
125
{
 
126
        os << "Rating:" << std::endl;
 
127
 
 
128
        CEntity::Serialise(os);
 
129
 
 
130
        os << "\tVotes count: " << VotesCount() << std::endl;
 
131
        os << "\tRating:      " << Rating() << std::endl;
 
132
 
 
133
        return os;
 
134
}