Skip to content

Commit bfbd0f7

Browse files
committed
merge from tfs to codeplex
1 parent 85c73b3 commit bfbd0f7

30 files changed

+541
-188
lines changed

Release/include/astreambuf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ namespace Concurrency { namespace streams
152152
virtual bool can_seek() const = 0;
153153

154154
/// <summary>
155-
/// <c>is_eof</c> is used to determine whether a read head has reached the buffer.
155+
/// <c>is_eof</c> is used to determine whether a read head has reached the end of the buffer.
156156
/// </summary>
157157
virtual bool is_eof() const = 0;
158158

@@ -443,7 +443,7 @@ namespace Concurrency { namespace streams
443443
}
444444

445445
/// <summary>
446-
/// <c>is_eof</c> is used to determine whether a read head has reached the buffer.
446+
/// <c>is_eof</c> is used to determine whether a read head has reached the end of the buffer.
447447
/// </summary>
448448
virtual bool is_eof() const
449449
{
@@ -911,7 +911,7 @@ namespace Concurrency { namespace streams
911911
virtual bool is_open() const { return get_base()->is_open(); }
912912

913913
/// <summary>
914-
/// <c>is_eof</c> is used to determine whether a read head has reached the buffer.
914+
/// <c>is_eof</c> is used to determine whether a read head has reached the end of the buffer.
915915
/// </summary>
916916
virtual bool is_eof() const { return get_base()->is_eof(); }
917917

Release/include/http_client.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,27 @@ class http_client
253253
~http_client() {}
254254

255255
/// <summary>
256-
/// Add an HTTP pipeline stage to the client.
256+
/// Gets the base uri
257+
/// </summary>
258+
/// <returns>
259+
/// A base uri initialized in constructor
260+
/// </return>
261+
const uri& base_uri() const
262+
{
263+
return _base_uri;
264+
}
265+
266+
/// <summary>
267+
/// Adds an HTTP pipeline stage to the client.
257268
/// </summary>
258269
/// <param name="handler">A function object representing the pipeline stage.</param>
259270
void add_handler(std::function<pplx::task<http_response>(http_request, std::shared_ptr<http::http_pipeline_stage>)> handler)
260271
{
261-
m_pipeline->append(std::make_shared< ::web::http::details::function_pipeline_wrapper>(handler));
272+
m_pipeline->append(std::make_shared<::web::http::details::function_pipeline_wrapper>(handler));
262273
}
263274

264275
/// <summary>
265-
/// Add an HTTP pipeline stage to the client.
276+
/// Adds an HTTP pipeline stage to the client.
266277
/// </summary>
267278
/// <param name="stage">A shared pointer to a pipeline stage.</param>
268279
void add_handler(std::shared_ptr<http::http_pipeline_stage> stage)
@@ -387,8 +398,10 @@ class http_client
387398
private:
388399

389400
void build_pipeline(const uri &base_uri, const http_client_config& client_config);
401+
402+
std::shared_ptr<::web::http::http_pipeline> m_pipeline;
390403

391-
std::shared_ptr< ::web::http::http_pipeline> m_pipeline;
404+
uri _base_uri;
392405
};
393406

394407
} // namespace client

Release/include/http_helpers.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@ namespace details
4040
{
4141
// Constants for MIME types.
4242
const utility::string_t content_type_application_json = U("application/json");
43+
4344
const utility::string_t content_type_application_octetstream = U("application/octet-stream");
4445
const utility::string_t content_type_text_plain = U("text/plain");
4546
const utility::string_t content_type_text_plain_utf8 = U("text/plain; charset=utf-8");
4647
const utility::string_t content_type_text_plain_utf16 = U("text/plain; charset=utf-16");
4748
const utility::string_t content_type_text_plain_utf16le = U("text/plain; charset=utf-16le");
4849

50+
// Unofficial JSON MIME types...
51+
const utility::string_t content_type_text_json = U("text/json");
52+
const utility::string_t content_type_text_xjson = U("text/x-json");
53+
const utility::string_t content_type_text_javascript = U("text/javascript");
54+
const utility::string_t content_type_text_xjavascript = U("text/x-javascript");
55+
const utility::string_t content_type_application_javascript = U("application/javascript");
56+
const utility::string_t content_type_application_xjavascript = U("application/x-javascript");
57+
4958
// Constants for differnet charsets.
5059
const utility::string_t charset_usascii = U("us-ascii");
5160
const utility::string_t charset_latin1 = U("iso-8859-1");
@@ -55,10 +64,15 @@ namespace details
5564
const utility::string_t charset_utf16be = U("utf-16be");
5665

5766
/// <summary>
58-
/// Determines which or not the given content type is 'textual' according the feature specifications.
67+
/// Determines whether or not the given content type is 'textual' according the feature specifications.
5968
/// </summary>
6069
bool is_content_type_textual(const utility::string_t &content_type);
6170

71+
/// <summary>
72+
/// Determines whether or not the given content type is JSON according the feature specifications.
73+
/// </summary>
74+
bool is_content_type_json(const utility::string_t &content_type);
75+
6276
/// <summary>
6377
/// Parses the given Content-Type header value to get out actual content type and charset.
6478
/// If the charset isn't specified the default charset for the content type will be set.

Release/include/json.h

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,6 @@ namespace web { namespace json
171171
/// <returns>The JSON value object that contains the result of the assignment.</returns>
172172
_ASYNCRTIMP value &operator=(value &&);
173173

174-
/// <summary>
175-
/// Constructor creating a JSON value from an input stream, by parsing its contents.
176-
/// </summary>
177-
/// <param name="input">The stream to read the JSON value from</param>
178-
/// <returns>The JSON value object created from the input stream.</returns>
179-
_ASYNCRTIMP static value parse(utility::istream_t &input);
180-
181-
#ifdef _MS_WINDOWS
182-
/// <summary>
183-
/// Constructor creating a JSON value from a byte buffer stream, by parsing its contents.
184-
/// </summary>
185-
/// <param name="stream">The stream to read the JSON value from</param>
186-
_ASYNCRTIMP static value parse(std::istream& stream);
187-
#endif
188-
189174
// Static factories
190175

191176
/// <summary>
@@ -312,31 +297,44 @@ namespace web { namespace json
312297
/// <returns>The number of children. 0 for all non-composites.</returns>
313298
size_t size() const;
314299

300+
/// <summary>
301+
/// Parse a string and construct a JSON value.
302+
/// </summary>
303+
/// <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
304+
_ASYNCRTIMP static value parse(utility::string_t);
305+
315306
/// <summary>
316307
/// Serialize the current JSON value to a C++ string.
317308
/// </summary>
318309
/// <returns>A string representation of the value</returns>
319310
_ASYNCRTIMP utility::string_t to_string() const;
320311

321312
/// <summary>
322-
/// Parse a string and construct a JSON value.
313+
/// Parse a JSON value from the contents of an input stream using the native platform character width.
323314
/// </summary>
324-
/// <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
325-
_ASYNCRTIMP static value parse(utility::string_t);
315+
/// <param name="input">The stream to read the JSON value from</param>
316+
/// <returns>The JSON value object created from the input stream.</returns>
317+
_ASYNCRTIMP static value parse(utility::istream_t &input);
326318

327-
#ifdef _MS_WINDOWS
328319
/// <summary>
329-
/// Write the current JSON value as a double-byte string to a stream instance.
320+
/// Write the current JSON value to a stream with the native platform character width.
330321
/// </summary>
331322
/// <param name="stream">The stream that the JSON string representation should be written to.</param>
332-
_ASYNCRTIMP void serialize(std::basic_ostream<utf16char> &stream) const;
333-
#endif
323+
_ASYNCRTIMP void serialize(utility::ostream_t &stream) const;
334324

325+
#ifdef _MS_WINDOWS
335326
/// <summary>
336-
/// Serialize the content of the value into a stream in UTF8 format
327+
/// Parse a JSON value from the contents of a single-byte (UTF8) stream.
328+
/// </summary>
329+
/// <param name="stream">The stream to read the JSON value from</param>
330+
_ASYNCRTIMP static value parse(std::istream& stream);
331+
332+
/// <summary>
333+
/// Serialize the content of the value into a single-byte (UTF8) stream.
337334
/// </summary>
338335
/// <param name="stream">The stream that the JSON string representation should be written to.</param>
339-
_ASYNCRTIMP void serialize(std::basic_ostream<char>& stream) const;
336+
_ASYNCRTIMP void serialize(std::ostream& stream) const;
337+
#endif
340338

341339
/// <summary>
342340
/// Convert the JSON value to a C++ double, if and only if it is a number value.
@@ -381,6 +379,13 @@ namespace web { namespace json
381379
return !((*this) == other);
382380
}
383381

382+
/// <summary>
383+
/// Access a field of a JSON object.
384+
/// </summary>
385+
/// <param name="key">The name of the field</param>
386+
/// <returns>The value kept in the field; null if the field does not exist</returns>
387+
value get(const utility::string_t &key) const;
388+
384389
/// <summary>
385390
/// Access a field of a JSON object.
386391
/// </summary>
@@ -406,6 +411,13 @@ namespace web { namespace json
406411
public:
407412
#endif
408413

414+
/// <summary>
415+
/// Access an element of a JSON array.
416+
/// </summary>
417+
/// <param name="key">The index of an element in the JSON array</param>
418+
/// <returns>The value kept at the array index; null if outside the boundaries of the array</returns>
419+
value get(size_t index) const;
420+
409421
/// <summary>
410422
/// Accesses an element of a JSON array.
411423
/// </summary>
@@ -530,6 +542,9 @@ namespace web { namespace json
530542
virtual const json::value::element_vector &elements() const { throw json_exception(U("not an array")); }
531543
virtual const json::value::field_map &fields() const { throw json_exception(U("not an object")); }
532544

545+
virtual value get_field(const utility::string_t &) const { throw json_exception(U("not an object")); }
546+
virtual value get_element(std::vector<value>::size_type) const { throw json_exception(U("not an array")); }
547+
533548
virtual value &index(const utility::string_t &) { throw json_exception(U("not an object")); }
534549
virtual value &index(std::vector<value>::size_type) { throw json_exception(U("not an array")); }
535550

@@ -775,6 +790,7 @@ namespace web { namespace json
775790

776791
virtual json::value::value_type type() const { return json::value::Object; }
777792

793+
_ASYNCRTIMP virtual value get_field(const utility::string_t &) const;
778794
_ASYNCRTIMP virtual json::value &index(const utility::string_t &key);
779795
_ASYNCRTIMP virtual const json::value &cnst_index(const utility::string_t &key) const;
780796

@@ -843,6 +859,18 @@ namespace web { namespace json
843859

844860
virtual json::value::value_type type() const { return json::value::Array; }
845861

862+
virtual value get_element(std::vector<value>::size_type index) const
863+
{
864+
#ifdef _MS_WINDOWS
865+
msl::utilities::SafeInt<std::vector<json::value>::size_type> idx(index);
866+
msl::utilities::SafeInt<std::vector<json::value>::size_type> size(m_elements.size());
867+
#else
868+
size_t idx = index;
869+
size_t size = m_elements.size();
870+
#endif
871+
return (idx >= size) ? value() : m_elements[index].second;
872+
}
873+
846874
virtual json::value &index(std::vector<json::value>::size_type index)
847875
{
848876
#ifdef _MS_WINDOWS
@@ -925,6 +953,17 @@ namespace web { namespace json
925953
return m_value->size();
926954
}
927955

956+
inline json::value json::value::get(const utility::string_t& key) const
957+
{
958+
return m_value->get_field(key);
959+
}
960+
961+
inline json::value json::value::get(size_t index) const
962+
{
963+
return m_value->get_element(index);
964+
}
965+
966+
928967
inline json::value::iterator json::value::begin()
929968
{
930969
return m_value->elements().begin();

Release/include/pplxtasks.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ namespace details
847847

848848
// Specializations to avoid marshaling for strings and arrays.
849849
template<typename _Type>
850-
struct _MarshalHelper< ::Platform::Array<_Type^>>
850+
struct _MarshalHelper<::Platform::Array<_Type^>>
851851
{
852852
static ::Platform::Array<_Type^>^ _Perform(::Platform::Array<_Type^>^& _ObjInCtx, const _ContextCallback& _Ctx)
853853
{
@@ -856,7 +856,7 @@ namespace details
856856
};
857857

858858
template<>
859-
struct _MarshalHelper< ::Platform::String>
859+
struct _MarshalHelper<::Platform::String>
860860
{
861861
static ::Platform::String^ _Perform(::Platform::String^& _ObjInCtx, const _ContextCallback& _Ctx)
862862
{
@@ -7320,15 +7320,19 @@ namespace details
73207320
inline
73217321
task<bool> do_while(std::function<task<bool>(void)> func)
73227322
{
7323-
task<bool> first = func();
7324-
return first.then([=](bool guard) -> task<bool> {
7325-
if (guard)
7326-
return do_while(func);
7327-
else
7328-
return first;
7329-
});
7330-
}
7323+
task<bool> cond = func();
73317324

7325+
while ( cond.is_done() )
7326+
{
7327+
if ( !cond.get() )
7328+
return task_from_result(true);
7329+
cond = func();
7330+
}
7331+
7332+
return cond.then([=](task<bool> guard) {
7333+
return (guard.get()) ? do_while(func) : task_from_result(true);
7334+
});
7335+
}
73327336
} // namespace details
73337337

73347338
} // namespace pplx

0 commit comments

Comments
 (0)