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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2