What's new in version 1.2

This version is mainly a code cleanup, bug fix and compilation's errors fix.

Code cleanup

In this version I made some cleanup of:

Compatible with STL-enabled wxWdigets' builds

There was a problem in compiling wxJSON if wxWdigets is built using the

  --enable-stl

flag. The problem is related to the declaration of the wxJSONInternalMap type which represents the container of key/value pairs. The declaration of such a type is:

  class WXDLLIMPEXP_JSON wxJSONInternalMap;   // forward declaration
  
  class WXDLLIMPEXP_JSON wxJSONValue
  {
    ...
    // this is the reason of the forward declaration
    const wxJSONInternalMap* AsMap() const;
    ...
  };

  WX_DECLARE_STRING_HASH_MAP( wxJSONValue, wxJSONInternalMap );

The code declares a hasp map container of strings as the key and wxJSONValue as the value. If wxWidgets is built without STL enabled the above code compiles fine.

Otherwise, a compile error occurs due to the redeclaration of the wxJSONInternalMap type. This happen because the wxWidgets' implementation of hashmaps relies on the std::hash_map STL container if STL is enabled. The above code is wrong if using STL for the map container. The correct code, when using STL is the following:

  WX_DECLARE_STRING_HASH_MAP( wxJSONValue, wxJSONInternalMap );
  // the above is similar to:
  // typedef std::hash_map<wxString, wxJSONValue>  wxJSONInternalMap;
  
  class WXDLLIMPEXP_JSON wxJSONValue
  {
    ...
    const wxJSONInternalMap* AsMap() const;
    ...
  };

In this version, the wxJSON library checks if STL is enabled in wxWidgets and conditionally compiles the library so that no compilation error occurs.

Issues when writing doubles

There is an issue in the wxJSONWriter class when a JSON value of type double is written to the JSON text representation. The writer relies on the snprintf function to write a text representation of the double as a string of decimal digits.

You may also know that some decimal fractional number cannot be exactly represented in binary format (and viceversa). For example, the decimal fraction 1/10 cannot be representated correctly in binary. The problem is that when writing that number to JSON text you may get one of the following:

  0.1
  0.100000
  0.10000000000000000555

depending on the precision flags used in the format string. For this reason, the wxJSON writer uses a default format string of:

  %.10g

which specifies a precision of ten significant decimal digits suppressing trailing ZEROes. You can modify the format string using the wxJSONWriter::SetDoubleFmtString member function. The format string set by this function is used for all JSON text generated by the wxJSON writer object for which the function was called.


Generated on Wed Dec 30 14:42:30 2009 for wxJSON by  doxygen 1.5.5