Debian Codegraph @

src/ApvlvInfo.h

raw
1 /*
2 * This file is part of the apvlv package
3 * Copyright (C) <2008> <Alf>
4 *
5 * Contact: Alf <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22 /* @CPPFILE ApvlvInfo.h
23 *
24 * Author: Alf <[email protected]>
25 */
26
27 #ifndef _APVLV_INFO_H_
28 #define _APVLV_INFO_H_
29
30 #include <deque>
31 #include <optional>
32 #include <string>
33
34 namespace apvlv
35 {
36
37 struct InfoFile
38 {
39 int page;
40 int skip;
41 double rate;
42 std::string file;
43 };
44
45 const int DEFAULT_MAX_INFO = 100;
46
47 class ApvlvInfo final
48 {
49 public:
50 ApvlvInfo (const ApvlvInfo &) = delete;
51 ApvlvInfo &operator= (const ApvlvInfo &) = delete;
52 void loadFile (std::string_view file);
53 bool update ();
54
55 std::optional<InfoFile *> lastFile ();
56 std::optional<InfoFile *> file (const std::string &filename);
57 bool updateFile (int page, int skip, double rate,
58 const std::string &filename);
59
60 static ApvlvInfo *
61 instance ()
62 {
63 static ApvlvInfo inst;
64 return &inst;
65 }
66
67 private:
68 ApvlvInfo ();
69 ~ApvlvInfo () = default;
70
71 std::string mFileName{};
72
73 std::deque<InfoFile> mInfoFiles{};
74 std::deque<InfoFile>::size_type mMaxInfo{ DEFAULT_MAX_INFO };
75
76 bool addPosition (const char *str);
77 };
78 };
79
80 #endif
81
82 /* Local Variables: */
83 /* mode: c++ */
84 /* End: */