gwnavruntime/basesystem/floatformatter.h Source File

floatformatter.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
12 
13 namespace Kaim
14 {
15 
16 // usage
17 // FloatFormatter fmt4f("%.4f");
18 // stream << fmt4f(x) << fmt4f(y) << fmt4f(z);
19 class FloatFormatter
20 {
21  KY_DEFINE_NEW_DELETE_OPERATORS(Kaim::Stat_Default_Mem)
22 public:
23  FloatFormatter(const char* format = "%.2f") : m_format(format) { KY_UNUSED(m_buffer); KY_UNUSED(m_format); }
24 
25  char* operator()(KyFloat32 value)
26  {
27  #ifndef KY_NO_LOG_OUTPUT
28  SFsprintf(m_buffer, ArraySize(m_buffer), m_format, value);
29  return m_buffer;
30  #else
31  KY_UNUSED(value);
32  return nullptr;
33  #endif
34  }
35 
36 private:
37  const char* m_format;
38  char m_buffer[64];
39 };
40 
41 }
42 
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
KyUInt32 ArraySize(T(&)[N])
Returns the size of a fixed-size array.
Definition: types.h:189
float KyFloat32
float
Definition: types.h:32