libmusicbrainz5  5.1.0
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 
31 namespace 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 
77  CList::Serialise(os);
78 
79  for (int count=0;count<NumItems();count++)
80  {
81  T *ThisItem=Item(count);
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:
105  void ParseElement(const XMLNode& Node)
106  {
107  std::string NodeName=Node.getName();
108 
109  if (T::GetElementName()==NodeName)
110  {
111  T *Item=0;
112 
113  ProcessItem(Node,Item);
114  AddItem(Item);
115  }
116  else
117  CList::ParseElement(Node);
118  }
119  };
120 }
121 
122 #endif
MusicBrainz5::CListImpl::CListImpl
CListImpl(const XMLNode &Node=XMLNode::emptyNode())
Definition: ListImpl.h:37
MusicBrainz5::CListImpl::operator=
MusicBrainz5::CListImpl< T > & operator=(const CListImpl< T > &Other)
Definition: ListImpl.h:54
MusicBrainz5::CListImpl::ParseElement
void ParseElement(const XMLNode &Node)
Definition: ListImpl.h:105
MusicBrainz5::CListImpl::~CListImpl
virtual ~CListImpl()
Definition: ListImpl.h:64
MusicBrainz5::CListImpl::Clone
CListImpl< T > * Clone()
Definition: ListImpl.h:68
MusicBrainz5::CListImpl::AddItem
void AddItem(T *Item)
Definition: ListImpl.h:99
MusicBrainz5::CListImpl::Serialise
virtual std::ostream & Serialise(std::ostream &os) const
Definition: ListImpl.h:73
MusicBrainz5::CList
Definition: List.h:37
MusicBrainz5::CEntity::Parse
void Parse(const XMLNode &Node)
MusicBrainz5::CListImpl::CListImpl
CListImpl(const CListImpl< T > &Other)
Definition: ListImpl.h:48
MusicBrainz5::CList::operator=
CList & operator=(const CList &Other)
MusicBrainz5::CList::Serialise
virtual std::ostream & Serialise(std::ostream &os) const
MusicBrainz5::CList::Item
CEntity * Item(int Item) const
MusicBrainz5::CList::ParseElement
virtual void ParseElement(const XMLNode &Node)
MusicBrainz5::CList::NumItems
int NumItems() const
MusicBrainz5::CListImpl::Item
T * Item(int Item) const
Definition: ListImpl.h:94
MusicBrainz5::CList::AddItem
void AddItem(CEntity *Item)
MusicBrainz5
Definition: Alias.h:36
MusicBrainz5::CListImpl::GetElementName
static std::string GetElementName()
Definition: ListImpl.h:89
List.h
MusicBrainz5::CListImpl
Definition: ListImpl.h:34
MusicBrainz5::CEntity::ProcessItem
void ProcessItem(const XMLNode &Node, T *&RetVal)
Definition: Entity.h:64