Support conversion of linkshere
[dueringa_WikiWalker.git] / inc / JsonSerializer.h
blob3369a642170f876ece899bde4b2bb872b96d4e38
1 //! \file
3 #ifndef WIKIWALKER_JSONSERIALIZER_H
4 #define WIKIWALKER_JSONSERIALIZER_H
6 #include <iostream>
8 #include "ArticleCollection.h"
10 namespace WikiWalker
12 /*! Serialize AricleCollection from and to a custom JSON format
14 class JsonSerializer
16 public:
17 /*! Serialize ArticleCollection to JSON in an output stream
18 * \param collection pointer to article to be output
19 * \param outstream outstream stream to putput to.
20 * YOU are responsible for opening and closing the stream.
21 * Articles in the collection which happen to "link" against nullptrs
22 * because their weak_ptr already expired will be simply *omitted* from the
23 * serialization
25 void serialize(const CollectionUtils::ArticleCollection& collection,
26 std::ostream& outstream);
28 /*! Deserialize JSON data to an ArticleCollection
29 * \param instream the stream containing the JSON data
30 * \returns The desirialized article collection.
31 * \sa deserialize(CollectionUtils::ArticleCollection&, std::istream&)
33 CollectionUtils::ArticleCollection deserialize(std::istream& instream);
35 /*! Deserialize JSON data to an ArticleCollection
36 * \param[out] collection The desirialized article collection
37 * \param instream the stream containing the JSON data
38 * \details The deserialized object / collection might not exactly match the
39 * serialized one! If a link of an article which is inside the article
40 * collection doesn't exist in the collection on serialization, it will be
41 * added to the collection on deserialization.
43 * Example: "A" is in the collection and links to "B", but "B" is not in the
44 * collection itself, so `["A" -> [ "B" ]]`. On deserialization, however,
45 * "B" is added to the collection, so the collection looks like `["A" -> [
46 * "B" ], "B" -> null]`. This is, the "new" article B is added and marked as
47 * non-analyzed.
49 * This is because of the implementation of the links as #std::weak_ptr - on
50 * serialization, they could still be in scope, but on deserialization, I
51 * need some #std::shared_ptr so the object doesn't disappear right away.
52 * This is why I deserialize them as new object in the collection.
54 void deserialize(CollectionUtils::ArticleCollection& collection,
55 std::istream& instream);
57 } // namespace WikiWalker
58 #endif // WIKIWALKER_JSONSERIALIZER_H