BibleTime
cswordtreekey.h
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-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #pragma once
14 
15 #include "cswordkey.h"
16 
17 #include <QString>
18 #include <type_traits>
19 
20 // Sword includes:
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 #ifdef __clang__
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wsuggest-destructor-override"
28 #endif
29 #include <treekeyidx.h>
30 #ifdef __clang__
31 #pragma clang diagnostic pop
32 #endif
33 #pragma GCC diagnostic pop
34 
35 
36 class CSwordModuleInfo;
37 
38 /** BibleTime's implementation of Sword's TreeKeyIdx class.
39  * @short CSwordKey implementation for Sword's TreeKey
40  * @author The BibleTime team
41  */
42 
43 class CSwordTreeKey final : public CSwordKey {
44 
45  public: // types:
46 
47  using Offset =
48  decltype(std::declval<sword::TreeKeyIdx const &>().getOffset());
49 
50  public:
51 
52  #define BibleTime_CSwordTreeKey_DEFINE_COMP(op) \
53  friend bool operator op(CSwordTreeKey const & lhs, \
54  CSwordTreeKey const & rhs) \
55  { return lhs.offset() op rhs.offset(); }
56  #if __cpp_impl_three_way_comparison >= 201907L
58  #else
65  #endif
66  #undef BibleTime_CSwordTreeKey_DEFINE_COMP
67 
68  CSwordTreeKey & operator=(CSwordTreeKey const &) = delete;
69 
70  /**
71  \param k The Sword tree key which belongs to this key
72  \param module The module which belongs to this key
73  */
74  CSwordTreeKey(const sword::TreeKeyIdx *k,
75  const CSwordModuleInfo *module);
76 
77  CSwordTreeKey( const CSwordTreeKey& k );
78 
79  sword::TreeKeyIdx const & asSwordKey() const noexcept final override;
80 
81  void setModule(const CSwordModuleInfo *newModule) final override;
82 
83  CSwordTreeKey* copy() const final override;
84 
85  /**
86  * Returns the TreeKeyIdx::getLocalKey value in unicode.
87  * Local key is the last part of the tree key, for example "Subsection1" from "/Section1/Subsection1".
88  * Use this instead of getLocalKey() to avoid encoding problems.
89  */
90  QString getLocalNameUnicode();
91 
92  QString key() const final override;
93 
94  bool setKey(const QString &key) final override;
95 
96  bool setKey(const char *key) final override;
97 
98  bool hasChildren() { return m_key.hasChildren(); }
99  void positionToRoot() { m_key.root(); }
100  bool positionToParent() { return m_key.parent(); }
101  bool positionToFirstChild() { return m_key.firstChild(); }
102  bool positionToNextSibling() { return m_key.nextSibling(); }
103  Offset offset() const { return m_key.getOffset(); }
104  void setOffset(Offset value) { m_key.setOffset(value); }
105 
106  protected:
107 
108  const char * rawKey() const final override;
109 
110  private: // fields:
111 
112  sword::TreeKeyIdx m_key;
113 
114 };
CSwordKey & operator=(CSwordKey const &)=delete
CSwordModuleInfo const * module() const
Definition: cswordkey.h:68
CSwordKey implementation for Sword's TreeKey.
Definition: cswordtreekey.h:43
void positionToRoot()
Definition: cswordtreekey.h:99
bool positionToFirstChild()
bool hasChildren()
Definition: cswordtreekey.h:98
bool positionToNextSibling()
const char * rawKey() const final override
bool positionToParent()
QString getLocalNameUnicode()
QString key() const final override
Offset offset() const
bool setKey(const QString &key) final override
void setModule(const CSwordModuleInfo *newModule) final override
CSwordTreeKey(const sword::TreeKeyIdx *k, const CSwordModuleInfo *module)
decltype(std::declval< sword::TreeKeyIdx const & >().getOffset()) Offset
Definition: cswordtreekey.h:48
sword::TreeKeyIdx const & asSwordKey() const noexcept final override
void setOffset(Offset value)
BibleTime_CSwordTreeKey_DEFINE_COMP(<) BibleTime_CSwordTreeKey_DEFINE_COMP(<
sword::TreeKeyIdx m_key
CSwordTreeKey * copy() const final override