1 #ifndef HOOKDATAKEY__HPP
2 #define HOOKDATAKEY__HPP
3 
4 /*  $Id: hookdatakey.hpp 184468 2010-03-01 15:45:11Z 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: Eugene Vasilchenko
30 *
31 * File Description:
32 *   !!! PUT YOUR DESCRIPTION HERE !!!
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 
38 #include <vector>
39 
40 /** @addtogroup HookSupport
41  *
42  * @{
43  */
44 
45 
46 BEGIN_NCBI_SCOPE
47 
48 class CHookDataBase;
49 
50 class NCBI_XSERIAL_EXPORT CLocalHookSetBase
51 {
52 public:
53     typedef CHookDataBase THookData;
54     typedef CObject THook;
55 
56     CLocalHookSetBase(void);
57     ~CLocalHookSetBase(void);
58 
59     void Clear(void);
IsEmpty(void) const60     bool IsEmpty(void) const
61     {
62         return m_Hooks.empty();
63     }
64 
65     typedef pair<THookData*, CRef<THook> > TValue;
66     typedef vector<TValue> THooks;
67 
68 protected:
69     void ResetHook(THookData* key);
70     void SetHook(THookData* key, THook* hook);
71     const THook* GetHook(const THookData* key) const;
72 
73 private:
74     CLocalHookSetBase(const CLocalHookSetBase&);
75     CLocalHookSetBase& operator=(const CLocalHookSetBase&);
76 
77     friend class CHookDataBase;
78 
79     struct Compare
80     {
operator ()CLocalHookSetBase::Compare81         bool operator()(const TValue& v1, const TValue& v2) const
82             {
83                 return v1.first < v2.first;
84             }
operator ()CLocalHookSetBase::Compare85 	bool operator()(const THookData* key, const TValue& value) const
86             {
87                 return key < value.first;
88             }
operator ()CLocalHookSetBase::Compare89         bool operator()(const TValue& value, const THookData* key) const
90             {
91                 return value.first < key;
92             }
93     };
94 
95     THooks::iterator x_Find(const THookData* key);
96     THooks::const_iterator x_Find(const THookData* key) const;
97     bool x_Found(THooks::const_iterator it, const THookData* key) const;
98 
99     THooks m_Hooks;
100 };
101 
102 
103 template<class Hook>
104 class CLocalHookSet : public CLocalHookSetBase
105 {
106     typedef CLocalHookSetBase CParent;
107 public:
108     typedef CParent::THookData THookData;
109     typedef Hook THook;
110 
111 protected:
112     friend class CHookDataBase;
SetHook(THookData * key,THook * hook)113     void SetHook(THookData* key, THook* hook)
114         {
115             CParent::SetHook(key, hook);
116         }
GetHook(THookData * key) const117     THook* GetHook(THookData* key) const
118         {
119             return static_cast<THook*>(CParent::GetHook(key));
120         }
121 };
122 
123 END_NCBI_SCOPE
124 
125 #endif  /* HOOKDATAKEY__HPP */
126 
127 
128 /* @} */
129