Skip to content

Commit 963c03a

Browse files
committed
Sync to TFS
1 parent 27ca13d commit 963c03a

File tree

19 files changed

+226
-895
lines changed

19 files changed

+226
-895
lines changed

Release/include/cpprest/asyncrt_utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ namespace conversions
170170

171171
namespace details
172172
{
173+
/// <summary>
174+
/// Our own implementation of alpha numeric instead of std::isalnum to avoid
175+
/// taking global lock for performance reasons.
176+
/// </summary>
177+
inline bool __cdecl is_alnum(char ch)
178+
{
179+
return (ch >= '0' && ch <= '9')
180+
|| (ch >= 'A' && ch <= 'Z')
181+
|| (ch >= 'a' && ch <= 'z');
182+
}
173183

174184
/// <summary>
175185
/// Simplistic implementation of make_unique. A better implementation would be based on variadic templates

Release/include/cpprest/json.h

Lines changed: 111 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,46 @@ namespace web { namespace json
434434
CASABLANCA_DEPRECATED("This API is deprecated and will be removed in a future release, use operator[] instead.")
435435
value get(const utility::string_t &key) const;
436436

437+
/// <summary>
438+
/// Accesses an element of a JSON array. Throws when index out of bounds.
439+
/// </summary>
440+
/// <param name="index">The index of an element in the JSON array.</param>
441+
/// <returns>A reference to the value.</returns>
442+
_ASYNCRTIMP json::value& at(size_t index);
443+
444+
/// <summary>
445+
/// Accesses an element of a JSON array. Throws when index out of bounds.
446+
/// </summary>
447+
/// <param name="index">The index of an element in the JSON array.</param>
448+
/// <returns>A reference to the value.</returns>
449+
_ASYNCRTIMP const json::value& at(size_t index) const;
450+
451+
/// <summary>
452+
/// Accesses an element of a JSON object. If the key doesn't exist, this method throws.
453+
/// </summary>
454+
/// <param name="key">The key of an element in the JSON object.</param>
455+
/// <returns>If the key exists, a reference to the value.</returns>
456+
_ASYNCRTIMP json::value& at(const utility::string_t& key);
457+
458+
/// <summary>
459+
/// Accesses an element of a JSON object. If the key doesn't exist, this method throws.
460+
/// </summary>
461+
/// <param name="key">The key of an element in the JSON object.</param>
462+
/// <returns>If the key exists, a reference to the value.</returns>
463+
_ASYNCRTIMP const json::value& at(const utility::string_t& key) const;
464+
437465
/// <summary>
438466
/// Accesses a field of a JSON object.
439467
/// </summary>
440468
/// <param name="key">The name of the field</param>
441-
/// <returns>A reference to the value kept in the field</returns>
469+
/// <returns>A reference to the value kept in the field.</returns>
442470
_ASYNCRTIMP value & operator [] (const utility::string_t &key);
443471

444472
/// <summary>
445473
/// Accesses a field of a JSON object.
446474
/// </summary>
447475
/// <param name="key">The name of the field</param>
448-
/// <returns>A reference to the value kept in the field</returns>
476+
/// <returns>A reference to the value kept in the field.</returns>
449477
_ASYNCRTIMP const value & operator [] (const utility::string_t &key) const;
450478

451479
#ifdef _MS_WINDOWS
@@ -471,16 +499,9 @@ namespace web { namespace json
471499
/// Accesses an element of a JSON array.
472500
/// </summary>
473501
/// <param name="index">The index of an element in the JSON array.</param>
474-
/// <returns>A reference to the value kept in the field</returns>
502+
/// <returns>A reference to the value kept in the field.</returns>
475503
_ASYNCRTIMP value & operator [] (size_t index);
476504

477-
/// <summary>
478-
/// Accesses an element of a JSON array.
479-
/// </summary>
480-
/// <param name="index">The index of an element in the JSON array.</param>
481-
/// <returns>A reference to the value kept in the field</returns>
482-
_ASYNCRTIMP const value & operator [] (size_t index) const;
483-
484505
private:
485506
friend class web::json::details::_Object;
486507
friend class web::json::details::_Array;
@@ -512,6 +533,26 @@ namespace web { namespace json
512533
#endif
513534
};
514535

536+
/// <summary>
537+
/// A single exception type to represent errors in parsing, converting, and accessing
538+
/// elements of JSON values.
539+
/// </summary>
540+
class json_exception : public std::exception
541+
{
542+
private:
543+
std::string _message;
544+
public:
545+
json_exception() {}
546+
json_exception(const utility::char_t * const &message) : _message(utility::conversions::to_utf8string(message)) { }
547+
548+
// Must be narrow string because it derives from std::exception
549+
const char* what() const _noexcept
550+
{
551+
return _message.c_str();
552+
}
553+
~json_exception() _noexcept {}
554+
};
555+
515556
/// <summary>
516557
/// A JSON array represented as a C++ class.
517558
/// </summary>
@@ -641,22 +682,44 @@ namespace web { namespace json
641682
}
642683

643684
/// <summary>
644-
/// Accesses an element of a JSON array.
685+
/// Accesses an element of a JSON array. Throws when index out of bounds.
645686
/// </summary>
646687
/// <param name="index">The index of an element in the JSON array.</param>
647-
/// <returns>A reference to the value kept in the field</returns>
648-
json::value& operator[](size_type index)
688+
/// <returns>A reference to the value kept in the field.</returns>
689+
json::value& at(size_type index)
649690
{
691+
if (index >= m_elements.size())
692+
throw json_exception(_XPLATSTR("index out of bounds"));
693+
694+
return m_elements[index];
695+
}
696+
697+
/// <summary>
698+
/// Accesses an element of a JSON array. Throws when index out of bounds.
699+
/// </summary>
700+
/// <param name="index">The index of an element in the JSON array.</param>
701+
/// <returns>A reference to the value kept in the field.</returns>
702+
const json::value& at(size_type index) const
703+
{
704+
if (index >= m_elements.size())
705+
throw json_exception(_XPLATSTR("index out of bounds"));
706+
650707
return m_elements[index];
651708
}
652709

653710
/// <summary>
654711
/// Accesses an element of a JSON array.
655712
/// </summary>
656713
/// <param name="index">The index of an element in the JSON array.</param>
657-
/// <returns>A const reference to the value kept in the field</returns>
658-
const json::value& operator[](size_type index) const
714+
/// <returns>A reference to the value kept in the field.</returns>
715+
json::value& operator[](size_type index)
659716
{
717+
SafeInt<size_type> nMinSize(index);
718+
nMinSize += 1;
719+
SafeInt<size_type> nlastSize(m_elements.size());
720+
if (nlastSize < nMinSize)
721+
m_elements.resize(nMinSize);
722+
660723
return m_elements[index];
661724
}
662725

@@ -676,26 +739,6 @@ namespace web { namespace json
676739
template<typename CharType> friend class json::details::JSON_Parser;
677740
};
678741

679-
/// <summary>
680-
/// A single exception type to represent errors in parsing, converting, and accessing
681-
/// elements of JSON values.
682-
/// </summary>
683-
class json_exception : public std::exception
684-
{
685-
private:
686-
std::string _message;
687-
public:
688-
json_exception() {}
689-
json_exception(const utility::char_t * const &message) : _message(utility::conversions::to_utf8string(message)) { }
690-
691-
// Must be narrow string because it derives from std::exception
692-
const char* what() const _noexcept
693-
{
694-
return _message.c_str();
695-
}
696-
~json_exception() _noexcept {}
697-
};
698-
699742
/// <summary>
700743
/// A JSON object represented as a C++ class.
701744
/// </summary>
@@ -832,10 +875,40 @@ namespace web { namespace json
832875
return m_elements.crend();
833876
}
834877

878+
/// <summary>
879+
/// Accesses an element of a JSON object. If the key doesn't exist, this method throws.
880+
/// </summary>
881+
/// <param name="key">The key of an element in the JSON object.</param>
882+
/// <returns>If the key exists, a reference to the value kept in the field.</returns>
883+
json::value& at(const utility::string_t& key)
884+
{
885+
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
886+
887+
if (iter == m_elements.end() || key != (iter->first))
888+
throw web::json::json_exception(_XPLATSTR("Key not found"));
889+
890+
return iter->second;
891+
}
892+
893+
/// <summary>
894+
/// Accesses an element of a JSON object. If the key doesn't exist, this method throws.
895+
/// </summary>
896+
/// <param name="key">The key of an element in the JSON object.</param>
897+
/// <returns>If the key exists, a reference to the value kept in the field.</returns>
898+
const json::value& at(const utility::string_t& key) const
899+
{
900+
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
901+
902+
if (iter == m_elements.end() || key != (iter->first))
903+
throw web::json::json_exception(_XPLATSTR("Key not found"));
904+
905+
return iter->second;
906+
}
907+
835908
/// <summary>
836909
/// Accesses an element of a JSON object.
837910
/// </summary>
838-
/// <param name="index">The key of an element in the JSON object.</param>
911+
/// <param name="key">The key of an element in the JSON object.</param>
839912
/// <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>
840913
json::value& operator[](const utility::string_t& key)
841914
{
@@ -851,7 +924,7 @@ namespace web { namespace json
851924
/// Gets an iterator to an element of a JSON object.
852925
/// </summary>
853926
/// <param name="key">The key of an element in the JSON object.</param>
854-
/// <returns>A const iterator to the value kept in the field</returns>
927+
/// <returns>A const iterator to the value kept in the field.</returns>
855928
const_iterator find(const utility::string_t& key) const
856929
{
857930
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
@@ -866,7 +939,7 @@ namespace web { namespace json
866939
/// Gets an iterator to an element of a JSON object.
867940
/// </summary>
868941
/// <param name="key">The key of an element in the JSON object.</param>
869-
/// <returns>An iterator to the value kept in the field</returns>
942+
/// <returns>An iterator to the value kept in the field.</returns>
870943
iterator find(const utility::string_t& key)
871944
{
872945
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
@@ -1483,30 +1556,8 @@ namespace web { namespace json
14831556
virtual json::array& as_array() { return m_array; }
14841557
virtual const json::array& as_array() const { return m_array; }
14851558

1486-
virtual value get_element(array::size_type index) const
1487-
{
1488-
SafeInt<array::size_type> idx(index);
1489-
SafeInt<array::size_type> size(m_array.size());
1490-
return (idx >= size) ? value() : m_array[index];
1491-
}
1492-
14931559
virtual json::value &index(json::array::size_type index)
14941560
{
1495-
SafeInt<json::array::size_type> nMinSize(index);
1496-
nMinSize += 1;
1497-
SafeInt<json::array::size_type> nlastSize(m_array.size());
1498-
if (nlastSize < nMinSize)
1499-
m_array.m_elements.resize(nMinSize);
1500-
1501-
return m_array.m_elements[index];
1502-
}
1503-
1504-
virtual const json::value &cnst_index(array::size_type index) const
1505-
{
1506-
SafeInt<array::size_type> idx(index);
1507-
SafeInt<array::size_type> size(m_array.size());
1508-
if ( idx >= size )
1509-
throw json_exception(_XPLATSTR("index out of bounds"));
15101561
return m_array[index];
15111562
}
15121563

Release/include/cpprest/uri_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace web { namespace details
6565
/// </summary>
6666
static bool is_unreserved(int c)
6767
{
68-
return std::isalnum((char)c, loc) || c == '-' || c == '.' || c == '_' || c == '~';
68+
return ::utility::details::is_alnum((char)c) || c == '-' || c == '.' || c == '_' || c == '~';
6969
}
7070

7171
/// <summary>
@@ -125,7 +125,7 @@ namespace web { namespace details
125125
/// </summary>
126126
static bool is_scheme_character(int c)
127127
{
128-
return std::isalnum((char)c, loc) || c == '+' || c == '-' || c == '.';
128+
return ::utility::details::is_alnum((char)c) || c == '+' || c == '-' || c == '.';
129129
}
130130

131131
/// <summary>

Release/include/pplx/pplxlinux.h

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
* ==++==
33
*
4-
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -88,7 +88,7 @@ namespace platform
8888
static const unsigned int timeout_infinite = 0xFFFFFFFF;
8989

9090
event_impl()
91-
: _signaled(false)
91+
: _signaled(false)
9292
{
9393
}
9494

@@ -217,7 +217,7 @@ namespace platform
217217
_M_cs.lock();
218218
_M_owner = id;
219219
_M_recursionCount = 1;
220-
}
220+
}
221221
}
222222

223223
void unlock()
@@ -231,7 +231,7 @@ namespace platform
231231
{
232232
_M_owner = -1;
233233
_M_cs.unlock();
234-
}
234+
}
235235
}
236236

237237
private:
@@ -240,36 +240,12 @@ namespace platform
240240
volatile long _M_owner;
241241
};
242242

243-
class linux_timer;
244-
class apple_timer;
245-
246-
class timer_impl
247-
{
248-
public:
249-
timer_impl()
250-
: m_timerImpl(nullptr)
251-
{
252-
}
253-
254-
~timer_impl();
255-
256-
_PPLXIMP void start(unsigned int ms, bool repeat, TaskProc_t userFunc, _In_ void * context);
257-
_PPLXIMP void stop(bool waitForCallbacks);
258-
259-
private:
260-
#if defined(__APPLE__)
261-
apple_timer * m_timerImpl;
262-
#else
263-
linux_timer * m_timerImpl;
264-
#endif
265-
};
266-
267243
#if defined(__APPLE__)
268244
class apple_scheduler : public pplx::scheduler_interface
269245
{
270246
public:
271247
_PPLXIMP virtual void schedule( TaskProc_t proc, _In_ void* param);
272-
248+
273249
virtual ~apple_scheduler();
274250
};
275251
#else
@@ -279,12 +255,7 @@ namespace platform
279255
_PPLXIMP virtual void schedule( TaskProc_t proc, _In_ void* param);
280256
};
281257
#endif
282-
283-
/// <summary>
284-
/// Timer
285-
/// </summary>
286-
typedef details::timer_impl timer_t;
287-
258+
288259
} // namespace details
289260

290261
/// <summary>
@@ -336,7 +307,7 @@ namespace extensibility
336307
#else
337308
typedef details::linux_scheduler default_scheduler_t;
338309
#endif
339-
310+
340311
namespace details
341312
{
342313
/// <summary>

0 commit comments

Comments
 (0)