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// PropertyMap.hpp
7//
8
9
10//
11// Defines the PropertyMap class
12//
13// ============================================================
14
15#ifndef __BINDER__PROPERTY_HASH_TRAITS_HPP__
16#define __BINDER__PROPERTY_HASH_TRAITS_HPP__
17
18#include "bindertypes.hpp"
19#include "sstring.h"
20#include "shash.h"
21
22namespace BINDER_SPACE
23{
24 class PropertyEntry
25 {
26 public:
27 inline PropertyEntry()
28 {
29 m_pPropertyName = NULL;
30 m_pPropertyValue = NULL;
31 }
32 inline ~PropertyEntry()
33 {
34 SAFE_DELETE(m_pPropertyName);
35 SAFE_DELETE(m_pPropertyValue);
36 }
37
38 // Getters/Setters
39 inline SString *GetPropertyName()
40 {
41 return m_pPropertyName;
42 }
43 inline void SetPropertyName(SString *pPropertyName)
44 {
45 SAFE_DELETE(m_pPropertyName);
46 m_pPropertyName = pPropertyName;
47 }
48 inline SBuffer *GetPropertyValue()
49 {
50 return m_pPropertyValue;
51 }
52 inline void SetPropertyValue(SBuffer *pPropertyValue)
53 {
54 SAFE_DELETE(m_pPropertyValue);
55 m_pPropertyValue = pPropertyValue;
56 }
57
58 protected:
59 SString *m_pPropertyName;
60 SBuffer *m_pPropertyValue;
61 };
62
63 class PropertyHashTraits : public DefaultSHashTraits<PropertyEntry *>
64 {
65 public:
66 typedef SString* key_t;
67
68 // GetKey, Equals, and Hash can throw due to SString
69 static const bool s_NoThrow = false;
70
71 static key_t GetKey(element_t pPropertyEntry)
72 {
73 return pPropertyEntry->GetPropertyName();
74 }
75 static BOOL Equals(key_t pPropertyName1, key_t pPropertyName2)
76 {
77 return pPropertyName1->Equals(*pPropertyName2);
78 }
79 static count_t Hash(key_t pPropertyName)
80 {
81 return pPropertyName->Hash();
82 }
83 static element_t Null()
84 {
85 return NULL;
86 }
87 static bool IsNull(const element_t &propertyEntry)
88 {
89 return (propertyEntry == NULL);
90 }
91
92 };
93};
94
95#endif
96