CARMA C++
DoubleStringifier.h
1 #ifndef CARMA_UTIL_DOUBLE_STRINGIFIER_H
2 #define CARMA_UTIL_DOUBLE_STRINGIFIER_H
3 
5 
6 
7 namespace carma {
8 namespace util {
9 
10 
11 class DoubleStringifier {
12  public:
13 
14  enum {
15  MAX_CHARS_PER_VALUE = 20
16  };
17 
18  explicit DoubleStringifier( );
19 
20  virtual ~DoubleStringifier( );
21 
22  ::size_t stringifyDouble( double v,
23  char * buffer,
24  ::size_t bufferMaxCount );
25 
26  private:
27 
28  DoubleStringifier( const DoubleStringifier & ); // no copying
29  DoubleStringifier & operator=( const DoubleStringifier & ); // no copying
30 
31  void stringifyDouble( double v, char * buffer );
32 
33  unsigned short firstBiasedBase10Exponent_[ 0x0800 + 1 ];
34 
35  double firstScale_[ 0x0800 ];
36  double secondScale_[ 0x0800 ];
37 
38  char leadChunks_[ 100 ][ 1 ];
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::DoubleStringifier::stringifyDouble( const double 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  stringifyDouble( 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.