~ubuntu-branches/ubuntu/precise/libmusicbrainz/precise-proposed

« back to all changes in this revision

Viewing changes to include/musicbrainz4/ListImpl.h

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-02-01 17:18:10 UTC
  • Revision ID: package-import@ubuntu.com-20120201171810-jzz90w51dx6shdr1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* --------------------------------------------------------------------------
 
2
 
 
3
   libmusicbrainz4 - Client library to access MusicBrainz
 
4
 
 
5
   Copyright (C) 2011 Andrew Hawkins
 
6
 
 
7
   This file is part of libmusicbrainz4.
 
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
   libmusicbrainz4 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: ListImpl.h 13259 2011-08-10 12:02:50Z adhawkins $
 
22
 
 
23
----------------------------------------------------------------------------*/
 
24
 
 
25
#ifndef _MUSICBRAINZ4_LIST_IMPL_H
 
26
#define _MUSICBRAINZ4_LIST_IMPL_H
 
27
 
 
28
#include "musicbrainz4/List.h"
 
29
 
 
30
namespace MusicBrainz4
 
31
{
 
32
        template <class T>
 
33
        class CListImpl: public CList
 
34
        {
 
35
        public:
 
36
                CListImpl(const XMLNode& Node=XMLNode::emptyNode())
 
37
                :       CList()
 
38
                {
 
39
                        if (!Node.isEmpty())
 
40
                        {
 
41
                                //std::cout << T::GetElementName() << " List node: " << std::endl << Node.createXMLString(true) << std::endl;
 
42
 
 
43
                                Parse(Node);
 
44
                        }
 
45
                }
 
46
 
 
47
                CListImpl(const CListImpl<T>& Other)
 
48
                :       CList()
 
49
                {
 
50
                        *this=Other;
 
51
                }
 
52
 
 
53
                MusicBrainz4::CListImpl<T>& operator =(const CListImpl<T>& Other)
 
54
                {
 
55
                        if (this!=&Other)
 
56
                        {
 
57
                                CList::operator =(Other);
 
58
                        }
 
59
 
 
60
                        return *this;
 
61
                }
 
62
 
 
63
                virtual ~CListImpl()
 
64
                {
 
65
                }
 
66
 
 
67
                CListImpl<T> *Clone()
 
68
                {
 
69
                        return new CListImpl<T>(*this);
 
70
                }
 
71
 
 
72
                virtual std::ostream& Serialise(std::ostream& os) const
 
73
                {
 
74
                        os << T::GetElementName() << " List (impl):" << std::endl;
 
75
 
 
76
                        CList::Serialise(os);
 
77
 
 
78
                        for (int count=0;count<NumItems();count++)
 
79
                        {
 
80
                                T *ThisItem=Item(count);
 
81
 
 
82
                                os << *ThisItem << std::endl;
 
83
                        }
 
84
 
 
85
                        return os;
 
86
                }
 
87
 
 
88
                static std::string GetElementName()
 
89
                {
 
90
                        return "";
 
91
                }
 
92
 
 
93
                T *Item(int Item) const
 
94
                {
 
95
                        return dynamic_cast<T *>(CList::Item(Item));
 
96
                }
 
97
 
 
98
                void AddItem(T *Item)
 
99
                {
 
100
                        CList::AddItem(Item);
 
101
                }
 
102
 
 
103
        protected:
 
104
                bool ParseElement(const XMLNode& Node)
 
105
                {
 
106
                        bool RetVal=true;
 
107
 
 
108
                        std::string NodeName=Node.getName();
 
109
 
 
110
                        if (T::GetElementName()==NodeName)
 
111
                        {
 
112
                                T *Item=0;
 
113
 
 
114
                                RetVal=ProcessItem(Node,Item);
 
115
                                if (RetVal)
 
116
                                        AddItem(Item);
 
117
                        }
 
118
                        else
 
119
                                RetVal=CList::ParseElement(Node);
 
120
 
 
121
                        return RetVal;
 
122
                }
 
123
 
 
124
        };
 
125
}
 
126
 
 
127
#endif