(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.1.2.2 and 1.5

version 1.1.2.2, 2006/01/18 17:37:56 version 1.5, 2008/11/13 22:15:03
Line 1 
Line 1 
 //%2005////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
Line 8 
Line 8 
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // EMC Corporation; VERITAS Software Corporation; The Open Group. // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 27 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // 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)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/AcceptLanguageList.h> #include <Pegasus/Common/AcceptLanguageList.h>
Line 39 
Line 36 
 #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 115 
Line 144 
 { {
     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.1.2.2  
changed lines
  Added in v.1.5

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2