1 | // Licensed to the .NET Foundation under one or more agreements. |
---|---|
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | // ============================================================ |
5 | // |
6 | // AssemblyIdentityCache.hpp |
7 | // |
8 | |
9 | |
10 | // |
11 | // Defines the AssemblyIdentityCache class and its helpers |
12 | // |
13 | // ============================================================ |
14 | |
15 | #ifndef __BINDER__ASSEMBLY_IDENTITY_CACHE_HPP__ |
16 | #define __BINDER__ASSEMBLY_IDENTITY_CACHE_HPP__ |
17 | |
18 | #include "bindertypes.hpp" |
19 | #include "assemblyidentity.hpp" |
20 | #include "utils.hpp" |
21 | #include "sstring.h" |
22 | #include "shash.h" |
23 | |
24 | namespace BINDER_SPACE |
25 | { |
26 | class AssemblyIdentityCacheEntry |
27 | { |
28 | public: |
29 | inline AssemblyIdentityCacheEntry() |
30 | { |
31 | m_szTextualIdentity = NULL; |
32 | m_pAssemblyIdentity = NULL; |
33 | } |
34 | inline ~AssemblyIdentityCacheEntry() |
35 | { |
36 | SAFE_DELETE_ARRAY(m_szTextualIdentity); |
37 | SAFE_DELETE(m_pAssemblyIdentity); |
38 | } |
39 | |
40 | // Getters/Setters |
41 | inline LPCSTR GetTextualIdentity() |
42 | { |
43 | return m_szTextualIdentity; |
44 | } |
45 | inline void SetTextualIdentity(LPCSTR szTextualIdentity) |
46 | { |
47 | size_t len = strlen(szTextualIdentity) + 1; |
48 | |
49 | m_szTextualIdentity = new char[len]; |
50 | strcpy_s((LPSTR) m_szTextualIdentity, len, szTextualIdentity); |
51 | } |
52 | inline AssemblyIdentityUTF8 *GetAssemblyIdentity() |
53 | { |
54 | return m_pAssemblyIdentity; |
55 | } |
56 | inline void SetAssemblyIdentity(AssemblyIdentityUTF8 *pAssemblyIdentity) |
57 | { |
58 | m_pAssemblyIdentity = pAssemblyIdentity; |
59 | } |
60 | |
61 | protected: |
62 | LPCSTR m_szTextualIdentity; |
63 | AssemblyIdentityUTF8 *m_pAssemblyIdentity; |
64 | }; |
65 | |
66 | class AssemblyIdentityHashTraits : public DefaultSHashTraits<AssemblyIdentityCacheEntry *> |
67 | { |
68 | public: |
69 | typedef LPCSTR key_t; |
70 | |
71 | static key_t GetKey(element_t pAssemblyIdentityCacheEntry) |
72 | { |
73 | return pAssemblyIdentityCacheEntry->GetTextualIdentity(); |
74 | } |
75 | static BOOL Equals(key_t textualIdentity1, key_t textualIdentity2) |
76 | { |
77 | if ((textualIdentity1 == NULL) && (textualIdentity2 == NULL)) |
78 | return TRUE; |
79 | if ((textualIdentity1 == NULL) || (textualIdentity2 == NULL)) |
80 | return FALSE; |
81 | |
82 | return (strcmp(textualIdentity1, textualIdentity2) == 0); |
83 | } |
84 | static count_t Hash(key_t textualIdentity) |
85 | { |
86 | if (textualIdentity == NULL) |
87 | return 0; |
88 | else |
89 | return HashStringA(textualIdentity); |
90 | } |
91 | static element_t Null() |
92 | { |
93 | return NULL; |
94 | } |
95 | static bool IsNull(const element_t &assemblyIdentityCacheEntry) |
96 | { |
97 | return (assemblyIdentityCacheEntry == NULL); |
98 | } |
99 | |
100 | }; |
101 | |
102 | class AssemblyIdentityCache : protected SHash<AssemblyIdentityHashTraits> |
103 | { |
104 | private: |
105 | typedef SHash<AssemblyIdentityHashTraits> Hash; |
106 | public: |
107 | AssemblyIdentityCache(); |
108 | ~AssemblyIdentityCache(); |
109 | |
110 | HRESULT Add(/* in */ LPCSTR szTextualIdentity, |
111 | /* in */ AssemblyIdentityUTF8 *pAssemblyIdentity); |
112 | AssemblyIdentityUTF8 *Lookup(/* in */ LPCSTR szTextualIdentity); |
113 | }; |
114 | }; |
115 | |
116 | #endif |
117 |