1 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.4 //
|
3 martin 1.3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.4 //
|
10 martin 1.3 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.4 //
|
17 martin 1.3 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.4 //
|
20 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.4 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.3 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.4 //
|
28 martin 1.3 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.1
30 #ifndef Pegasus_String_Conversion_h
31 #define Pegasus_String_Conversion_h
32
33 #include <Pegasus/Common/Config.h>
34 #include <Pegasus/Common/Linkage.h>
|
35 kumpf 1.2 #include <Pegasus/Common/CIMType.h>
36 #include <cctype>
|
37 mike 1.1
38 PEGASUS_NAMESPACE_BEGIN
39
40 // The following functions convert the integer "x" to a string. The "buffer"
41 // argument is a scratch area that may or may not be used in the conversion.
42 // These functions return a pointer to the converted string and set "size" to
43 // the length of that string.
44
45 PEGASUS_COMMON_LINKAGE
46 const char* Uint8ToString(char buffer[22], Uint8 x, Uint32& size);
47
48 PEGASUS_COMMON_LINKAGE
49 const char* Uint16ToString(char buffer[22], Uint16 x, Uint32& size);
50
51 PEGASUS_COMMON_LINKAGE
52 const char* Uint32ToString(char buffer[22], Uint32 x, Uint32& size);
53
54 PEGASUS_COMMON_LINKAGE
55 const char* Uint64ToString(char buffer[22], Uint64 x, Uint32& size);
56
57 PEGASUS_COMMON_LINKAGE
58 mike 1.1 const char* Sint8ToString(char buffer[22], Sint8 x, Uint32& size);
59
60 PEGASUS_COMMON_LINKAGE
61 const char* Sint16ToString(char buffer[22], Sint16 x, Uint32& size);
62
63 PEGASUS_COMMON_LINKAGE
64 const char* Sint32ToString(char buffer[22], Sint32 x, Uint32& size);
65
66 PEGASUS_COMMON_LINKAGE
67 const char* Sint64ToString(char buffer[22], Sint64 x, Uint32& size);
68
|
69 kumpf 1.2 class PEGASUS_COMMON_LINKAGE StringConversion
70 {
71 public:
72
73 /**
74 Converts a valid hexadecimal character to a Uint8 value.
75 @param c The hexadecimal character to convert
76 @return The converted Uint8 value
77 */
78 static inline Uint8 hexCharToNumeric(const char c)
79 {
80 Uint8 n;
81
82 if (isdigit(c))
83 n = (c - '0');
84 else if (isupper(c))
85 n = (c - 'A' + 10);
86 else // if (islower(c))
87 n = (c - 'a' + 10);
88
89 return n;
90 kumpf 1.2 }
91
92 /**
93 Converts a character string to a Uint64 value according to the DMTF
94 specifications for decimal formatting of integer values in MOF and XML.
95 (The two specifications are identical.)
96 @param stringValue The character string to convert
97 @param x The converted Uint64 value
98 @return true if the character string is well-formatted and the
99 conversion is successful, false otherwise
100 */
101 static Boolean decimalStringToUint64(
102 const char* stringValue,
103 Uint64& x);
104
105 /**
106 Converts a character string to a Uint64 value according to the DMTF
107 specifications for octal formatting of integer values in MOF
108 and XML. (The two specifications are identical.)
109 @param stringValue The character string to convert
110 @param x The converted Uint64 value
111 kumpf 1.2 @return true if the character string is well-formatted and the
112 conversion is successful, false otherwise
113 */
114 static Boolean octalStringToUint64(
115 const char* stringValue,
116 Uint64& x);
117
118 /**
119 Converts a character string to a Uint64 value according to the DMTF
120 specifications for hexadecimal formatting of integer values in MOF
121 and XML. (The two specifications are identical.)
122 @param stringValue The character string to convert
123 @param x The converted Uint64 value
124 @return true if the character string is well-formatted and the
125 conversion is successful, false otherwise
126 */
127 static Boolean hexStringToUint64(
128 const char* stringValue,
129 Uint64& x);
130
131 /**
132 kumpf 1.2 Converts a character string to a Uint64 value according to the DMTF
133 specifications for binary formatting of integer values in MOF
134 and XML. (The two specifications are identical.)
135 @param stringValue The character string to convert
136 @param x The converted Uint64 value
137 @return true if the character string is well-formatted and the
138 conversion is successful, false otherwise
139 */
140 static Boolean binaryStringToUint64(
141 const char* stringValue,
142 Uint64& x);
143
144 /**
145 Checks whether a specified Uint64 value will fit within a specified
146 unsigned integer type (e.g., Uint8, Uint16, Uint32) without overflow.
147 @param x The Uint64 value to check
148 @param type A CIMType specifying the constraining unsigned integer size
149 @return true if the specified integer fits within the specified type,
150 false otherwise
151 */
152 static Boolean checkUintBounds(
153 kumpf 1.2 Uint64 x,
154 CIMType type);
155
156 /**
157 Converts a character string to an Sint64 value by interpreting the
158 optional leading sign character and using the specified function to
159 convert the remainder of the string to a Uint64. Bounds checking is
160 performed when converting the Uint64 to Sint64.
161 @param stringValue The character string to convert
162 @param uint64Converter The function used to convert the unsigned
163 portion of the string to a Uint64 value.
164 @param x The converted Sint64 value
165 @return true if the character string is well-formatted and the
166 conversion is successful, false otherwise
167 */
168 static Boolean stringToSint64(
169 const char* stringValue,
170 Boolean (*uint64Converter)(const char*, Uint64&),
171 Sint64& x);
172
173 /**
174 kumpf 1.2 Checks whether a specified Sint64 value will fit within a specified
175 signed integer type (e.g., Sint8, Sint16, Sint32) without overflow.
176 @param x The Sint64 value to check
177 @param type A CIMType specifying the constraining signed integer size
178 @return true if the specified integer fits within the specified type,
179 false otherwise
180 */
181 static Boolean checkSintBounds(
182 Sint64 x,
183 CIMType type);
184
185 /**
186 Converts a character string to a Real64 value according to the DMTF
187 specifications for formatting real values in MOF and XML. (The two
188 specifications are identical.)
189 @param stringValue The character string to convert
190 @param x The converted Real64 value
191 @return true if the character string is well-formatted and the
192 conversion is successful, false otherwise
193 */
194 static Boolean stringToReal64(
195 kumpf 1.2 const char* stringValue,
196 Real64& x);
197 };
198
|
199 mike 1.1 PEGASUS_NAMESPACE_END
200
201 #endif /* Pegasus_String_Conversion_h */
|