CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
keyvalue_pair.h
1
2#pragma once
3
4#include "system/get_hash_code.h"
5#include <system/boxed_value.h>
6
7#include <utility>
8
9namespace System {
10namespace Collections {
11namespace Generic {
12
18template<typename TKey, typename TValue>
19class ASPOSECPP_SHARED_CLASS KeyValuePair
20{
21public:
23 std::pair<TKey, TValue> m_pair;
24
30 KeyValuePair(const TKey& key, const TValue& value) : m_pair(key, value) {}
35 template <typename OtherK, typename OtherV>
36 KeyValuePair(const std::pair<OtherK, OtherV>& pair) : m_pair(pair) {}
37
40 const TKey& get_Key() const { return m_pair.first; }
43 const TValue& get_Value() const { return m_pair.second; }
44
46 bool IsNull() const { return false; }
47
51 bool operator < (const KeyValuePair& kvp) const
52 {
53 return false;
54 }
58 {
59 return u"[" + ToStringHelper(get_Key()) + u", " + ToStringHelper(get_Value()) + u"]";
60 }
63 int GetHashCode() const
64 {
65 return (System::GetHashCode(get_Key()) ^ System::GetHashCode(get_Value()));
66 }
67
68#ifdef ASPOSE_GET_SHARED_MEMBERS
69 void PopulateSharedMembers(Object::shared_members_type& result) const
70 {
71 result.Add("KeyValuePair::Key", this->m_pair.first);
72 result.Add("KeyValuePair::Value", this->m_pair.second);
73 }
74#endif
75
76private:
81 template<class C>
82 static typename std::enable_if<std::is_arithmetic<C>::value || std::is_enum<C>::value, String>::type
83 ToStringHelper(const C& value)
84 {
85 return String::Format(u"{0}", value);
86 }
91 template<typename C>
92 static typename std::enable_if<(!std::is_arithmetic<C>::value && !std::is_enum<C>::value && !IsSmartPtr<C>::value), String>::type
93 ToStringHelper(const C& obj)
94 {
95 return obj.ToString();
96 }
101 template<typename C>
102 static typename std::enable_if<IsSmartPtr<C>::value, String>::type
103 ToStringHelper(const C& obj)
104 {
105 if (obj == nullptr)
106 return u"nullptr";
107 return obj.GetObjectOrNull()->ToString();
108 }
112 static String ToStringHelper(const String& s)
113 {
114 return s;
115 }
116
117};
118
125template<typename TKey, typename TValue>
127{
128 return System::Details::AreEqual(left.get_Key(), right.get_Key()) && System::Details::AreEqual(left.get_Value(), right.get_Value());
129}
130
137template<typename TKey, typename TValue>
139{
140 return ! (left == right);
141}
142
149template<typename TKey, typename TValue>
150std::ostream& operator<<(std::ostream& stream, const KeyValuePair<TKey, TValue>& pair)
151{
152 stream << pair.ToString();
153 return stream;
154}
155
162template<typename TKey, typename TValue>
163std::wostream& operator<<(std::wostream& stream, const KeyValuePair<TKey, TValue>& pair)
164{
165 stream << pair.ToString();
166 return stream;
167}
168
169} // namespace Generic
170} // namespace Collections
171} // namespace System
172
173
174namespace System
175{
176
178
182template<typename TKey, typename TValue> struct IsBoxable<Collections::Generic::KeyValuePair<TKey, TValue>> : std::true_type {};
183
187template<typename TKey, typename TValue>
188class BoxedValue<System::Collections::Generic::KeyValuePair<TKey, TValue>> : public DefaultBoxedValue<System::Collections::Generic::KeyValuePair<TKey, TValue>>
189{
190public:
194 : DefaultBoxedValue<System::Collections::Generic::KeyValuePair<TKey, TValue>>(value)
195 {}
196};
197
199
200}
201
202namespace std{
203
207template<typename TKey, typename TValue>
208struct hash<System::Collections::Generic::KeyValuePair<TKey, TValue> >
209{
213 std::size_t operator()(const System::Collections::Generic::KeyValuePair<TKey, TValue> & kvp) const
214 {
216 }
217};
218
219}
BoxedValue(const T &value)
Constructs an object that represents the specified value boxed.
Definition: boxed_value.h:192
Pair of key and value. This type should be allocated on stack and passed to functions by value or by ...
Definition: keyvalue_pair.h:20
int GetHashCode() const
Calculates key-value pair hash by xoring key's and value's hashes.
Definition: keyvalue_pair.h:63
const TKey & get_Key() const
Gets key.
Definition: keyvalue_pair.h:40
KeyValuePair()
Null key-value pair initializer.
Definition: keyvalue_pair.h:26
bool IsNull() const
Always returns false.
Definition: keyvalue_pair.h:46
String ToString() const
Converts key-value pair to string.
Definition: keyvalue_pair.h:57
KeyValuePair(const TKey &key, const TValue &value)
Constructor.
Definition: keyvalue_pair.h:30
KeyValuePair(const std::pair< OtherK, OtherV > &pair)
Type conversion constructor.
Definition: keyvalue_pair.h:36
const TValue & get_Value() const
Gets value.
Definition: keyvalue_pair.h:43
std::pair< TKey, TValue > m_pair
Internal data structure.
Definition: keyvalue_pair.h:23
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
static String Format(const SharedPtr< IFormatProvider > &fp, const String &format, const Args &... args)
Formats string in C# style.
Definition: string.h:1405
String ToString() const
Wrapper for handling String class in contexts where ToString() is being called on value type objects.
Definition: string.h:494
std::ostream & operator<<(std::ostream &stream, const KeyValuePair< TKey, TValue > &pair)
Insert data into the stream using UTF-8 encoding.
Definition: keyvalue_pair.h:150
bool operator!=(const KeyValuePair< TKey, TValue > &left, const KeyValuePair< TKey, TValue > &right)
Compares two key-value pairs using inverse 'equals' semantics.
Definition: keyvalue_pair.h:138
bool operator==(const KeyValuePair< TKey, TValue > &left, const KeyValuePair< TKey, TValue > &right)
Compares two key-value pairs using 'equals' semantics. Uses operator == or EqualsTo method for both k...
Definition: keyvalue_pair.h:126
Definition: db_command.h:9
std::enable_if< std::is_scalar< T >::value, int >::type GetHashCode(const T &obj)
Returns a hash code for the specified scalar value.
Definition: get_hash_code.h:21
constexpr bool operator<(std::nullptr_t, DateTime)
Definition: date_time.h:712
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1499