1 martin 1.2 //%LICENSE////////////////////////////////////////////////////////////////
2 //
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 //
10 // 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 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 martin 1.2 // 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.
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_CIMNameCast_h
33 #define Pegasus_CIMNameCast_h
34
35 #include <Pegasus/Common/CIMName.h>
36
37 PEGASUS_NAMESPACE_BEGIN
38
39 //
40 // This function performs a compile-time cast from String to CIMName. It should
41 // only be used where the String is already known to contain a valid CIM name,
42 // thereby avoiding the overhead of checking every character of the String.
43 // This cast is possible because CIMName has a single String member. Note that
44 // that sizeof(CIMName) == sizeof(String) and that the classes are identical
45 // in their representation, differing only by interface. When compiled for
46 // debug, this function checks that str refers to a valid CIM name.
47 //
48 inline const CIMName& CIMNameCast(const String& str)
49 {
50 kumpf 1.1 #if defined(PEGASUS_DEBUG)
51
52 if (str.size() && !CIMName::legal(str))
53 {
54 throw InvalidNameException(str);
55 }
56
57 #endif
58
59 return *(reinterpret_cast<const CIMName*>(&str));
60 }
61
62 inline const CIMNamespaceName& CIMNamespaceNameCast(const String& str)
63 {
64 #if defined(PEGASUS_DEBUG)
65
66 if (str.size() && !CIMNamespaceName::legal(str))
67 {
68 throw InvalidNamespaceNameException(str);
69 }
70
71 kumpf 1.1 #endif
72
73 return *(reinterpret_cast<const CIMNamespaceName*>(&str));
74 }
75
76
77 /** Checks whether a given character string consists of ASCII only and
78 legal characters for a CIMName (i.e. letter, numbers and underscore)
79 The first character has to be a letter or underscore
80 @param str character string to be checked
81 @return 0 in case non-legal ASCII character was found
82 >0 length of the character string str
83 */
84 PEGASUS_COMMON_LINKAGE Uint32 CIMNameLegalASCII(const char* str);
85
86 PEGASUS_NAMESPACE_END
87
88 #endif /* Pegasus_CIMNameCast_h */
|