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-2025 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#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wextra-semi"
22#pragma GCC diagnostic ignored "-Wsuggest-override"
23#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
24#ifdef __clang__
25#pragma clang diagnostic push
26#pragma clang diagnostic ignored "-Wsuggest-destructor-override"
27#endif
28#include <swkey.h>
29#include <swmodule.h>
30#include <treekeyidx.h>
31#ifdef __clang__
32#pragma clang diagnostic pop
33#endif
34#pragma GCC diagnostic pop
35
36
38 CSwordBackend & backend)
39 : CSwordModuleInfo(module, backend, CSwordModuleInfo::GenericBook)
40 , m_depth(
41 [this]{
42 if (auto * const key = tree()) {
43 key->root();
44 int maxDepth = 0;
45 for (int depth = 0;;) {
46 do {
47 while (key->firstChild()) {
48 ++depth;
49 }
50 } while (key->nextSibling());
51 if (depth > maxDepth)
52 maxDepth = depth;
53 do {
54 if (!key->parent())
55 return maxDepth;
56 --depth;
57 } while (!key->nextSibling());
58 }
59 }
60 return -1;
61 }())
62{}
63
64sword::TreeKeyIdx * CSwordBookModuleInfo::tree() const {
65 auto * const currentKey = swordModule().getKey();
66 BT_ASSERT(dynamic_cast<sword::TreeKeyIdx *>(currentKey));
67 return static_cast<sword::TreeKeyIdx *>(currentKey);
68}
69
71{ 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.