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

Go to the SVN repository for this file.

1 #ifndef OBJMGR_IMPL_HEAP_SCOPE__HPP
2 #define OBJMGR_IMPL_HEAP_SCOPE__HPP
3 
4 /* $Id: heap_scope.hpp 87148 2019-07-30 16:13:15Z vasilche $
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 * Eugene Vasilchenko
31 *
32 * File Description:
33 * CHeapScope is internal holder of CScope_Impl object
34 *
35 */
36 
37 #include <corelib/ncbiobj.hpp>
38 
41 
42 // objmgr
43 class CScope;
44 class CHeapScope;
45 class CScope_Impl;
46 
47 /////////////////////////////////////////////////////////////////////////////
48 // CHeapScope
49 // Holds reference on heap scope object
50 // used internally in interface classes (iterators, handles etc)
51 /////////////////////////////////////////////////////////////////////////////
52 
54 {
55 public:
56  CHeapScope(void)
57  {
58  }
59  explicit CHeapScope(CScope& scope)
60  {
61  Set(&scope);
62  }
63  explicit CHeapScope(CScope* scope)
64  {
65  Set(scope);
66  }
67 
68  // check is scope is not null
69  bool IsSet(void) const
70  {
71  return m_Scope.NotEmpty();
72  }
73  bool IsNull(void) const
74  {
75  return !m_Scope;
76  }
77 
79 
80  bool operator==(const CHeapScope& scope) const
81  {
82  return m_Scope == scope.m_Scope;
83  }
84  bool operator!=(const CHeapScope& scope) const
85  {
86  return m_Scope != scope.m_Scope;
87  }
88  bool operator<(const CHeapScope& scope) const
89  {
90  return m_Scope < scope.m_Scope;
91  }
92 
93  // scope getters
94  NCBI_XOBJMGR_EXPORT CScope& GetScope(void) const;
96  operator CScope&(void) const
97  {
98  return GetScope();
99  }
100  operator CScope*(void) const
101  {
102  return &GetScope();
103  }
104  CScope& operator*(void) const
105  {
106  return GetScope();
107  }
108 
109  // scope impl getters
111 
112  operator CScope_Impl*(void) const
113  {
114  return GetImpl();
115  }
116  CScope_Impl* operator->(void) const
117  {
118  return GetImpl();
119  }
120 
121 
122  NCBI_XOBJMGR_EXPORT void Set(CScope* scope);
123  void Reset(void)
124  {
125  m_Scope.Reset();
126  }
127 
128  void Swap(CHeapScope& scope)
129  {
130  m_Scope.Swap(scope.m_Scope);
131  }
132 
133 private:
134  // the reference has to be CObject* to avoid circular header dep.
136 };
137 
138 
139 /////////////////////////////////////////////////////////////////////////////
140 // inline methods
141 /////////////////////////////////////////////////////////////////////////////
142 
143 
146 
147 #endif//OBJMGR_IMPL_HEAP_SCOPE__HPP
CRef< CObject > m_Scope
Definition: heap_scope.hpp:135
CHeapScope(void)
Definition: heap_scope.hpp:56
CScope_Impl * GetImpl(void) const
Definition: heap_scope.cpp:80
void Swap(CHeapScope &scope)
Definition: heap_scope.hpp:128
bool operator!=(const CHeapScope &scope) const
Definition: heap_scope.hpp:84
bool IsNull(void) const
Definition: heap_scope.hpp:73
CHeapScope(CScope *scope)
Definition: heap_scope.hpp:63
void Reset(void)
Definition: heap_scope.hpp:123
bool IsSet(void) const
Definition: heap_scope.hpp:69
CScope * GetScopeOrNull(void) const
Definition: heap_scope.cpp:74
DECLARE_OPERATOR_BOOL_REF(m_Scope)
void Set(CScope *scope)
Definition: heap_scope.cpp:56
CScope & GetScope(void) const
Definition: heap_scope.cpp:68
bool operator<(const CHeapScope &scope) const
Definition: heap_scope.hpp:88
CHeapScope(CScope &scope)
Definition: heap_scope.hpp:59
CScope & operator*(void) const
Definition: heap_scope.hpp:104
bool operator==(const CHeapScope &scope) const
Definition: heap_scope.hpp:80
CScope_Impl * operator->(void) const
Definition: heap_scope.hpp:116
CScope –.
Definition: scope.hpp:92
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
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
void Swap(TThisType &ref)
Swaps the pointer with another reference.
Definition: ncbiobj.hpp:754
#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
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Wed May 22 11:33:19 2024 by modify_doxy.py rev. 669887