@@ -268,6 +268,26 @@ namespace web { namespace json
268
268
// / <returns><c>true</c> if the value is a number value, <c>false</c> otherwise</returns>
269
269
bool is_number () const { return type () == Number; }
270
270
271
+ // / <summary>
272
+ // / Is the current value represented as an integer number value?
273
+ // / </summary>
274
+ // / <remarks>
275
+ // / Note that if a json value is a number but represented as a double it can still
276
+ // / be retrieved as a integer using as_integer(), however the value will be truncated.
277
+ // / </remarks>
278
+ // / <returns><c>true</c> if the value is an integer value, <c>false</c> otherwise.</returns>
279
+ _ASYNCRTIMP bool is_integer () const ;
280
+
281
+ // / <summary>
282
+ // / Is the current value represented as an double number value?
283
+ // / </summary>
284
+ // / <remarks>
285
+ // / Note that if a json value is a number but represented as a int it can still
286
+ // / be retrieved as a double using as_double().
287
+ // / </remarks>
288
+ // / <returns><c>true</c> if the value is an double value, <c>false</c> otherwise.</returns>
289
+ _ASYNCRTIMP bool is_double () const ;
290
+
271
291
// / <summary>
272
292
// / Is the current value a Boolean value?
273
293
// / </summary>
@@ -568,6 +588,9 @@ namespace web { namespace json
568
588
569
589
virtual json::value::value_type type () const { return json::value::Null; }
570
590
591
+ virtual bool is_integer () const { throw json_exception (_XPLATSTR (" not a number" )); }
592
+ virtual bool is_double () const { throw json_exception (_XPLATSTR (" not a number" )); }
593
+
571
594
virtual double as_double () const { throw json_exception (_XPLATSTR (" not a number" )); }
572
595
virtual int32_t as_integer () const { throw json_exception (_XPLATSTR (" not a number" )); }
573
596
virtual bool as_bool () const { throw json_exception (_XPLATSTR (" not a boolean" )); }
@@ -647,6 +670,9 @@ namespace web { namespace json
647
670
648
671
virtual json::value::value_type type () const { return json::value::Number; }
649
672
673
+ virtual bool is_integer () const { return m_was_int; }
674
+ virtual bool is_double () const { return !m_was_int; }
675
+
650
676
virtual double as_double () const { return m_was_int ? static_cast <double >(m_intval) : m_value; }
651
677
virtual int32_t as_integer () const { return m_was_int ? m_intval : static_cast <int32_t >(m_value); }
652
678
0 commit comments