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 // ============================================================
6 // AssemblyIdentityCache.hpp
11 // Defines the AssemblyIdentityCache class and its helpers
13 // ============================================================
15 #ifndef __BINDER__ASSEMBLY_IDENTITY_CACHE_HPP__
16 #define __BINDER__ASSEMBLY_IDENTITY_CACHE_HPP__
18 #include "bindertypes.hpp"
19 #include "assemblyidentity.hpp"
24 namespace BINDER_SPACE
26 class AssemblyIdentityCacheEntry
29 inline AssemblyIdentityCacheEntry()
31 m_szTextualIdentity = NULL;
32 m_pAssemblyIdentity = NULL;
34 inline ~AssemblyIdentityCacheEntry()
36 SAFE_DELETE_ARRAY(m_szTextualIdentity);
37 SAFE_DELETE(m_pAssemblyIdentity);
41 inline LPCSTR GetTextualIdentity()
43 return m_szTextualIdentity;
45 inline void SetTextualIdentity(LPCSTR szTextualIdentity)
47 size_t len = strlen(szTextualIdentity) + 1;
49 m_szTextualIdentity = new char[len];
50 strcpy_s((LPSTR) m_szTextualIdentity, len, szTextualIdentity);
52 inline AssemblyIdentityUTF8 *GetAssemblyIdentity()
54 return m_pAssemblyIdentity;
56 inline void SetAssemblyIdentity(AssemblyIdentityUTF8 *pAssemblyIdentity)
58 m_pAssemblyIdentity = pAssemblyIdentity;
62 LPCSTR m_szTextualIdentity;
63 AssemblyIdentityUTF8 *m_pAssemblyIdentity;
66 class AssemblyIdentityHashTraits : public DefaultSHashTraits<AssemblyIdentityCacheEntry *>
71 static key_t GetKey(element_t pAssemblyIdentityCacheEntry)
73 return pAssemblyIdentityCacheEntry->GetTextualIdentity();
75 static BOOL Equals(key_t textualIdentity1, key_t textualIdentity2)
77 if ((textualIdentity1 == NULL) && (textualIdentity2 == NULL))
79 if ((textualIdentity1 == NULL) || (textualIdentity2 == NULL))
82 return (strcmp(textualIdentity1, textualIdentity2) == 0);
84 static count_t Hash(key_t textualIdentity)
86 if (textualIdentity == NULL)
89 return HashStringA(textualIdentity);
91 static const element_t Null()
95 static bool IsNull(const element_t &assemblyIdentityCacheEntry)
97 return (assemblyIdentityCacheEntry == NULL);
102 class AssemblyIdentityCache : protected SHash<AssemblyIdentityHashTraits>
105 typedef SHash<AssemblyIdentityHashTraits> Hash;
107 AssemblyIdentityCache();
108 ~AssemblyIdentityCache();
110 HRESULT Add(/* in */ LPCSTR szTextualIdentity,
111 /* in */ AssemblyIdentityUTF8 *pAssemblyIdentity);
112 AssemblyIdentityUTF8 *Lookup(/* in */ LPCSTR szTextualIdentity);