1 /* Copyright © 2015-2019 Jakub Wilk <jwilk@jwilk.net>
2  *
3  * This file is part of pdf2djvu.
4  *
5  * pdf2djvu is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * pdf2djvu is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14 
15 #ifndef PDF2DJVU_DJVU_OUTLINE_H
16 #define PDF2DJVU_DJVU_OUTLINE_H
17 
18 #include <cstddef>
19 #include <ostream>
20 #include <stdexcept>
21 #include <string>
22 #include <vector>
23 
24 namespace djvu
25 {
26 
27     class OutlineError
28     : public std::runtime_error
29     {
30     public:
31         OutlineError();
32     };
33 
34     class OutlineItem;
35 
36     class OutlineBase
37     {
38     public:
39         virtual OutlineItem& add(std::string description, std::string url) = 0;
40         OutlineBase() = default;
41         OutlineBase(const OutlineBase &) = default;
~OutlineBase()42         virtual ~OutlineBase()
43         { }
44     };
45 
46     class OutlineItem
47     : public OutlineBase
48     {
49     public:
OutlineItem(std::string description,std::string url)50         OutlineItem(std::string description, std::string url)
51         : description(description),
52           url(url)
53         { }
54         OutlineItem& add(std::string description, std::string url);
55     private:
56         std::vector<OutlineItem> children;
57         std::string description;
58         std::string url;
59         size_t size() const;
60         friend std::ostream &operator<<(std::ostream &, const OutlineItem &);
61         friend class Outline;
62     };
63 
64     class Outline
65     : public OutlineBase
66     {
67     private:
68         std::vector<OutlineItem> items;
69         size_t size() const;
70     public:
71         OutlineItem& add(std::string description, std::string url);
72         operator bool() const;
73         friend std::ostream &operator<<(std::ostream &, const Outline &);
74     };
75 
76     std::ostream &operator<<(std::ostream &, const OutlineItem &);
77     std::ostream &operator<<(std::ostream &, const Outline &);
78 
79 }
80 
81 #endif
82 
83 // vim:ts=4 sts=4 sw=4 et
84