Syndication

global.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "global.h"
9 #include "documentsource.h"
10 #include "parsercollectionimpl.h"
11 
12 #include "atom/parser.h"
13 #include "mapper/mapperatomimpl.h"
14 #include "mapper/mapperrdfimpl.h"
15 #include "mapper/mapperrss2impl.h"
16 #include "rdf/parser.h"
17 #include "rss2/parser.h"
18 
19 #include <QCoreApplication>
20 
21 namespace
22 {
23 static bool collectionIsInitialized = false;
24 }
25 
26 namespace Syndication
27 {
28 static ParserCollectionImpl<Syndication::Feed> *parserColl = nullptr;
29 
30 namespace
31 {
32 // only executed when then was a QCoreApplication
33 static void cleanupParserCollection()
34 {
35  delete parserColl;
36  parserColl = nullptr;
37 }
38 
39 } // namespace
40 
42 {
43  if (!collectionIsInitialized) {
44  parserColl = new ParserCollectionImpl<Syndication::Feed>;
45  qAddPostRoutine(cleanupParserCollection);
46  parserColl->registerParser(new RSS2::Parser, new RSS2Mapper);
47  parserColl->registerParser(new Atom::Parser, new AtomMapper);
48  parserColl->registerParser(new RDF::Parser, new RDFMapper);
49  collectionIsInitialized = true;
50  }
51  return parserColl;
52 }
53 
54 FeedPtr parse(const DocumentSource &src, const QString &formatHint)
55 {
56  return parserCollection()->parse(src, formatHint);
57 }
58 
59 } // namespace Syndication
FeedPtr parse(const DocumentSource &src, const QString &formatHint)
parses a document from a source and returns a new Feed object wrapping the feed content.
Definition: global.cpp:54
A collection of format-specific parser implementations.
Definition: global.h:21
ParserCollection< Feed > * parserCollection()
The default ParserCollection instance parsing a DocumentSource into a Feed object.
Definition: global.cpp:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Jun 6 2023 03:56:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.