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

  1 martin 1.18 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.19 //
  3 martin 1.18 // 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.19 //
 10 martin 1.18 // 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.19 //
 17 martin 1.18 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.19 //
 20 martin 1.18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.19 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.18 // 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.19 //
 28 martin 1.18 //////////////////////////////////////////////////////////////////////////
 29 mike   1.2  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32 mike   1.17 #include "CIMPropertyListRep.h"
 33 mike   1.2  #include "CIMPropertyList.h"
 34 karl   1.19.8.1 #include "OrderedSet.h"
 35 mike   1.2      
 36                 PEGASUS_NAMESPACE_BEGIN
 37                 
 38 karl   1.19.8.1 template<class REP>
 39                 inline void Ref(REP* rep)
 40                 {
 41                         rep->_refCounter++;
 42                 }
 43                 
 44                 template<class REP>
 45                 inline void Unref(REP* rep)
 46                 {
 47                     if (rep->_refCounter.decAndTestIfZero())
 48                         delete rep;
 49                 }
 50                 
 51 a.arora 1.10     CIMPropertyList::CIMPropertyList()
 52 kumpf   1.3      {
 53 a.arora 1.10         _rep = new CIMPropertyListRep();
 54 mike    1.2      }
 55                  
 56 a.arora 1.10     CIMPropertyList::CIMPropertyList(const CIMPropertyList& x)
 57 mike    1.2      {
 58 karl    1.19.8.1     _rep = x._rep;
 59                      Ref(_rep);
 60 kumpf   1.3      }
 61 mike    1.2      
 62 karl    1.19.8.1 static inline CIMPropertyListRep* _copyOnWriteCIMPropertyListRep(
 63                      CIMPropertyListRep* rep)
 64 kumpf   1.3      {
 65 karl    1.19.8.1     if (rep->_refCounter.get() > 1)
 66                      {
 67                          CIMPropertyListRep* tmpRep= new CIMPropertyListRep(*rep);
 68                          Unref(rep);
 69                          return tmpRep;
 70                      }
 71                      else
 72                      {
 73                          return rep;
 74                      }
 75                  }
 76 chip    1.13     
 77 karl    1.19.8.1 CIMPropertyList::CIMPropertyList(const Array<CIMName>& propertyNames)
 78                  {
 79 chip    1.13         // ATTN: the following code is inefficient and problematic. besides
 80                      // adding overhead to check for null property names, it has the
 81                      // disadvantage of returning an error if only 1 of n properties are null
 82                      // without informing the caller of which one. this is mainly a problem
 83                      // with this object's interface. it should be more like CIMQualifierList,
 84                      // which has a add() method that would validate one at a time.
 85                  
 86                      // ensure names are not null
 87 kumpf   1.16         for (Uint32 i = 0, n = propertyNames.size(); i < n; i++)
 88 chip    1.13         {
 89 kumpf   1.16             if (propertyNames[i].isNull())
 90 chip    1.13             {
 91                              throw UninitializedObjectException();
 92                          }
 93                      }
 94 karl    1.19.8.1     _rep = new CIMPropertyListRep();
 95 kumpf   1.3          _rep->propertyNames = propertyNames;
 96                      _rep->isNull = false;
 97 mike    1.2      }
 98                  
 99 kumpf   1.3      CIMPropertyList::~CIMPropertyList()
