NCBI C++ ToolKit
priority.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef PRIORITY__HPP
2 #define PRIORITY__HPP
3 
4 /* $Id: priority.hpp 91808 2020-12-14 15:35:18Z grichenk $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Authors:
30 * Aleksey Grichenko
31 *
32 * File Description:
33 * Priority record for CObjectManager and CScope
34 *
35 */
36 
37 #include <corelib/ncbistd.hpp>
38 #include <corelib/ncbimtx.hpp>
39 #include <corelib/ncbiobj.hpp>
40 #include <map>
41 #include <memory>
42 
45 
46 
47 class CPriority_I;
48 class CTSE_Info;
49 class CScope_Impl;
50 class CDataSource;
52 
53 class CPriorityTree;
54 class CPriorityNode;
55 
57 {
58 public:
60 
61  CPriorityNode(void);
62  explicit CPriorityNode(TLeaf& leaf);
63  explicit CPriorityNode(const CPriorityTree& tree);
64  CPriorityNode(CScope_Impl& scope, const CPriorityNode& node);
65 
66  typedef int TPriority;
68 
69  // true if the node is a tree, not a leaf
70  bool IsTree(void) const;
71  bool IsLeaf(void) const;
72 
73  TLeaf& GetLeaf(void);
74  const TLeaf& GetLeaf(void) const;
75  CPriorityTree& GetTree(void);
76  const CPriorityTree& GetTree(void) const;
77 
78  // Set node type to "tree"
79  CPriorityTree& SetTree(void);
80  // Set node type to "leaf"
81  void SetLeaf(TLeaf& leaf);
82 
83  size_t Erase(const TLeaf& leaf);
84  bool IsEmpty(void) const; // true if node is null or empty tree
85  void Clear(void);
86 
87 private:
88 
91 };
92 
93 
95 {
96 public:
98 
99  CPriorityTree(void);
100  CPriorityTree(CScope_Impl& scope, const CPriorityTree& node);
101  ~CPriorityTree(void);
102 
105 
106  TPriorityMap& GetTree(void);
107  const TPriorityMap& GetTree(void) const;
108 
109  bool Insert(const CPriorityNode& node, TPriority priority);
110  bool Insert(const CPriorityTree& tree, TPriority priority);
111  bool Insert(TLeaf& leaf, TPriority priority);
112 
113  size_t Erase(const TLeaf& leaf);
114 
115  bool IsEmpty(void) const; // true if map is empty
116  bool HasSeveralNodes(void); // true if tree has more than one node
117  void Clear(void);
118 
119 private:
120 
122 };
123 
124 
126 {
127 public:
128  CPriority_I(void);
130 
132  typedef TLeaf value_type;
133 
135 
136  value_type& operator*(void) const;
137  value_type* operator->(void) const;
138 
139  const CPriority_I& operator++(void);
140 
141  const CPriority_I& InsertBefore(TLeaf& leaf);
142 
143 private:
145  CPriority_I& operator= (const CPriority_I&);
146 
149 
153  unique_ptr<CPriority_I> m_Sub_I;
154 };
155 
156 
157 // CPriorityTree inline methods
158 
159 inline
161 {
162  return m_Map;
163 }
164 
165 inline
167 {
168  return m_Map;
169 }
170 
171 inline
172 bool CPriorityTree::IsEmpty(void) const
173 {
174  return m_Map.empty();
175 }
176 
177 
178 // CPriorityNode inline methods
179 
180 inline
181 bool CPriorityNode::IsTree(void) const
182 {
183  return m_SubTree.NotEmpty();
184 }
185 
186 inline
187 bool CPriorityNode::IsLeaf(void) const
188 {
189  return m_Leaf.NotEmpty();
190 }
191 
192 inline
194 {
195  _ASSERT(IsLeaf());
196  return *m_Leaf;
197 }
198 
199 inline
201 {
202  _ASSERT(IsLeaf());
203  return *m_Leaf;
204 }
205 
206 inline
208 {
209  _ASSERT(IsTree());
210  return *m_SubTree;
211 }
212 
213 inline
215 {
216  _ASSERT(IsTree());
217  return *m_SubTree;
218 }
219 
220 inline
221 bool CPriorityNode::IsEmpty(void) const
222 {
223  return !IsLeaf() && (!IsTree() || m_SubTree->IsEmpty());
224 }
225 
226 
227 // CPriority_I inline methods
228 
229 inline
231 {
232  _ASSERT(m_Node && (m_Node->IsTree() || m_Node->IsLeaf()));
233  if (m_Sub_I.get()) {
234  return **m_Sub_I;
235  }
236  return m_Node->GetLeaf();
237 }
238 
239 inline
241 {
242  return &this->operator *();
243 }
244 
247 
248 #endif // PRIORITY__HPP
CObject –.
Definition: ncbiobj.hpp:180
bool IsTree(void) const
Definition: priority.hpp:181
TLeaf & GetLeaf(void)
Definition: priority.hpp:193
CDataSource_ScopeInfo TLeaf
Definition: priority.hpp:59
bool IsEmpty(void) const
Definition: priority.hpp:221
CPriorityTree & GetTree(void)
Definition: priority.hpp:207
bool IsLeaf(void) const
Definition: priority.hpp:187
multimap< TPriority, CPriorityNode > TPriorityMap
Definition: priority.hpp:67
CRef< TLeaf > m_Leaf
Definition: priority.hpp:90
CRef< CPriorityTree > m_SubTree
Definition: priority.hpp:89
CPriorityNode::TPriority TPriority
Definition: priority.hpp:103
bool IsEmpty(void) const
Definition: priority.hpp:172
multimap< TPriority, CPriorityNode > TPriorityMap
Definition: priority.hpp:104
TPriorityMap & GetTree(void)
Definition: priority.hpp:160
CDataSource_ScopeInfo TLeaf
Definition: priority.hpp:97
TPriorityMap m_Map
Definition: priority.hpp:121
value_type * operator->(void) const
Definition: priority.hpp:240
value_type & operator*(void) const
Definition: priority.hpp:230
CPriorityTree::TPriorityMap TPriorityMap
Definition: priority.hpp:147
CPriorityNode * m_Node
Definition: priority.hpp:152
DECLARE_OPERATOR_BOOL_PTR(m_Node)
unique_ptr< CPriority_I > m_Sub_I
Definition: priority.hpp:153
CPriority_I(const CPriority_I &)
TLeaf value_type
Definition: priority.hpp:132
TPriorityMap * m_Map
Definition: priority.hpp:150
TMap_I m_Map_I
Definition: priority.hpp:151
CPriorityNode::TLeaf TLeaf
Definition: priority.hpp:131
TPriorityMap::iterator TMap_I
Definition: priority.hpp:148
bool empty() const
Definition: map.hpp:289
Include a standard set of the NCBI C++ Toolkit most basic headers.
boolean leaf(meNode *v)
Definition: graph.cpp:44
CVect2< NCBI_PROMOTE(int,U) > operator*(int v1, const CVect2< U > &v2)
Definition: globals.hpp:371
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
Multi-threading – mutexes; rw-locks; semaphore.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
#define _ASSERT
Modified on Mon Jun 10 04:52:12 2024 by modify_doxy.py rev. 669887