libmusicbrainz4
4.0.3
|
00001 /* -------------------------------------------------------------------------- 00002 00003 libmusicbrainz4 - Client library to access MusicBrainz 00004 00005 Copyright (C) 2011 Andrew Hawkins 00006 00007 This file is part of libmusicbrainz4. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of v2 of the GNU Lesser General Public 00011 License as published by the Free Software Foundation. 00012 00013 libmusicbrainz4 is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this library. If not, see <http://www.gnu.org/licenses/>. 00020 00021 $Id$ 00022 00023 ----------------------------------------------------------------------------*/ 00024 00025 #ifndef _MUSICBRAINZ4_LIST_IMPL_H 00026 #define _MUSICBRAINZ4_LIST_IMPL_H 00027 00028 #include "musicbrainz4/List.h" 00029 00030 namespace MusicBrainz4 00031 { 00032 template <class T> 00033 class CListImpl: public CList 00034 { 00035 public: 00036 CListImpl(const XMLNode& Node=XMLNode::emptyNode()) 00037 : CList() 00038 { 00039 if (!Node.isEmpty()) 00040 { 00041 //std::cout << T::GetElementName() << " List node: " << std::endl << Node.createXMLString(true) << std::endl; 00042 00043 Parse(Node); 00044 } 00045 } 00046 00047 CListImpl(const CListImpl<T>& Other) 00048 : CList() 00049 { 00050 *this=Other; 00051 } 00052 00053 MusicBrainz4::CListImpl<T>& operator =(const CListImpl<T>& Other) 00054 { 00055 if (this!=&Other) 00056 { 00057 CList::operator =(Other); 00058 } 00059 00060 return *this; 00061 } 00062 00063 virtual ~CListImpl() 00064 { 00065 } 00066 00067 CListImpl<T> *Clone() 00068 { 00069 return new CListImpl<T>(*this); 00070 } 00071 00072 virtual std::ostream& Serialise(std::ostream& os) const 00073 { 00074 os << T::GetElementName() << " List (impl):" << std::endl; 00075 00076 CList::Serialise(os); 00077 00078 for (int count=0;count<NumItems();count++) 00079 { 00080 T *ThisItem=Item(count); 00081 00082 os << *ThisItem << std::endl; 00083 } 00084 00085 return os; 00086 } 00087 00088 static std::string GetElementName() 00089 { 00090 return ""; 00091 } 00092 00093 T *Item(int Item) const 00094 { 00095 return dynamic_cast<T *>(CList::Item(Item)); 00096 } 00097 00098 void AddItem(T *Item) 00099 { 00100 CList::AddItem(Item); 00101 } 00102 00103 protected: 00104 void ParseElement(const XMLNode& Node) 00105 { 00106 std::string NodeName=Node.getName(); 00107 00108 if (T::GetElementName()==NodeName) 00109 { 00110 T *Item=0; 00111 00112 ProcessItem(Node,Item); 00113 AddItem(Item); 00114 } 00115 else 00116 CList::ParseElement(Node); 00117 } 00118 }; 00119 } 00120 00121 #endif