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

Diff for /pegasus/src/Pegasus/Common/AcceptLanguageList.cpp between version 1.2 and 1.6

version 1.2, 2006/01/30 16:16:45 version 1.6, 2008/12/01 17:49:32
Line 1 
Line 1 
 //%2006////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development  // Licensed to The Open Group (TOG) under one or more contributor license
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;  // this work for additional information regarding copyright ownership.
 // IBM Corp.; EMC Corporation, The Open Group.  // Each contributor licenses this file to you under the OpenPegasus Open
 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;  // Source License; you may not use this file except in compliance with the
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.  // License.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;  //
 // EMC Corporation; VERITAS Software Corporation; The Open Group.  // Permission is hereby granted, free of charge, to any person obtaining a
 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;  // copy of this software and associated documentation files (the "Software"),
 // EMC Corporation; Symantec Corporation; The Open Group.  // to deal in the Software without restriction, including without limitation
 //  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 // Permission is hereby granted, free of charge, to any person obtaining a copy  // and/or sell copies of the Software, and to permit persons to whom the
 // of this software and associated documentation files (the "Software"), to  // Software is furnished to do so, subject to the following conditions:
 // deal in the Software without restriction, including without limitation the  //
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  // The above copyright notice and this permission notice shall be included
 // sell copies of the Software, and to permit persons to whom the Software is  // in all copies or substantial portions of the Software.
 // furnished to do so, subject to the following conditions:  //
 //  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
 // //
 //==============================================================================  //////////////////////////////////////////////////////////////////////////
 //  
 // Author: Humberto Rivero (hurivero@us.ibm.com)  
 //  
 // Modified By: Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3514  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 41 
