CARMA C++
FloatStringifier.h
1 #ifndef CARMA_UTIL_FLOAT_STRINGIFIER_H
2 #define CARMA_UTIL_FLOAT_STRINGIFIER_H
3 
5 
6 
7 namespace carma {
8 namespace util {
9 
10 
11 class FloatStringifier {
12  public:
13 
14  enum {
15  MAX_CHARS_PER_VALUE = 13
16  };
17 
18  explicit FloatStringifier( );
19 
20  virtual ~FloatStringifier( );
21 
22  ::size_t stringifyFloat( float v,
23  char * buffer,
24  ::size_t bufferMaxCount );
25 
26  private:
27 
28  FloatStringifier( const FloatStringifier & ); // no copying
29  FloatStringifier & operator=( const FloatStringifier & ); // no copying
30 
31  void stringifyFloat( float v, char * buffer );
32 
33  double firstScale_[ 0x0100 ];
34  double secondScale_[ 0x0100 ];
35 
36  unsigned short firstBiasedBase10Exponent_[ 0x0100 + 1 ];
37 
38  char leadChunks_[ 100 ][ 3 ];
39  char otherChunks_[ 10000 ][ 4 ];
40 
41  char exponents_[ 621 ][ 4 ];
42 };
43 
44 
45 } // namespace carma::util
46 } // namespace carma
47 
48 
49 inline ::size_t
50 carma::util::FloatStringifier::stringifyFloat( const float v,
51  char * const buffer,
52  const ::size_t bufferMaxCount )
53 {
54  if ( bufferMaxCount < MAX_CHARS_PER_VALUE )
55  throw CARMA_ERROR( "Buffer too small" );
56 
57  stringifyFloat( v, buffer );
58 
59  return MAX_CHARS_PER_VALUE;
60 }
61 
62 
63 #endif
Exception class for errors.
#define CARMA_ERROR(y)
Trick to get the file name and line number passed to the exception handler.