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

  1 mike  1.8 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.11 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5 mike  1.8  //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.11 // of this software and associated documentation files (the "Software"), to
  8            // deal in the Software without restriction, including without limitation the
  9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10 mike  1.8  // sell copies of the Software, and to permit persons to whom the Software is
 11            // furnished to do so, subject to the following conditions:
 12            // 
 13 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.8  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16 kumpf 1.11 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19 mike  1.8  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21            //
 22            //==============================================================================
 23            //
 24            // Author: Mike Brasher (mbrasher@bmc.com)
 25            //
 26 kumpf 1.14 // Modified By: Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com)
 27 kumpf 1.17 //              Carol Ann Krug Graves, Hewlett-Packard Company
 28            //                (carolann_graves@hp.com)
 29 mike  1.8  //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include <cctype>
 33            #include "CIMName.h"
 34            
 35            PEGASUS_NAMESPACE_BEGIN
 36            
 37 kumpf 1.14 ////////////////////////////////////////////////////////////////////////////////
 38            //
 39            // CIMName
 40            //
 41            ////////////////////////////////////////////////////////////////////////////////
 42            
 43            #define PEGASUS_ARRAY_T CIMName
 44            # include "ArrayImpl.h"
 45            #undef PEGASUS_ARRAY_T
 46            
 47            CIMName::CIMName()
 48                : cimName(String::EMPTY)
 49            {
 50            }
 51            
 52            CIMName::CIMName(const String& name)
 53                : cimName(name)
 54            {
 55                if (!legal(name))
 56                {
 57                    // ATTN: Does this clean up String memory properly?
 58 kumpf 1.16         throw InvalidNameException(name);
 59 kumpf 1.14     }
 60            }
 61            
 62            CIMName::CIMName(const char* name)
 63                : cimName(name)
 64            {
 65                if (!legal(name))
 66                {
 67                    // ATTN: Does this clean up String memory properly?
 68 kumpf 1.16         throw InvalidNameException(name);
 69 kumpf 1.14     }
 70            }
 71            
 72            CIMName& CIMName::operator=(const CIMName& name)
 73            {
 74 kumpf 1.17     cimName=name.cimName;
 75 kumpf 1.14     return *this;
 76            }
 77            
 78            CIMName& CIMName::operator=(const String& name)
 79            {
 80                if (!legal(name))
 81                {
 82 kumpf 1.16         throw InvalidNameException(name);
 83 kumpf 1.14     }
 84                cimName=name;
 85                return *this;
 86            }
 87            
 88 kumpf 1.17 #ifndef PEGASUS_REMOVE_DEPRECATED
 89 kumpf 1.14 CIMName& CIMName::operator=(const char* name)
 90            {
 91                cimName=name;
 92                return *this;
 93            }
 94 kumpf 1.17 #endif
 95 kumpf 1.14 
 96 kumpf 1.17 const String& CIMName::getString() const
 97 kumpf 1.14 {
 98                return cimName;
 99            }
