BibleTime
cswordbookmoduleinfo.cpp
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2026 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
14
15#include <QByteArray>
16#include "../../util/btassert.h"
17#include "../keys/cswordtreekey.h"
18
19// Sword includes:
20#ifdef __GNUC__
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wextra-semi"
23#pragma GCC diagnostic ignored "-Wsuggest-override"
24#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
25#endif
26#ifdef __clang__
27#pragma clang diagnostic push
28#pragma clang diagnostic ignored "-Wsuggest-destructor-override"
29#endif
30#include <swkey.h>
31#include <swmodule.h>
32#include <treekeyidx.h>
33#ifdef __clang__
34#pragma clang diagnostic pop
35#endif
36#ifdef __GNUC__
37#pragma GCC diagnostic pop
38#endif
39
40
42 CSwordBackend & backend)
43 : CSwordModuleInfo(module, backend, CSwordModuleInfo::GenericBook)
44 , m_depth(
45 [this]{
46 if (auto * const key = tree()) {
47 key->root();
48 int maxDepth = 0;
49 for (int depth = 0;;) {
50 do {
51 while (key->firstChild()) {
52 ++depth;
53 }
54 } while (key->nextSibling());
55 if (depth > maxDepth)
56 maxDepth = depth;
57 do {
58 if (!key->parent())
59 return maxDepth;
60 --depth;
61 } while (!key->nextSibling());
62 }
63 }
64 return -1;
65 }())
66{}
67
68sword::TreeKeyIdx * CSwordBookModuleInfo::tree() const {
69 auto * const currentKey = swordModule().getKey();
70 BT_ASSERT(dynamic_cast<sword::TreeKeyIdx *>(currentKey));
71 return static_cast<sword::TreeKeyIdx *>(currentKey);
72}
73
75{ return new CSwordTreeKey(tree(), this); }
#define BT_ASSERT(...)
Definition btassert.h:17
The backend layer main class, a backend implementation of Sword.
sword::TreeKeyIdx * tree() const
int depth() const noexcept
CSwordBookModuleInfo(sword::SWModule &module, CSwordBackend &usedBackend)
CSwordKey * createKey() const final override
sword::SWModule & swordModule() const
CSwordKey implementation for Sword's TreeKey.