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

  1 karl  1.32 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.8  //
  3 karl  1.27 // 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 karl  1.23 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.27 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.28 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.32 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.8  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 kumpf 1.11 // 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 mike  1.8  // 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 karl  1.32 // 
 21 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.8  // 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 kumpf 1.11 // 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 mike  1.8  // 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            // Author: Mike Brasher (mbrasher@bmc.com)
 33            //
 34 kumpf 1.14 // Modified By: Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com)
 35 kumpf 1.17 //              Carol Ann Krug Graves, Hewlett-Packard Company
 36 david.dillard 1.29 //                  (carolann_graves@hp.com)
 37                    //              David Dillard, VERITAS Software Corp.
 38                    //                  (david.dillard@veritas.com)
 39 mike          1.8  //
 40                    //%/////////////////////////////////////////////////////////////////////////////
 41                    
 42                    #include <cctype>
 43                    #include "CIMName.h"
 44 david         1.19 #include "CommonUTF.h"
 45 r.kieninger   1.31 #include "CharSet.h"
 46 mike          1.8  
 47                    PEGASUS_NAMESPACE_BEGIN
 48                    
 49 kumpf         1.14 ////////////////////////////////////////////////////////////////////////////////
 50                    //
 51                    // CIMName
 52                    //
 53                    ////////////////////////////////////////////////////////////////////////////////
 54                    
 55                    #define PEGASUS_ARRAY_T CIMName
 56                    # include "ArrayImpl.h"
 57                    #undef PEGASUS_ARRAY_T
 58                    
 59 r.kieninger   1.31 CIMName::CIMName(const String& name) : cimName(name)
 60 kumpf         1.14 {
 61 r.kieninger   1.31     if (!legal(name))
 62                            throw InvalidNameException(name);
 63 kumpf         1.14 }
 64                    
 65 r.kieninger   1.31 CIMName::CIMName(const char* name) : cimName(name)
 66 kumpf         1.14 {
 67                        if (!legal(name))
 68 kumpf         1.16         throw InvalidNameException(name);
 69 kumpf         1.14 }
 70                    
 71 r.kieninger   1.31 CIMName& CIMName::operator=(const String& name)
 72 kumpf         1.14 {
 73                        if (!legal(name))
 74 kumpf         1.16         throw InvalidNameException(name);
 75 kumpf         1.14 
 76 r.kieninger   1.31     cimName=name;
 77 kumpf         1.14     return *this;
 78                    }
 79                    
 80 r.kieninger   1.31 CIMName& CIMName::operator=(const char* name)
 81 kumpf         1.14 {
 82                        if (!legal(name))
 83 kumpf         1.16         throw InvalidNameException(name);
 84 r.kieninger   1.31 
 85                        cimName = name;
 86 kumpf         1.14     return *this;
 87                    }
 88                    
 89 r.kieninger   1.31 Boolean CIMName::legal(const String& name)
 90 kumpf         1.14 {
 91 r.kieninger   1.31     // Check first character.
 92 kumpf         1.14 
 93 r.kieninger   1.31     const Uint16* p = (const Uint16*)name.getChar16Data();
 94                        size_t n = name.size();
 95 kumpf         1.14 
 96 r.kieninger   1.31     if (!(*p < 128 && CharSet::isAlphaUnder(*p)))
 97                        {
 98                    	if (!(*p >= 0x0080 && *p <= 0xFFEF))
 99                                return false;
100                        }
101 kumpf         1.14 
102 r.kieninger   1.31     p++;
103                        n--;
104 mike          1.8  
105 r.kieninger   1.31     // Use loop unrolling to skip over good ASCII 7-bit characters.
106 mike          1.8  
107 r.kieninger   1.31     while (n >= 4)
108                        {
109                    	if (p[0] < 128 && CharSet::isAlNumUnder(p[0]) &&
110                    	    p[1] < 128 && CharSet::isAlNumUnder(p[1]) &&
111                    	    p[2] < 128 && CharSet::isAlNumUnder(p[2]) &&
112                    	    p[3] < 128 && CharSet::isAlNumUnder(p[3]))
113                    	{
114                    	    p += 4;
115                    	    n -= 4;
116                    	    continue;
117                    	}
118 david         1.19 
119 r.kieninger   1.31 	break;
120 david         1.20     }
121 kumpf         1.21 
122 r.kieninger   1.31     // Process remaining charcters.
123                    
124                        while (n)
125 mike          1.8      {
126 r.kieninger   1.31 	if (!(*p < 128 && CharSet::isAlNumUnder(*p)))
127                    	{
128                    	    if (!(*p >= 0x0080 && *p <= 0xFFEF))
129                    		return false;
130                    	}
131                    	p++;
132                    	n--;
133 mike          1.8      }
134                    
135                        return true;
136 kumpf         1.10 }
137                    
138 kumpf         1.14 ////////////////////////////////////////////////////////////////////////////////
139                    //
140                    // CIMNamespaceName
141                    //
142                    ////////////////////////////////////////////////////////////////////////////////
143                    
144 kumpf         1.17 #define PEGASUS_ARRAY_T CIMNamespaceName
145                    # include "ArrayImpl.h"
146                    #undef PEGASUS_ARRAY_T
147                    
148 r.kieninger   1.31 inline void _check_namespace_name(String& name)
149 kumpf         1.14 {
150 r.kieninger   1.31     if (!CIMNamespaceName::legal(name))
151                            throw InvalidNamespaceNameException(name);
152                    
153                        if (name[0] == '/')
154                            name.remove(0, 1);
155 kumpf         1.14 }
156                    
157 r.kieninger   1.31 CIMNamespaceName::CIMNamespaceName(const String& name) 
158                        : cimNamespaceName(name)
159 kumpf         1.14 {
160 r.kieninger   1.31     _check_namespace_name(cimNamespaceName);
161 kumpf         1.14 }
162                    
163 r.kieninger   1.31 CIMNamespaceName::CIMNamespaceName(const char* name) 
164                        : cimNamespaceName(name)
165 kumpf         1.14 {
166 r.kieninger   1.31     _check_namespace_name(cimNamespaceName);
167 kumpf         1.14 }
168                    
169                    CIMNamespaceName& CIMNamespaceName::operator=(const CIMNamespaceName& name)
170                    {
171 r.kieninger   1.31     cimNamespaceName = name.cimNamespaceName;
172 kumpf         1.14     return *this;
173                    }
174                    
175                    CIMNamespaceName& CIMNamespaceName::operator=(const String& name)
176                    {
177 r.kieninger   1.31     cimNamespaceName = name;
178                        _check_namespace_name(cimNamespaceName);
179 kumpf         1.14     return *this;
180                    }
181                    
182 r.kieninger   1.31 CIMNamespaceName& CIMNamespaceName::operator=(const char* name)
183 kumpf         1.14 {
184 r.kieninger   1.31     cimNamespaceName = name;
185                        _check_namespace_name(cimNamespaceName);
186                        return *this;
187 kumpf         1.14 }
188                    
189 kumpf         1.18 Boolean CIMNamespaceName::legal(const String& name)
190 kumpf         1.14 {
191 kumpf         1.21     Uint32 length = name.size();
192                        Uint32 index = 0;
193 kumpf         1.14 
194 kumpf         1.21     // Skip a leading '/' because the CIM specification is ambiguous
195                        if (name[0] == '/')
196 david         1.19     {
197 kumpf         1.21         index++;
198 kumpf         1.14     }
199                    
200 kumpf         1.21     Boolean moreElements = true;
201 kumpf         1.14 
202 kumpf         1.21     // Check each namespace element (delimited by '/' characters)
203                        while (moreElements)
204 kumpf         1.14     {
205 kumpf         1.21         moreElements = false;
206 kumpf         1.14 
207 kumpf         1.21         if (index == length)
208                            {
209                                return false;
210                            }
211 kumpf         1.14 
212 r.kieninger   1.31         Uint16 ch = name[index++];
213 kumpf         1.14 
214 kumpf         1.21         // First character must be alphabetic or '_' if ASCII
215 r.kieninger   1.31 
216                            if (!((ch >= 0x0080 && ch <= 0xFFEF) || CharSet::isAlphaUnder(ch)))
217 kumpf         1.14             return false;
218 kumpf         1.21 
219                            // Remaining characters must be alphanumeric or '_' if ASCII
220                            while (index < length)
221                            {
222 r.kieninger   1.31             ch = name[index++];
223 kumpf         1.21 
224                                // A '/' indicates another namespace element follows
225 r.kieninger   1.31             if (ch == '/')
226 kumpf         1.21             {
227                                    moreElements = true;
228                                    break;
229                                }
230                    
231 r.kieninger   1.31 	    if(!((ch >= 0x0080 && ch <= 0xFFEF) || CharSet::isAlNumUnder(ch)))
232 kumpf         1.21                 return false;
233                            }
234 kumpf         1.14     }
235                    
236                        return true;
237                    }
238                    
239 r.kieninger   1.31 Boolean operator==(const CIMNamespaceName& name1, const CIMNamespaceName& name2)
240 kumpf         1.14 {
241 r.kieninger   1.31     return name1.equal(name2);
242 kumpf         1.14 }
243 kumpf         1.17 
244 r.kieninger   1.31 Boolean operator==(const CIMNamespaceName& name1, const char* name2)
245 kumpf         1.17 {
246                        return name1.equal(name2);
247                    }
248 mike          1.8  
249 r.kieninger   1.31 Boolean operator==(const char* name1, const CIMNamespaceName& name2)
250                    {
251                        return name2.equal(name1);
252                    }
253                    
254 david.dillard 1.29 Boolean operator!=(const CIMNamespaceName& name1, const CIMNamespaceName& name2)
255                    {
256                        return !name1.equal(name2);
257                    }
258                    
259 r.kieninger   1.31 Boolean operator!=(const CIMNamespaceName& name1, const char* name2)
260                    {
261                        return !name1.equal(name2);
262                    }
263                    
264                    Boolean operator!=(const char* name1, const CIMNamespaceName& name2)
265                    {
266                        return !name2.equal(name1);
267                    }
268                    
269 mike          1.8  PEGASUS_NAMESPACE_END
270 r.kieninger   1.31 
271                    /*
272                    ================================================================================
273                    
274                    Optimizations:
275                    
276                        1. Optimized legal().
277                        2. Implmented "char*" version of operator=().
278                        3. Added conditional inlining (for Pegaus internal use).
279                        4. Added comparison functions for "char*".
280                        5. Implemented "unchecked" version of constructors and assignment operators
281                           that take String or "char*".
282                        6. Added loop unrolling to CIMName::legal()
283                    
284                    ================================================================================
285                    */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2