gwnavruntime/basesystem/floatformatter.h Source File

floatformatter.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 // primary contact: GUAL - secondary contact: NOBODY
8 #ifndef Navigation_FloatFormatter_H
9 #define Navigation_FloatFormatter_H
10 
14 
15 namespace Kaim
16 {
17 
18 // usage
19 // FloatFormatter fmt4f("%.4f");
20 // stream << fmt4f(x) << fmt4f(y) << fmt4f(z);
21 class FloatFormatter
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Kaim::Stat_Default_Mem)
24 public:
25  FloatFormatter(const char* format = "%.2f") : m_format(format) { KY_UNUSED(m_buffer); KY_UNUSED(m_format); }
26 
27  char* operator()(KyFloat32 value)
28  {
29  #ifndef KY_NO_LOG_OUTPUT
30  SFsprintf(m_buffer, ArraySize(m_buffer), m_format, value);
31  return m_buffer;
32  #else
33  KY_UNUSED(value);
34  return KY_NULL;
35  #endif
36  }
37 
38 private:
39  const char* m_format;
40  char m_buffer[64];
41 };
42 
43 }
44 
45 #endif //Navigation_FloatFormatter_H
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
KyUInt32 ArraySize(T(&)[N])
Returns the size of a fixed-size array.
Definition: types.h:361
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43