(file) Return to StringConversion.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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 kumpf  1.5 // The following functions convert the integer "x" to a string. The "buffer"
 41 mike   1.1 // argument is a scratch area that may or may not be used in the conversion.
 42 kumpf  1.5 // These functions return a pointer to the converted string and set "size" to
 43 mike   1.1 // 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            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 mike   1.1 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 thilo.boehm 1.6 PEGASUS_COMMON_LINKAGE
 70                 const char* Real32ToString(char buffer[128], Real32 x, Uint32& size);
 71                 
 72                 PEGASUS_COMMON_LINKAGE
 73                 const char* Real64ToString(char buffer[128], Real64 x, Uint32& size);
 74                 
 75                 
 76 kumpf       1.2 class PEGASUS_COMMON_LINKAGE StringConversion
 77                 {
 78                 public:
 79                 
 80                     /**
 81                         Converts a valid hexadecimal character to a Uint8 value.
 82 kumpf       1.5         @param c The hexadecimal character to convert
 83 kumpf       1.2         @return The converted Uint8 value
 84                     */
 85                     static inline Uint8 hexCharToNumeric(const char c)
 86                     {
 87                         Uint8 n;
 88                 
 89                         if (isdigit(c))
 90                             n = (c - '0');
 91                         else if (isupper(c))
 92                             n = (c - 'A' + 10);
 93                         else // if (islower(c))
 94                             n = (c - 'a' + 10);
 95                 
 96                         return n;
 97                     }
 98                 
 99                     /**
100                         Converts a character string to a Uint64 value according to the DMTF
101                         specifications for decimal formatting of integer values in MOF and XML.
102                         (The two specifications are identical.)
103 kumpf       1.5         @param stringValue The character string to convert
104 kumpf       1.2         @param x The converted Uint64 value
105                         @return true if the character string is well-formatted and the
106                             conversion is successful, false otherwise
107                     */
108                     static Boolean decimalStringToUint64(
109                         const char* stringValue,
110 ajay.rao    1.7         Uint64& x,
111                         Boolean allowLeadingZeros=false);
112 kumpf       1.2 
113                     /**
114                         Converts a character string to a Uint64 value according to the DMTF
115                         specifications for octal formatting of integer values in MOF
116                         and XML.  (The two specifications are identical.)
117 kumpf       1.5         @param stringValue The character string to convert
118 kumpf       1.2         @param x The converted Uint64 value
119                         @return true if the character string is well-formatted and the
120                             conversion is successful, false otherwise
121                     */
122                     static Boolean octalStringToUint64(
123                         const char* stringValue,
124 ajay.rao    1.7         Uint64& x,
125                         Boolean allowLeadingZeros = false);
126 kumpf       1.2 
127                     /**
128                         Converts a character string to a Uint64 value according to the DMTF
129                         specifications for hexadecimal formatting of integer values in MOF
130                         and XML.  (The two specifications are identical.)
131 kumpf       1.5         @param stringValue The character string to convert
132 kumpf       1.2         @param x The converted Uint64 value
133                         @return true if the character string is well-formatted and the
134                             conversion is successful, false otherwise
135                     */
136                     static Boolean hexStringToUint64(
137                         const char* stringValue,
138 ajay.rao    1.7         Uint64& x,
139                         Boolean allowLeadingZeros = false);
140 kumpf       1.2 
141                     /**
142                         Converts a character string to a Uint64 value according to the DMTF
143                         specifications for binary formatting of integer values in MOF
144                         and XML.  (The two specifications are identical.)
145 kumpf       1.5         @param stringValue The character string to convert
146 kumpf       1.2         @param x The converted Uint64 value
147                         @return true if the character string is well-formatted and the
148                             conversion is successful, false otherwise
149                     */
150                     static Boolean binaryStringToUint64(
151                         const char* stringValue,
152 ajay.rao    1.7         Uint64& x, 
153                         Boolean allowLeadingZeros = false);
154 kumpf       1.2 
155                     /**
156                         Checks whether a specified Uint64 value will fit within a specified
157                         unsigned integer type (e.g., Uint8, Uint16, Uint32) without overflow.
158                         @param x The Uint64 value to check
159                         @param type A CIMType specifying the constraining unsigned integer size
160                         @return true if the specified integer fits within the specified type,
161                             false otherwise
162                     */
163                     static Boolean checkUintBounds(
164                         Uint64 x,
165                         CIMType type);
166                 
167                     /**
168                         Converts a character string to an Sint64 value by interpreting the
169 kumpf       1.5         optional leading sign character and using the specified function to
170 kumpf       1.2         convert the remainder of the string to a Uint64.  Bounds checking is
171                         performed when converting the Uint64 to Sint64.
172 kumpf       1.5         @param stringValue The character string to convert
173 kumpf       1.2         @param uint64Converter The function used to convert the unsigned
174                             portion of the string to a Uint64 value.
175                         @param x The converted Sint64 value
176                         @return true if the character string is well-formatted and the
177                             conversion is successful, false otherwise
178                     */
179                     static Boolean stringToSint64(
180                         const char* stringValue,
181 ajay.rao    1.7         Boolean (*uint64Converter)(const char*, Uint64&,Boolean),
182 kumpf       1.2         Sint64& x);
183                 
184                     /**
185                         Checks whether a specified Sint64 value will fit within a specified
186                         signed integer type (e.g., Sint8, Sint16, Sint32) without overflow.
187                         @param x The Sint64 value to check
188                         @param type A CIMType specifying the constraining signed integer size
189                         @return true if the specified integer fits within the specified type,
190                             false otherwise
191                     */
192                     static Boolean checkSintBounds(
193                         Sint64 x,
194                         CIMType type);
195                 
196                     /**
197                         Converts a character string to a Real64 value according to the DMTF
198                         specifications for formatting real values in MOF and XML.  (The two
199                         specifications are identical.)
200 kumpf       1.5         @param stringValue The character string to convert
201 kumpf       1.2         @param x The converted Real64 value
202                         @return true if the character string is well-formatted and the
203                             conversion is successful, false otherwise
204                     */
205                     static Boolean stringToReal64(
206                         const char* stringValue,
207                         Real64& x);
208 thilo.boehm 1.6 
209                     static Boolean stringToSignedInteger(
210                         const char* stringValue,
211                         Sint64& x);
212                 
213                     static Boolean stringToUnsignedInteger(
214                         const char* stringValue,
215                         Uint64& x);
216                 
217 kumpf       1.2 };
218                 
219 mike        1.1 PEGASUS_NAMESPACE_END
220                 
221                 #endif /* Pegasus_String_Conversion_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2