libmusicbrainz5 5.1.0
Loading...
Searching...
No Matches
ListImpl.h
Go to the documentation of this file.
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#ifndef _MUSICBRAINZ5_LIST_IMPL_H
27#define _MUSICBRAINZ5_LIST_IMPL_H
28
29#include "musicbrainz5/List.h"
30
31namespace MusicBrainz5
32{
33 template <class T>
34 class CListImpl: public CList
35 {
36 public:
37 CListImpl(const XMLNode& Node=XMLNode::emptyNode())
38 : CList()
39 {
40 if (!Node.isEmpty())
41 {
42 //std::cout << T::GetElementName() << " List node: " << std::endl << Node.createXMLString(true) << std::endl;
43
44 Parse(Node);
45 }
46 }
47
48 CListImpl(const CListImpl<T>& Other)
49 : CList()
50 {
51 *this=Other;
52 }
53
55 {
56 if (this!=&Other)
57 {
58 CList::operator =(Other);
59 }
60
61 return *this;
62 }
63
64 virtual ~CListImpl()
65 {
66 }
67
69 {
70 return new CListImpl<T>(*this);
71 }
72
73 virtual std::ostream& Serialise(std::ostream& os) const
74 {
75 os << T::GetElementName() << " List (impl):" << std::endl;
76
78
79 for (int count=0;count<NumItems();count++)
80 {
82
83 os << *ThisItem << std::endl;
84 }
85
86 return os;
87 }
88
89 static std::string GetElementName()
90 {
91 return "";
92 }
93
94 T *Item(int Item) const
95 {
96 return dynamic_cast<T *>(CList::Item(Item));
97 }
98
99 void AddItem(T *Item)
100 {
102 }
103
104 protected:
106 {
107 std::string NodeName=Node.getName();
108
109 if (T::GetElementName()==NodeName)
110 {
111 T *Item=0;
112
114 AddItem(Item);
115 }
116 else
118 }
119 };
120}
121
122#endif
void Parse(const XMLNode &Node)
void ProcessItem(const XMLNode &Node, T *&RetVal)
Definition Entity.h:64
Definition List.h:38
virtual void ParseElement(const XMLNode &Node)
CEntity * Item(int Item) const
CList & operator=(const CList &Other)
int NumItems() const
virtual std::ostream & Serialise(std::ostream &os) const
void AddItem(CEntity *Item)
Definition ListImpl.h:35
void ParseElement(const XMLNode &Node)
Definition ListImpl.h:105
CListImpl< T > * Clone()
Definition ListImpl.h:68
T * Item(int Item) const
Definition ListImpl.h:94
MusicBrainz5::CListImpl< T > & operator=(const CListImpl< T > &Other)
Definition ListImpl.h:54
void AddItem(T *Item)
Definition ListImpl.h:99
virtual std::ostream & Serialise(std::ostream &os) const
Definition ListImpl.h:73
static std::string GetElementName()
Definition ListImpl.h:89
virtual ~CListImpl()
Definition ListImpl.h:64
CListImpl(const XMLNode &Node=XMLNode::emptyNode())
Definition ListImpl.h:37
CListImpl(const CListImpl< T > &Other)
Definition ListImpl.h:48
Definition Alias.h:37