HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_FormatNumber.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_FormatNumber.h ( SYS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __SYS_FormatNumber__
12 #define __SYS_FormatNumber__
13 
14 #include "SYS_API.h"
15 
16 #include "SYS_Types.h"
17 
18 enum class SYS_FormatFlags
19 {
20  None = 0x00, ///< Just output the raw number in the given base.
21  AddCPrefix = 0x01, ///< Add the C prefixes for the appropriate base.
22  /// E.g. 0x for hexadecimal (base 16), 0 for octal
23  /// (base 8) and 0b for binary (base 2,
24  /// a C++11 extension).
25  UpperCase = 0x02, ///< Alphabetic digits should be printed in upper-case
26  /// instead of default lower-case.
27  AddPlus = 0x04, ///< Always show a sign to indicate the sign of the
28  /// number. Usually only the negative sign is shown
29  /// for negative numbers, but this will add a positive
30  /// sign for positive numbers too.
31  DigitGrouping = 0x08, ///< Add digit groupings for the integer part of the
32  /// resulting number. For decimal numbers, this is
33  /// every three digits, for hexadecimal, octal and
34  /// binary numbers, this is every four digits. Other
35  /// bases ignore this flag.
36 };
37 
39 { return SYS_FormatFlags(int(a) | int(b)); }
40 
41 static inline bool operator&(SYS_FormatFlags a, SYS_FormatFlags b)
42 { return (int(a) & int(b)) == int(b); }
43 
44 
45 /// Write the text version of an integer value into a character buffer specified
46 /// by @c buffer of size @c buffer_size. The number of characters written is
47 /// returned.
48 /// Note that a string terminator value is *not* written out.
49 /// @param buffer The character buffer to copy the formatted number into. If
50 /// this value is @c nullptr, then the value returned will be the
51 /// number of bytes required to store the result.
52 /// @param buffer_size The size of the buffer given in @c buffer. If @c buffer
53 /// is @c nullptr, this value is ignored.
54 /// @param number The number to convert to a text representation.
55 /// @param base The numerical base the number will be converted to.
56 /// @param min_digits The minimum number of digits to write out. If this value
57 /// is greater than the actual number of digits needed, the
58 /// final value will be zero-padded after the sign charadcter.
59 /// @param flags The flags specifying the formatting.
60 /// @return The number of bytes written out to @c buffer. If @c buffer
61 /// is @c nullptr, then the size of the buffer required to write
62 /// out the entire value is returned.
63 SYS_API size_t
64 SYSformatInteger(char *buffer, size_t buffer_size, int8 number,
65  int base=10, int min_digits=0,
67 SYS_API size_t
68 SYSformatInteger(char *buffer, size_t buffer_size, uint8 number,
69  int base=10, int min_digits=0,
71 SYS_API size_t
72 SYSformatInteger(char *buffer, size_t buffer_size, int16 number,
73  int base=10, int min_digits=0,
75 SYS_API size_t
76 SYSformatInteger(char *buffer, size_t buffer_size, uint16 number,
77  int base=10, int min_digits=0,
79 SYS_API size_t
80 SYSformatInteger(char *buffer, size_t buffer_size, int32 number,
81  int base=10, int min_digits=0,
83 SYS_API size_t
84 SYSformatInteger(char *buffer, size_t buffer_size, uint32 number,
85  int base=10, int min_digits=0,
87 SYS_API size_t
88 SYSformatInteger(char *buffer, size_t buffer_size, int64 number,
89  int base=10, int min_digits=0,
91 SYS_API size_t
92 SYSformatInteger(char *buffer, size_t buffer_size, uint64 number,
93  int base=10, int min_digits=0,
95 
96 #if defined(MBSD)
97 static inline size_t
98 SYSformatInteger(char *buffer, size_t buffer_size, size_t number,
99  int base=10, int min_digits=0,
101 {
102  return SYSformatInteger(buffer, buffer_size, (uint64)number, base, min_digits, flags);
103 }
104 #endif
105 
106 
107 /// Specifies the notation to use when formatting floating point numbers.
109 {
110  Shortest, ///< Print using the shortest representation, picking
111  /// either fixed-point or normalized scientific
112  /// notation, as needed.
113  /// Corresponds to printf's '%g'/'%G' formatting codes.
114  Fixed, ///< Print using fixed-point notation.
115  /// Corresponds to printf's '%f'/'%F' formatting code.
116  Scientific, ///< Print using normalized scientific notation.
117  /// Corresponds to printf's '%e'/'%E' formatting code.
118  Hexadecimal, ///< Print using the C99 hexadecimal float notation.
119  /// Corresponds to printf's '%a'/'%A' formatting code.
120  Engineering, ///< Print using engineering notation. This is similar
121  /// to normalized scientific notation, except the
122  /// powers are always divisible by 3.
123 };
124 
125 /// Write the text version of float value into a character buffer specified by
126 /// @c buffer of size @c buffer_size. The number of characters written is
127 /// returned. No string terminator value is written out. If the buffer given is
128 /// @c nullptr, then this function immediately returns the amount of space
129 /// needed to store the string.
130 SYS_API size_t
131 SYSformatFloat(char *buffer, size_t buffer_size, fpreal16 number,
132  uint32 precision = 4,
135 
136 SYS_API size_t
137 SYSformatFloat(char *buffer, size_t buffer_size, fpreal32 number,
138  uint32 precision = 6,
141 
142 SYS_API size_t
143 SYSformatFloat(char *buffer, size_t buffer_size, fpreal64 number,
144  uint32 precision = 8,
147 
148 #endif // __SYS_FormatNumber__
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
GLbitfield flags
Definition: glcorearb.h:1596
unsigned short uint16
Definition: SYS_Types.h:38
int int32
Definition: SYS_Types.h:39
SYS_FormatFlags
SYS_API size_t SYSformatInteger(char *buffer, size_t buffer_size, int8 number, int base=10, int min_digits=0, SYS_FormatFlags flags=SYS_FormatFlags::None)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
SYS_FormatNotation
Specifies the notation to use when formatting floating point numbers.
unsigned long long uint64
Definition: SYS_Types.h:117
float fpreal32
Definition: SYS_Types.h:200
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
Definition: core.h:760
long long int64
Definition: SYS_Types.h:116
SYS_API size_t SYSformatFloat(char *buffer, size_t buffer_size, fpreal16 number, uint32 precision=4, SYS_FormatNotation notation=SYS_FormatNotation::Shortest, SYS_FormatFlags flags=SYS_FormatFlags::None)
const TypeMask operator|(const TypeMask &m1, const TypeMask &m2)
Definition: GA_PrimCompat.h:79
signed char int8
Definition: SYS_Types.h:35
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
const TypeMask operator&(const TypeMask &m1, const TypeMask &m2)
Definition: GA_PrimCompat.h:84
GLenum GLint GLint * precision
Definition: glcorearb.h:1925
short int16
Definition: SYS_Types.h:37
Just output the raw number in the given base.
unsigned int uint32
Definition: SYS_Types.h:40
#define SYS_API
Definition: SYS_API.h:11