100            
101 kumpf 1.17 #ifndef PEGASUS_REMOVE_DEPRECATED
102 kumpf 1.14 CIMName::operator String() const
103            {
104                return cimName;
105            }
106 kumpf 1.17 #endif
107 kumpf 1.14 
108            Boolean CIMName::isNull() const
109            {
110                return (cimName.size() == 0);
111            }
112            
113            void CIMName::clear()
114            {
115                cimName.clear();
116            }
117            
118 kumpf 1.18 Boolean CIMName::legal(const String& name)
119 mike  1.8  {
120 kumpf 1.12     Uint32 length = name.size();
121 mike  1.8  
122 kumpf 1.12     if (length == 0 || !(isalpha(name[0]) || name[0] == '_'))
123 kumpf 1.10         return false;
124 mike  1.8  
125 kumpf 1.12     for (Uint32 i=1; i<length; i++)
126 mike  1.8      {
127 kumpf 1.14         // ATTN-RK-20020729: Is this check necessary?  Add it to namespace name?
128 kumpf 1.13         if (name[i] > PEGASUS_MAX_PRINTABLE_CHAR)
129 kumpf 1.12             return false;
130 mike  1.8  
131 kumpf 1.14         if (!(isalnum(name[i]) || name[i] == '_'))
132 kumpf 1.12             return false;
133 mike  1.8      }
134            
135                return true;
136 kumpf 1.10 }
137            
138 kumpf 1.14 Boolean CIMName::equal(const CIMName& name) const
139            {
140                return String::equalNoCase(cimName, name.cimName);
141            }
142            
143 kumpf 1.15 Boolean operator==(const CIMName& name1, const CIMName& name2)
144            {
145                return name1.equal(name2);
146            }
147 kumpf 1.14 
148            
149            ////////////////////////////////////////////////////////////////////////////////
150            //
151            // CIMNamespaceName
152            //
153            ////////////////////////////////////////////////////////////////////////////////
154            
155 kumpf 1.17 #define PEGASUS_ARRAY_T CIMNamespaceName
156            # include "ArrayImpl.h"
157            #undef PEGASUS_ARRAY_T
158            
159 kumpf 1.14 CIMNamespaceName::CIMNamespaceName()
160                : cimNamespaceName(String::EMPTY)
161            {
162            }
163            
164            CIMNamespaceName::CIMNamespaceName(const String& name)
165                : cimNamespaceName(name)
166            {
167                if (!legal(name))
168                {
169                    // ATTN: Does this clean up String memory properly?
170 kumpf 1.16         throw InvalidNamespaceNameException(name);
171 kumpf 1.14     }
172            }
173            
174            CIMNamespaceName::CIMNamespaceName(const char* name)
175                : cimNamespaceName(name)
176            {
177                if (!legal(name))
178                {
179                    // ATTN: Does this clean up String memory properly?
180 kumpf 1.16         throw InvalidNamespaceNameException(name);
181 kumpf 1.14     }
182            }
183            
184            CIMNamespaceName& CIMNamespaceName::operator=(const CIMNamespaceName& name)
185            {
186 kumpf 1.17     cimNamespaceName=name.cimNamespaceName;
187 kumpf 1.14     return *this;
188            }
189            
190            CIMNamespaceName& CIMNamespaceName::operator=(const String& name)
191            {
192                if (!legal(name))
193                {
194 kumpf 1.16         throw InvalidNamespaceNameException(name);
195 kumpf 1.14     }
196                cimNamespaceName=name;
197                return *this;
198            }
199            
200 kumpf 1.17 #ifndef PEGASUS_REMOVE_DEPRECATED
201 kumpf 1.14 CIMNamespaceName& CIMNamespaceName::operator=(const char* name)
202            {
203                cimNamespaceName=name;
204                return *this;
205            }
206 kumpf 1.17 #endif
207 kumpf 1.14 
208 kumpf 1.17 const String& CIMNamespaceName::getString() const
209 kumpf 1.14 {
210                return cimNamespaceName;
211            }
212            
213 kumpf 1.17 #ifndef PEGASUS_REMOVE_DEPRECATED
214 kumpf 1.14 CIMNamespaceName::operator String() const
215            {
216                return cimNamespaceName;
217            }
218 kumpf 1.17 #endif
219 kumpf 1.14 
220            Boolean CIMNamespaceName::isNull() const
221            {
222                return (cimNamespaceName.size() == 0);
223            }
224            
225            void CIMNamespaceName::clear()
226            {
227                cimNamespaceName.clear();
228            }
229            
230 kumpf 1.18 Boolean CIMNamespaceName::legal(const String& name)
231 kumpf 1.14 {
232                Uint32 length = name.size();
233                if (length == 0) return true;    // ATTN: Cheap hack!
234            
235                // ATTN-RK-20020729: Hack: Skip leading '/' because spec is ambiguous
236                Uint32 start = 0;
237                if (name[0] == '/')
238                {
239                    start++;
240                }
241            
242                for (Uint32 i=start; i<length; )
243                {
244                    if (!name[i] || (!isalpha(name[i]) && name[i] != '_'))
245                    {
246                        return false;
247                    }
248            
249                    i++;
250            
251                    while (isalnum(name[i]) || name[i] == '_')
252 kumpf 1.14         {
253                        i++;
254                    }
255            
256                    if (name[i] == '/')
257                    {
258                        i++;
259                    }
260                }
261            
262                return true;
263            
264            // Alternate implementation
265            #if 0
266                String temp;
267            
268                // check each namespace segment (delimited by '/') for correctness
269            
270                for(Uint32 i = 0; i < name.size(); i += temp.size() + 1)
271                {
272                    // isolate the segment beginning at i and ending at the first
273 kumpf 1.14         // ocurrance of '/' after i or eos
274            
275                    temp = name.subString(i, name.subString(i).find('/'));
276            
277                    // check segment for correctness
278            
279                    if (!CIMName::legal(temp))
280                    {
281                        return false;
282                    }
283                }
284            
285                return true;
286            #endif
287            }
288            
289            Boolean CIMNamespaceName::equal(const CIMNamespaceName& name) const
290            {
291                return String::equalNoCase(cimNamespaceName, name.cimNamespaceName);
292            }
293 kumpf 1.17 
294            Boolean operator==(const CIMNamespaceName& name1, const CIMNamespaceName& name2)
295            {
296                return name1.equal(name2);
297            }
298 mike  1.8  
299            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2