summaryrefslogtreecommitdiff
path: root/dev-cpp/cpprestsdk/files/cpprestsdk-2.10.19-llvm-json-unique-ptr.patch
blob: ce7f03741b0b4d388564a7dd9d76417e6f2b94b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
This patch moves the implementations of certain json-methods to the cpp-file-implementations.
This is needed because llvm needs sizeof(T) to be valid for a lot more methods on containers
and std::unique_ptr, so these methods can't be header only on llvm. This patch is developed 
by me and I cannot right now find an upstream bug-report on this just yet. I uploaded a similar 
patch to FreeBSD ports a while ago. 
--- a/Release/include/cpprest/json.h
+++ b/Release/include/cpprest/json.h
@@ -737,12 +737,10 @@
     _ASYNCRTIMP void format(std::basic_string<char>& string) const;
 
 #ifdef ENABLE_JSON_VALUE_VISUALIZER
-    explicit value(std::unique_ptr<details::_Value> v, value_type kind) : m_value(std::move(v)), m_kind(kind)
+    explicit value(std::unique_ptr<details::_Value> v, value_type kind);
 #else
-    explicit value(std::unique_ptr<details::_Value> v) : m_value(std::move(v))
+    explicit value(std::unique_ptr<details::_Value> v);
 #endif
-    {
-    }
 
     std::unique_ptr<details::_Value> m_value;
 #ifdef ENABLE_JSON_VALUE_VISUALIZER
@@ -831,9 +829,9 @@
     typedef storage_type::size_type size_type;
 
 private:
-    array() : m_elements() {}
-    array(size_type size) : m_elements(size) {}
-    array(storage_type elements) : m_elements(std::move(elements)) {}
+    array();
+    array(size_type size);
+    array(storage_type elements);
 
 public:
     /// <summary>
@@ -915,20 +913,13 @@
     /// <returns>Iterator to the new location of the element following the erased element.</returns>
     /// <remarks>GCC doesn't support erase with const_iterator on vector yet. In the future this should be
     /// changed.</remarks>
-    iterator erase(iterator position) { return m_elements.erase(position); }
+    iterator erase(iterator position);
 
     /// <summary>
     /// Deletes the element at an index of the JSON array.
     /// </summary>
     /// <param name="index">The index of the element to delete.</param>
-    void erase(size_type index)
-    {
-        if (index >= m_elements.size())
-        {
-            throw json_exception("index out of bounds");
-        }
-        m_elements.erase(m_elements.begin() + index);
-    }
+    void erase(size_type index);
 
     /// <summary>
     /// Accesses an element of a JSON array. Throws when index out of bounds.
@@ -959,15 +950,7 @@
     /// </summary>
     /// <param name="index">The index of an element in the JSON array.</param>
     /// <returns>A reference to the value kept in the field.</returns>
-    json::value& operator[](size_type index)
-    {
-        msl::safeint3::SafeInt<size_type> nMinSize(index);
-        nMinSize += 1;
-        msl::safeint3::SafeInt<size_type> nlastSize(m_elements.size());
-        if (nlastSize < nMinSize) m_elements.resize((size_type)nMinSize);
-
-        return m_elements[index];
-    }
+    json::value& operator[](size_type index);
 
     /// <summary>
     /// Gets the number of elements of the array.
@@ -998,14 +981,8 @@
     typedef storage_type::size_type size_type;
 
 private:
-    object(bool keep_order = false) : m_elements(), m_keep_order(keep_order) {}
-    object(storage_type elements, bool keep_order = false) : m_elements(std::move(elements)), m_keep_order(keep_order)
-    {
-        if (!keep_order)
-        {
-            sort(m_elements.begin(), m_elements.end(), compare_pairs);
-        }
-    }
+    object(bool keep_order = false);
+    object(storage_type elements, bool keep_order = false);
 
 public:
     /// <summary>
@@ -1087,22 +1064,13 @@
     /// <returns>Iterator to the new location of the element following the erased element.</returns>
     /// <remarks>GCC doesn't support erase with const_iterator on vector yet. In the future this should be
     /// changed.</remarks>