Line 34 
 #include <Pegasus/Common/InternalException.h> #include <Pegasus/Common/InternalException.h>
 #include <Pegasus/Common/AutoPtr.h> #include <Pegasus/Common/AutoPtr.h>
 #include <Pegasus/Common/ArrayInternal.h> #include <Pegasus/Common/ArrayInternal.h>
   #include <Pegasus/Common/Pair.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 //////////////////////////////////////////////////////////////  typedef Pair<LanguageTag, Real32> AcceptLanguagePair;
 //  typedef Array<AcceptLanguagePair> AcceptLanguageArray;
 // AcceptLanguageListRep  
 //  
 //////////////////////////////////////////////////////////////  
  
 class AcceptLanguageListRep  #define PEGASUS_ARRAY_T AcceptLanguagePair
 {  # include <Pegasus/Common/ArrayInter.h>
 public:  # include "ArrayImpl.h"
     Array<LanguageTag> languageTags;  #undef PEGASUS_ARRAY_T
     Array<Real32> qualityValues;  
 };  
  
 //////////////////////////////////////////////////////////////  
 // //
 // AcceptLanguageList  // Implementation Notes:
   // =====================
   //
   // The internal representation member (_rep) is a pointer to an
   // AcceptLanguageListRep object. We could define a class with this name
   // as follows:
   //
   //     class AcceptLanguageListRep
   //     {
   //         AcceptLanguageArray array;
   //     };
   //
   // But this requires separate heap object to hold the array. Instead we use
   // the following fact to eliminate the extra heap object:
   //
   //     sizeof(AcceptLanguageArray) == sizeof(AcceptLanguageListRep*)
   //
   // We know this since all arrays contain a single pointer to a representation
   // object. Take for example the following structure:
   //
   //     class MyClass
   //     {
   //         void* rep;
   //     };
   //
   // Clearly, sizeof(MyClass) == sizeof(void*). We eliminate the extra heap object
   // by overlaying the AcceptLanguageList::_rep pointer with the array base. So
   // AcceptLanguageList::_rep in fact refers to the Array<T>::_rep.
 // //
 //////////////////////////////////////////////////////////////  
  
 AcceptLanguageList::AcceptLanguageList()  static inline AcceptLanguageArray& GetAcceptLanguageArray(
       AcceptLanguageList* list)
 { {
     _rep = new AcceptLanguageListRep();      return *reinterpret_cast<AcceptLanguageArray*>(list);
 } }
  
 AcceptLanguageList::AcceptLanguageList(  static inline const AcceptLanguageArray& GetAcceptLanguageArray(
     const AcceptLanguageList& acceptLanguages)      const AcceptLanguageList* list)
 { {
     _rep = new AcceptLanguageListRep();      return *reinterpret_cast<const AcceptLanguageArray*>(list);
     AutoPtr<AcceptLanguageListRep> rep(_rep);  }
  
     _rep->languageTags = acceptLanguages._rep->languageTags;  AcceptLanguageList::AcceptLanguageList()
     _rep->qualityValues = acceptLanguages._rep->qualityValues;  {
       AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       new (&self) AcceptLanguageArray;
   }
  
     rep.release();  AcceptLanguageList::AcceptLanguageList(const AcceptLanguageList& x)
   {
       AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       const AcceptLanguageArray& other = GetAcceptLanguageArray(&x);
       new (&self) AcceptLanguageArray(other);
 } }
  
 AcceptLanguageList::~AcceptLanguageList() AcceptLanguageList::~AcceptLanguageList()
 { {
     delete _rep;      AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       self.~AcceptLanguageArray();
 } }
  
 AcceptLanguageList& AcceptLanguageList::operator=(  AcceptLanguageList& AcceptLanguageList::operator=(const AcceptLanguageList& x)
     const AcceptLanguageList& acceptLanguages)  
 { {
     if (&acceptLanguages != this)      AcceptLanguageArray& self = GetAcceptLanguageArray(this);
     {      const AcceptLanguageArray& other = GetAcceptLanguageArray(&x);
         _rep->languageTags = acceptLanguages._rep->languageTags;  
         _rep->qualityValues = acceptLanguages._rep->qualityValues;      if (&self != &other)
     }          self = other;
     return *this;     return *this;
 } }
  
 Uint32 AcceptLanguageList::size() const Uint32 AcceptLanguageList::size() const
 { {
     return _rep->languageTags.size();      const AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       return self.size();
 } }
  
 LanguageTag AcceptLanguageList::getLanguageTag(Uint32 index) const LanguageTag AcceptLanguageList::getLanguageTag(Uint32 index) const
 { {
     return _rep->languageTags[index];      const AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       return self[index].first;
 } }
  
 Real32 AcceptLanguageList::getQualityValue(Uint32 index) const  Real32 AcceptLanguageList::getQualityValue(Uint32 i) const
 { {
     return _rep->qualityValues[index];      const AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       return self[i].second;
 } }
  
 void AcceptLanguageList::insert( void AcceptLanguageList::insert(
Line 117 
Line 142 
 { {
     LanguageParser::validateQualityValue(qualityValue);     LanguageParser::validateQualityValue(qualityValue);
  
     // Insert in order of descending quality value      AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       Uint32 i;
     Uint32 index;      Uint32 n = self.size();
     const Uint32 maxIndex = _rep->languageTags.size();  
  
     for (index = 0; index < maxIndex; index++)      for (i = 0; i < n; i++)
     {     {
         if (_rep->qualityValues[index] < qualityValue)          if (self[i].second < qualityValue)
         {         {
             // Insert the new element before the element at this index             // Insert the new element before the element at this index
             break;             break;
         }         }
     }     }
  
     _rep->languageTags.insert(index, languageTag);      self.insert(i, AcceptLanguagePair(languageTag, qualityValue));
     _rep->qualityValues.insert(index, qualityValue);  
 } }
  
 void AcceptLanguageList::remove(Uint32 index)  void AcceptLanguageList::remove(Uint32 i)
 { {
     _rep->languageTags.remove(index);      AcceptLanguageArray& self = GetAcceptLanguageArray(this);
     _rep->qualityValues.remove(index);      self.remove(i);
 } }
  
 Uint32 AcceptLanguageList::find(const LanguageTag& languageTag) const Uint32 AcceptLanguageList::find(const LanguageTag& languageTag) const
 { {
     for (Uint32 i = 0; i < _rep->languageTags.size(); i++)      const AcceptLanguageArray& self = GetAcceptLanguageArray(this);
     {      Uint32 n = self.size();
         if (languageTag == _rep->languageTags[i])  
       for (Uint32 i = 0; i < n; i++)
         {         {
           if (languageTag == self[i].first)
             return i;             return i;
         }         }
     }  
     return PEG_NOT_FOUND;     return PEG_NOT_FOUND;
 } }
  
 void AcceptLanguageList::clear() void AcceptLanguageList::clear()
 { {
     _rep->languageTags.clear();      AcceptLanguageArray& self = GetAcceptLanguageArray(this);
     _rep->qualityValues.clear();      self.clear();
 } }
  
 Boolean AcceptLanguageList::operator==(  Boolean AcceptLanguageList::operator==(const AcceptLanguageList& x) const
     const AcceptLanguageList& acceptLanguages) const  
 {  
     if (_rep->languageTags.size() != acceptLanguages._rep->languageTags.size())  
     {     {
       const AcceptLanguageArray& self = GetAcceptLanguageArray(this);
       const AcceptLanguageArray& other = GetAcceptLanguageArray(&x);
   
       Uint32 n = self.size();
   
       if (n != other.size())
         return false;         return false;
     }  
  
     for (Uint32 i = 0; i < _rep->languageTags.size(); i++)      for (Uint32 i = 0; i < n; i++)
     {     {
         if ((_rep->languageTags[i] != acceptLanguages._rep->languageTags[i]) ||          if (self[i].first != other[i].first ||
             (_rep->qualityValues[i] != acceptLanguages._rep->qualityValues[i]))              self[i].second != other[i].second)
         {         {
             return false;             return false;
         }         }
     }     }
   
     return true;     return true;
 } }
  
 Boolean AcceptLanguageList::operator!=(  Boolean AcceptLanguageList::operator!=(const AcceptLanguageList& x) const
     const AcceptLanguageList& acceptLanguages) const  
 { {
     return !(*this == acceptLanguages);      return !operator==(x);
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2