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

Go to the SVN repository for this file.

1 #ifndef PATHHOOK__HPP
2 #define PATHHOOK__HPP
3 
4 /* $Id: pathhook.hpp 78701 2017-07-12 15:58:51Z gouriano $
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 * Author: Andrei Gourianov
30 *
31 * File Description:
32 * Helper classes to set serialization hooks by stack path
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 
38 
39 /** @addtogroup ObjStreamSupport
40  *
41  * @{
42  */
43 
45 
46 class CItemInfo;
47 class CObjectStack;
48 class CTypeInfo;
49 
51  : protected multimap<CObjectStack*, pair<string, CRef<CObject> > >
52 {
53 public:
54  CPathHook(void);
55  ~CPathHook(void);
56 
57  bool IsEmpty(void) const {return m_Empty;}
58  bool SetHook(CObjectStack* stk, const string& path, CObject* hook);
59  CObject* GetHook(CObjectStack& stk) const;
60 
61  static bool Match(const string& mask, const string& path);
62 
63  void Erase(CObjectStack* stk) {
64  erase(stk);
65  }
66 private:
67  CObject* x_Get(CObjectStack& stk, const string& path) const;
68  bool m_Empty;
69  bool m_Regular;
70  bool m_All;
71  bool m_Wildcard;
72 };
73 
74 
76  : protected map<string,CRef<CObject> >
77 {
78 public:
79  CStreamPathHookBase(void);
80  ~CStreamPathHookBase(void);
81 
82  bool IsEmpty(void) const {return m_Empty;}
83  bool SetHook(const string& path, CObject* hook);
84  CObject* GetHook(CObjectStack& stk) const;
85 
86  static CTypeInfo* FindType(const CObjectStack& stk);
87  static CItemInfo* FindItem(const CObjectStack& stk);
88 private:
89  CObject* x_Get(const string& path) const;
90  bool m_Empty;
91  bool m_Regular;
92  bool m_All;
93  bool m_Member;
94  bool m_Wildcard;
95 };
96 
97 
98 template <typename TInfo, typename THook>
100 {
101 public:
102  void SetHook(const string& path, THook hook)
103  {
104  CStreamPathHookBase::SetHook(path,hook);
105  }
106  THook GetHook(CObjectStack& stk) const
107  {
108  return static_cast<THook>(CStreamPathHookBase::GetHook(stk));
109  }
110  static TInfo FindItem(const CObjectStack& stk)
111  {
112  return dynamic_cast<TInfo>(CStreamPathHookBase::FindItem(stk));
113  }
114 };
115 
116 
117 template <typename THook>
119 {
120 public:
121  void SetHook(const string& path, THook hook)
122  {
123  CStreamPathHookBase::SetHook(path,hook);
124  }
125  THook GetHook(CObjectStack& stk) const
126  {
127  return static_cast<THook>(CStreamPathHookBase::GetHook(stk));
128  }
129 };
130 
132 
133 #endif /* PATHHOOK__HPP */
134 
135 
136 /* @} */
ncbi::TMaskedQueryRegions mask
CObject –.
Definition: ncbiobj.hpp:180
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
void SetHook(const string &path, THook hook)
Definition: pathhook.hpp:102
CObject * GetHook(CObjectStack &stk) const
Definition: pathhook.cpp:237
bool m_All
Definition: pathhook.hpp:70
bool SetHook(const string &path, CObject *hook)
Definition: pathhook.cpp:212
static CItemInfo * FindItem(const CObjectStack &stk)
Definition: pathhook.cpp:278
THook GetHook(CObjectStack &stk) const
Definition: pathhook.hpp:106
void SetHook(const string &path, THook hook)
Definition: pathhook.hpp:121
bool m_Empty
Definition: pathhook.hpp:68
static TInfo FindItem(const CObjectStack &stk)
Definition: pathhook.hpp:110
bool m_Regular
Definition: pathhook.hpp:69
void Erase(CObjectStack *stk)
Definition: pathhook.hpp:63
THook GetHook(CObjectStack &stk) const
Definition: pathhook.hpp:125
bool IsEmpty(void) const
Definition: pathhook.hpp:57
bool m_Wildcard
Definition: pathhook.hpp:71
bool IsEmpty(void) const
Definition: pathhook.hpp:82
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Wed Feb 28 07:15:15 2024 by modify_doxy.py rev. 669887