-    iterator erase(iterator position) { return m_elements.erase(position); }
+    iterator erase(iterator position);
 
     /// <summary>
     /// Deletes an element of the JSON object. If the key doesn't exist, this method throws.
     /// </summary>
     /// <param name="key">The key of an element in the JSON object.</param>
-    void erase(const utility::string_t& key)
-    {
-        auto iter = find_by_key(key);
-        if (iter == m_elements.end())
-        {
-            throw web::json::json_exception("Key not found");
-        }
-
-        m_elements.erase(iter);
-    }
+    void erase(const utility::string_t& key);
 
     /// <summary>
     /// Accesses an element of a JSON object. If the key doesn't exist, this method throws.
@@ -1142,17 +1110,7 @@
     /// <param name="key">The key of an element in the JSON object.</param>
     /// <returns>If the key exists, a reference to the value kept in the field, otherwise a newly created null value
     /// that will be stored for the given key.</returns>
-    json::value& operator[](const utility::string_t& key)
-    {
-        auto iter = find_insert_location(key);
-
-        if (iter == m_elements.end() || key != iter->first)
-        {
-            return m_elements.insert(iter, std::pair<utility::string_t, value>(key, value()))->second;
-        }
-
-        return iter->second;
-    }
+    json::value& operator[](const utility::string_t& key);
 
     /// <summary>
     /// Gets an iterator to an element of a JSON object.
--- a/Release/src/json/json.cpp
+++ b/Release/src/json/json.cpp
@@ -135,6 +135,14 @@
 {
 }
 
+#ifdef ENABLE_JSON_VALUE_VISUALIZER
+web::json::value::value(std::unique_ptr<details::_Value> v, value_type kind) : m_value(std::move(v)), m_kind(kind)
+#else
+web::json::value::value(std::unique_ptr<details::_Value> v) : m_value(std::move(v))
+#endif
+{
+}
+
 web::json::value::value(const value& other)
     : m_value(other.m_value->_copy_value())
 #ifdef ENABLE_JSON_VALUE_VISUALIZER
@@ -495,3 +503,67 @@
 #endif
     return instance;
 }
+
+web::json::array::array() : m_elements() {}
+web::json::array::array(size_type size) : m_elements(size) {}
+web::json::array::array(storage_type elements) : m_elements(std::move(elements)) {}
+
+web::json::array::iterator web::json::array::erase(web::json::array::iterator position)
+{
+    return m_elements.erase(position);
+}
+
+void web::json::array::erase(web::json::array::size_type index)
+{
+    if (index >= m_elements.size())
+    {
+        throw json_exception("index out of bounds");
+    }
+    m_elements.erase(m_elements.begin() + index);
+}
+
+json::value& web::json::array::operator[](web::json::array::size_type index)
+{
+    msl::safeint3::SafeInt<size_type> nMinSize(index);
+    nMinSize += 1;
+    msl::safeint3::SafeInt<size_type> nlastSize(m_elements.size());
+    if (nlastSize < nMinSize) m_elements.resize((size_type)nMinSize);
+
+    return m_elements[index];
+}
+
+web::json::object::object(bool keep_order) : m_elements(), m_keep_order(keep_order) {}
+web::json::object::object(storage_type elements, bool keep_order) : m_elements(std::move(elements)), m_keep_order(keep_order)
+{
+    if (!keep_order)
+    {
+        sort(m_elements.begin(), m_elements.end(), compare_pairs);
+    }
+}
+web::json::object::iterator web::json::object::erase(iterator position)
+{
+    return m_elements.erase(position);
+}
+
+void web::json::object::erase(const utility::string_t& key)
+{
+    auto iter = find_by_key(key);
+    if (iter == m_elements.end())
+    {
+        throw web::json::json_exception("Key not found");
+    }
+
+    m_elements.erase(iter);
+}
+
+json::value& web::json::object::operator[](const utility::string_t& key)
+{
+    auto iter = find_insert_location(key);
+
+    if (iter == m_elements.end() || key != iter->first)
+    {
+        return m_elements.insert(iter, std::pair<utility::string_t, value>(key, value()))->second;
+    }
+
+    return iter->second;
+}