[serialization] Facets for writing and reading infinity and nan to text streams

Following a suggestion of Robert Ramey's, I have put together facets for writing and reading non-finite floating point numbers, such as infinity and nan, to text streams, in a consistent and portable way. This is useful when serializing to text archives, but should have other applications as well. I have attached a zip file. It contains three files: 1. the actual code: non_finite_num_facets.hpp 2. documentation: non_finite_num_facets_doc.txt 3. tests: non_finite_num_facets_test.cpp The code handles char and wchar_t. It handles float, double and long double. The code has been tested with VC++ 7.1 but should work with other compilers as well. Any feedback is wellcome. --Johan Råde (rade@maths.lth.se)

Halleluhuh - please upload this to the Boost Vault - and keep a copy incase the vault disappears. Robert Ramey Johan Råde wrote:
Following a suggestion of Robert Ramey's, I have put together facets for writing and reading non-finite floating point numbers, such as infinity and nan, to text streams, in a consistent and portable way. This is useful when serializing to text archives, but should have other applications as well.
I have attached a zip file. It contains three files:
1. the actual code: non_finite_num_facets.hpp 2. documentation: non_finite_num_facets_doc.txt 3. tests: non_finite_num_facets_test.cpp
The code handles char and wchar_t. It handles float, double and long double.
The code has been tested with VC++ 7.1 but should work with other compilers as well.
Any feedback is wellcome.
--Johan Råde (rade@maths.lth.se)
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Robert, I tested the non_finite_num_facets library with text archives. It works, but only if I do things in the following order: 1. construct stream 2. construct archive 3. imbue locale into stream If I reverse step 2 and 3, then it does not work; put_num_extended is never called. That is strange, and maybe undesirable. --Johan Råde

Here is a revised version of the non_finite_num_facets library; see attached zip file. Now I'm going on vacation for two weeks, with no internet access. When I get back I will 1. improve the documentation 2. add classes put_num_strict and get_num_strict that set the failbit when they encounter any non-finite numbers 3. upload the library to the Boost Vault --Johan Råde Robert Ramey wrote:
Halleluhuh - please upload this to the Boost Vault - and keep a copy incase the vault disappears.
Robert Ramey
participants (2)
-
Johan Råde
-
Robert Ramey