1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <sal/types.h>
24 #include <rtl/ustring.hxx>
30 * Node represents a node within a LookupTree. As en external caller, you
31 * should never have to do anything with this class directly.
32 * Use any of the classes derived from LookupTree instead for constructing a
38 //explicit Node(TreeHead* const pHead);
39 explicit Node(TreeHead
* const pHead
, Node
* const pParent
= NULL
,
40 const sal_Unicode cKey
= 0, const int nProbability
= 0);
44 // Removes the specified child from this node. Make sure you may remove it
46 void removeChild(Node
*& pChild
);
48 // Inserts a complete keyword starting from this node of the tree.
49 void insertKey(OUString sKey
, const int nProbability
);
50 // Removes a complete keyword starting from this node of the tree.
51 void removeKey(OUString sKey
);
53 // Returns the child node keyed with cKey.
54 Node
* advanceKey(const sal_Unicode cKey
);
56 // Use this to inform a parent about its child having changed.
57 // Call this only with nProbability = 0 if you have made sure the node can
59 void childHasChanged(Node
* pChild
, const int nProbability
, bool bAllowRemoval
= false);
61 // Rechose the node that is suggested for auto-completion
62 void reevaluateSuggestion(bool& bNodeProbabilityChanged
);
65 /* =================== Virtuals =================== */
66 virtual bool isSeparatedlyHandled(const sal_Unicode cKey
) const = 0;
68 // Returns a reference to the pointer to the child node for the requested
69 // char. Returns NULL if no such child could be found.
70 // IMPORTANT: In the latter case, you may NOT overwrite the return value,
71 // if you did not set bCreatePlaceholder to true.
72 virtual Node
*& getChildRef(const sal_Unicode cKey
, bool bCreatePlaceholder
= false) = 0;
74 // Sets nSuggest to the highest probability within the subtree and pSuggest
75 // to point to the (first) node with this probability.
76 virtual void evaluateSeparateStorage(int& nSuggest
, Node
*& pSuggest
) const = 0;
78 // Removes all child nodes and clears all memory.
79 virtual void freeMemory() = 0;
81 /* =================== Member Variables =================== */
82 const sal_Unicode m_cKey
; // the char represented by this node
83 int m_nKeyProbability
; // the number of occurrences of this key
85 // the highest KeyProbability in the tree sprouting from this node
86 int m_nHighestProbaInSubtree
;
88 Node
* const m_pParent
; // the parent of this node
89 Node
* m_pSuggest
; // next node in chain to the suggested autocompletion
91 TreeHead
* const m_pHead
; // head of the tree
93 unsigned short m_nChildren
; // the number of children of the node
94 std::list
<Node
*> m_lChildren
; // all chars not handled by array
96 // Allows returning a reference to a valid Null pointer. May NOT be overwritten.
97 static Node
* our_pNodeNullPointer
;
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */