Boost logo

Boost :

Subject: [boost] Requesting interest in a bounded capacity C-string
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-05-12 11:12:36


Hi,

I was looking for a bounded capacity string and I have take a look to the review (2006) of the rejected FixedString library (http://www.boostpro.com/vault/index.php?action=downloadfile&filename=fixed_string.zip&directory=Strings%20-%20Text%20Processing&). Here follows a brief compilation of the main points

* A motivating use case was missing
    * the motivating example (printf) was not enough significant, when we have the choice we can always find a better class.
* The design was not adapted to the goals
    * the inheritance hierarchy was considered to complicated needing an allocation
    * buffer overrun should be configurable - truncate, exception, assert,
    * The formating should be considered orthogonal to the fixed_string class

The context where I need to use something like this class is:
    * the binary layout can not be modified and must be bounded due to legacy issues, Third Party Products interfaces, protocol messages format or bounded capacity strings on persistent databases.
    * overrun must be checked because otherwise the program can crash.

I will propose to name it bounded_c_string (when _c_ stands for "C-style" but recalls also capacity)

These are the requirements I would associate to such a class
    * the value must always be a C-string (so with a trailing '\0')
    * The layout of a bounded_c_string<N> class must be the same as its counterpart C-string char[N] (sizeof(bounded_c_string<N>==N)
    * As a lot of code can use this type the refactoring from C code using char[N] to bounded_c_string<N> should be reduced to the type declaration (overloading of all the C string functions with bounded_c_string<N> are a must)
    * the efficiency must be equivalent to the hand written C-style
    * convertible to and from C-strings, std::string and other bounded_c_string<M>
    * C++ std::string like interface must also be provided

Note that there is not issues with the length of the string coherency because not stored.

This class do not intends to use dynamic memory when fixed capacity is not enough (see AutoBuffer library http://www.cs.aau.dk/~nesotto/boost/auto_buffer.zip for this use case)

I don't know which is the FixedString library, the last upload on the Vault dates from 08.01.2006.

Is there an interest for this simple class? Do you agree with the requirements?

Is there an interest for a bounded_c_memory class which will take care of the length of the significant data instead of the trailing '\0'?

Best regards,
_____________________
Vicente Juan Botet Escribá


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk