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 the GNU Lesser General Public
11    License as published by the Free Software Foundation; either
12    version 2.1 of the License, or (at your option) any later version.
13 
14    libmusicbrainz5 is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    Lesser General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this library.  If not, see <http://www.gnu.org/licenses/>.
21 
22      $Id$
23 
24 ----------------------------------------------------------------------------*/
25 
26 #include "config.h"
27 #include "musicbrainz5/defines.h"
28 
29 #include "musicbrainz5/Alias.h"
30 
31 class MusicBrainz5::CAliasPrivate
32 {
33 public:
34 		std::string m_Locale;
35 		std::string m_Text;
36 		std::string m_SortName;
37 		std::string m_Type;
38 		std::string m_Primary;
39 		std::string m_BeginDate;
40 		std::string m_EndDate;
41 };
42 
CAlias(const XMLNode & Node)43 MusicBrainz5::CAlias::CAlias(const XMLNode& Node)
44 :	CEntity(),
45 	m_d(new CAliasPrivate)
46 {
47 	if (!Node.isEmpty())
48 	{
49 		//std::cout << "Alias node: " << std::endl << Node.createXMLString(true) << std::endl;
50 
51 		Parse(Node);
52 
53 		if (Node.getText())
54 			ProcessItem(Node,m_d->m_Text);
55 	}
56 }
57 
CAlias(const CAlias & Other)58 MusicBrainz5::CAlias::CAlias(const CAlias& Other)
59 :	CEntity(),
60 	m_d(new CAliasPrivate)
61 {
62 	*this=Other;
63 }
64 
operator =(const CAlias & Other)65 MusicBrainz5::CAlias& MusicBrainz5::CAlias::operator =(const CAlias& Other)
66 {
67 	if (this!=&Other)
68 	{
69 		CEntity::operator =(Other);
70 
71 		m_d->m_Locale=Other.m_d->m_Locale;
72 		m_d->m_Text=Other.m_d->m_Text;
73 		m_d->m_SortName=Other.m_d->m_SortName;
74 		m_d->m_Type=Other.m_d->m_Type;
75 		m_d->m_Primary=Other.m_d->m_Primary;
76 		m_d->m_BeginDate=Other.m_d->m_BeginDate;
77 		m_d->m_EndDate=Other.m_d->m_EndDate;
78 	}
79 
80 	return *this;
81 }
82 
~CAlias()83 MusicBrainz5::CAlias::~CAlias()
84 {
85 	delete m_d;
86 }
87 
Clone()88 MusicBrainz5::CAlias *MusicBrainz5::CAlias::Clone()
89 {
90 	return new CAlias(*this);
91 }
92 
ParseAttribute(const std::string & Name,const std::string & Value)93 void MusicBrainz5::CAlias::ParseAttribute(const std::string& Name, const std::string& Value)
94 {
95 	if ("locale"==Name)
96 		m_d->m_Locale=Value;
97 	else if ("sort-name"==Name)
98 		m_d->m_SortName=Value;
99 	else if ("type"==Name)
100 		m_d->m_Type=Value;
101 	else if ("primary"==Name)
102 		m_d->m_Primary=Value;
103 	else if ("begin-date"==Name)
104 		m_d->m_BeginDate=Value;
105 	else if ("end-date"==Name)
106 		m_d->m_EndDate=Value;
107 	else
108 	{
109 #ifdef _MB5_DEBUG_
110 		std::cerr << "Unrecognised alias attribute: '" << Name << "'" << std::endl;
111 #endif
112 	}
113 }
114 
ParseElement(const XMLNode & Node)115 void MusicBrainz5::CAlias::ParseElement(const XMLNode& Node)
116 {
117 	std::string NodeName=Node.getName();
118 #ifdef _MB5_DEBUG_
119 	std::cerr << "Unrecognised alias element: '" << NodeName << std::endl;
120 #endif
121 }
122 
GetElementName()123 std::string MusicBrainz5::CAlias::GetElementName()
124 {
125 	return "alias";
126 }
127 
Locale() const128 std::string MusicBrainz5::CAlias::Locale() const
129 {
130 	return m_d->m_Locale;
131 }
132 
Text() const133 std::string MusicBrainz5::CAlias::Text() const
134 {
135 	return m_d->m_Text;
136 }
137 
SortName() const138 std::string MusicBrainz5::CAlias::SortName() const
139 {
140 	return m_d->m_SortName;
141 }
142 
Type() const143 std::string MusicBrainz5::CAlias::Type() const
144 {
145 	return m_d->m_Type;
146 }
147 
Primary() const148 std::string MusicBrainz5::CAlias::Primary() const
149 {
150 	return m_d->m_Primary;
151 }
152 
BeginDate() const153 std::string MusicBrainz5::CAlias::BeginDate() const
154 {
155 	return m_d->m_BeginDate;
156 }
157 
EndDate() const158 std::string MusicBrainz5::CAlias::EndDate() const
159 {
160 	return m_d->m_EndDate;
161 }
162 
Serialise(std::ostream & os) const163 std::ostream& MusicBrainz5::CAlias::Serialise(std::ostream& os) const
164 {
165 	os << "Alias:" << std::endl;
166 
167 	CEntity::Serialise(os);
168 
169 	os << "\tLocale:    " << Locale() << std::endl;
170 	os << "\tText:      " << Text() << std::endl;
171 	os << "\tSort Name: " << SortName() << std::endl;
172 	os << "\tType:      " << Type() << std::endl;
173 	os << "\tPrimary:   " << Primary() << std::endl;
174 	os << "\tBeginDate: " << BeginDate() << std::endl;
175 	os << "\tEndDate:   " << EndDate() << std::endl;
176 
177 	return os;
178 }
179