wfut 0.2.4
A client side C++ implementation of WFUT (WorldForge Update Tool).
ChannelWriter.cpp
1// This file may be redistributed and modified only under the terms of
2// the GNU Lesser General Public License (See COPYING for details).
3// Copyright (C) 2005 - 2007 Simon Goodall
4
5#include "types.h"
6
7#include "tinyxml/tinyxml.h"
8
9#include "libwfut/ChannelIO.h"
10
11namespace WFUT {
12
13static int writeChannel(TiXmlElement *element, const ChannelObject &channel) {
14 assert(element);
15
16 TiXmlElement name(TAG_name);
17 name.InsertEndChild(TiXmlText(channel.name));
18 element->InsertEndChild(name);
19
20 TiXmlElement description(TAG_description);
21 description.InsertEndChild(TiXmlText(channel.description));
22 element->InsertEndChild(description);
23
24 TiXmlElement url(TAG_url);
25 url.InsertEndChild(TiXmlText(channel.url));
26 element->InsertEndChild(url);
27
28 TiXmlElement email(TAG_email);
29 email.InsertEndChild(TiXmlText(channel.email));
30 element->InsertEndChild(email);
31
32 TiXmlElement logo(TAG_logo);
33 logo.InsertEndChild(TiXmlText(channel.logo));
34 element->InsertEndChild(logo);
35
36 return 0;
37}
38
39int writeChannelList(const std::string &filename, const ChannelList &channels) {
40 TiXmlDocument doc;
41 doc.InsertEndChild(TiXmlDeclaration("1.0", "", ""));
42
43 TiXmlElement clist(TAG_channellist);
44
45 ChannelList::const_iterator itr = channels.begin();
46 while (itr != channels.end()) {
47 TiXmlElement channel(TAG_channel);
48 writeChannel(&channel, *itr);
49 clist.InsertEndChild(channel);
50 ++itr;
51 }
52
53 doc.InsertEndChild(clist);
54 if (!doc.SaveFile(filename)) {
55 // error writing file
56 return 1;
57 }
58 return 0;
59}
60
61} /* namespace WFUT */