100 mike    1.2      {
101 karl    1.19.8.1     Unref(_rep);
102 mike    1.2      }
103                  
104 kumpf   1.6      void CIMPropertyList::set(const Array<CIMName>& propertyNames)
105 mike    1.2      {
106 chip    1.13         // ATTN: the following code is inefficient and problematic. besides
107                      // adding overhead to check for null property names, it has the
108                      // disadvantage of returning an error if only 1 of n properties are null
109                      // without informing the caller of which one. this is mainly a problem
110                      // with this object's interface. it should be more like CIMQualifierList,
111                      // which has a add() method that would validate one at a time.
112                  
113                      // ensure names are not null
114 kumpf   1.16         for (Uint32 i = 0, n = propertyNames.size(); i < n; i++)
115 chip    1.13         {
116 kumpf   1.16             if (propertyNames[i].isNull())
117 chip    1.13             {
118                              throw UninitializedObjectException();
119                          }
120                      }
121 karl    1.19.8.1     _rep = _copyOnWriteCIMPropertyListRep(_rep);
122                      
123 kumpf   1.3          _rep->propertyNames = propertyNames;
124 karl    1.19.8.1     _rep->cimNameTags.clear();
125 kumpf   1.3          _rep->isNull = false;
126 karl    1.19.8.1     _rep->isCimNameTagsUpdated = false;
127 mike    1.2      }
128                  
129                  CIMPropertyList& CIMPropertyList::operator=(const CIMPropertyList& x)
130                  {
131 karl    1.19.8.1     if (x._rep != _rep)
132 mike    1.2          {
133 karl    1.19.8.1         Unref(_rep);
134                          _rep = x._rep;
135                          Ref(_rep);
136 mike    1.2          }
137                      return *this;
138                  }
139                  
140                  void CIMPropertyList::clear()
141                  {
142 karl    1.19.8.1     // If there is more than one reference
143                      // remove reference and get a new shiny empty representation
144                      if (_rep->_refCounter.get() > 1)
145                      {
146                          Unref(_rep);
147                          _rep = new CIMPropertyListRep();
148                      }
149                      else
150                      {
151                          // If there is only one reference
152                          // no need to copy the data, we own it
153                          // just clear the fields
154                          _rep->propertyNames.clear();
155                          _rep->isNull = true;
156                          if(_rep->isCimNameTagsUpdated)
157                          { 
158                              _rep->cimNameTags.clear();
159                              _rep->isCimNameTagsUpdated = false;
160                          }
161                      }
162 kumpf   1.3      }
163                  
164                  Boolean CIMPropertyList::isNull() const
165                  {
166                      return _rep->isNull;
167                  }
168                  
169 kumpf   1.5      Uint32 CIMPropertyList::size() const
170 kumpf   1.3      {
171                      return _rep->propertyNames.size();
172                  }
173                  
174 kumpf   1.7      const CIMName& CIMPropertyList::operator[](Uint32 index) const
175 kumpf   1.3      {
176 kumpf   1.7          return _rep->propertyNames[index];
177 kumpf   1.3      }
178                  
179 kumpf   1.6      Array<CIMName> CIMPropertyList::getPropertyNameArray() const
180 kumpf   1.3      {
181                      return _rep->propertyNames;
182 mike    1.2      }
183                  
184 karl    1.19.8.1 Uint32 CIMPropertyList::getCIMNameTag(Uint32 index) const
185                  {
186                      return _rep->cimNameTags[index]; 
187                  }
188                  void CIMPropertyList::append(Array<String> & propertyListArray)
189                  {
190                      _rep = _copyOnWriteCIMPropertyListRep(_rep);
191                      Array<Uint32> cimNameTags;
192                      Array<CIMName> cimNameArray;
193                      for (Uint32 i = 0; i < propertyListArray.size(); i++)
194                      {
195                          CIMName name(propertyListArray[i]);
196                          Uint32 tag = generateCIMNameTag(name);
197                          Boolean dupFound=false;
198                          for(Uint32 j=0;j<cimNameTags.size();j++)
199                          {
200                              if ((tag == cimNameTags[j]) && (name == cimNameArray[j]))
201                              {
202                                  dupFound = true;
203                                  break;
204                              }
205 karl    1.19.8.1         }
206                          if(!dupFound)
207                          {
208                              cimNameTags.append(tag);
209                              cimNameArray.append(name);
210                          }
211                      }
212                      if(cimNameTags.size() != 0 )
213                      {
214                          _rep->cimNameTags.appendArray(cimNameTags);
215                          _rep->propertyNames = cimNameArray;
216                          _rep->isCimNameTagsUpdated = true;
217                      }
218                      _rep->isNull = false;
219                  }
220                  
221                  void CIMPropertyList::appendCIMNameTag(Uint32 nameTag)
222                  {
223                      _rep = _copyOnWriteCIMPropertyListRep(_rep);
224                      _rep->cimNameTags.append(nameTag);
225                  }
226 karl    1.19.8.1 
227 karl    1.19.8.2 String CIMPropertyList::toString() const
228                  {
229                      if (_rep->isNull)
230                          return("NULL");
231                  
232                      if (_rep->propertyNames.size() == 0)
233                          return("EMPTY");
234                  
235                      String rtn;
236                      for (Uint32 i = 0 ; i < _rep->propertyNames.size() ; i++)
237                      {
238                          if (i != 0)
239                              rtn.append(",");
240                          rtn.append(_rep->propertyNames[i].getString());
241                      }
242                      return(rtn);
243                  }
244                  
245 mike    1.2      PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2