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

  1 karl  1.2 //%2006////////////////////////////////////////////////////////////////////////
  2 kumpf 1.1 //
  3           // 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           // IBM Corp.; EMC Corporation, The Open Group.
  7           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.2 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12           // EMC Corporation; Symantec Corporation; The Open Group.
 13 kumpf 1.1 //
 14           // Permission is hereby granted, free of charge, to any person obtaining a copy
 15           // 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           // 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           // 
 21           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22           // 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           // 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           // 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: Humberto Rivero (hurivero@us.ibm.com)
 33           //
 34 kumpf 1.1 // Modified By: Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3514
 35           //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 36           //
 37           //%/////////////////////////////////////////////////////////////////////////////
 38           
 39           #include <Pegasus/Common/AcceptLanguageList.h>
 40           #include <Pegasus/Common/LanguageParser.h>
 41           #include <Pegasus/Common/InternalException.h>
 42           #include <Pegasus/Common/AutoPtr.h>
 43           #include <Pegasus/Common/ArrayInternal.h>
 44           
 45           PEGASUS_NAMESPACE_BEGIN
 46           
 47           //////////////////////////////////////////////////////////////
 48           //
 49           // AcceptLanguageListRep
 50           //
 51           //////////////////////////////////////////////////////////////
 52           
 53           class AcceptLanguageListRep
 54           {
 55 kumpf 1.1 public:
 56               Array<LanguageTag> languageTags;
 57               Array<Real32> qualityValues;
 58           };
 59           
 60           //////////////////////////////////////////////////////////////
 61           //
 62           // AcceptLanguageList
 63           //
 64           //////////////////////////////////////////////////////////////
 65           
 66           AcceptLanguageList::AcceptLanguageList()
 67           {
 68               _rep = new AcceptLanguageListRep();
 69           }
 70           
 71           AcceptLanguageList::AcceptLanguageList(
 72               const AcceptLanguageList& acceptLanguages)
 73           {
 74               _rep = new AcceptLanguageListRep();
 75               AutoPtr<AcceptLanguageListRep> rep(_rep);
 76 kumpf 1.1 
 77               _rep->languageTags = acceptLanguages._rep->languageTags;
 78               _rep->qualityValues = acceptLanguages._rep->qualityValues;
 79           
 80               rep.release();
 81           }
 82           
 83           AcceptLanguageList::~AcceptLanguageList()
 84           {
 85               delete _rep;
 86           }
 87           
 88           AcceptLanguageList& AcceptLanguageList::operator=(
 89               const AcceptLanguageList& acceptLanguages)
 90           {
 91               if (&acceptLanguages != this)
 92               {
 93                   _rep->languageTags = acceptLanguages._rep->languageTags;
 94                   _rep->qualityValues = acceptLanguages._rep->qualityValues;
 95               }
 96               return *this;
 97 kumpf 1.1 }
 98           
 99           Uint32 AcceptLanguageList::size() const
100           {
101               return _rep->languageTags.size();
102           }
103           
104           LanguageTag AcceptLanguageList::getLanguageTag(Uint32 index) const
105           {
106               return _rep->languageTags[index];
107           }
108           
109           Real32 AcceptLanguageList::getQualityValue(Uint32 index) const
110           {
111               return _rep->qualityValues[index];
112           }
113           
114           void AcceptLanguageList::insert(
115               const LanguageTag& languageTag,
116               Real32 qualityValue)
117           {
118 kumpf 1.1     LanguageParser::validateQualityValue(qualityValue);
119           
120               // Insert in order of descending quality value
121           
122               Uint32 index;
123               const Uint32 maxIndex = _rep->languageTags.size();
124           
125               for (index = 0; index < maxIndex; index++)
126               {
127                   if (_rep->qualityValues[index] < qualityValue)
128                   {
129                       // Insert the new element before the element at this index
130                       break;
131                   }
132               }
133           
134               _rep->languageTags.insert(index, languageTag);
135               _rep->qualityValues.insert(index, qualityValue);
136           }
137           
138           void AcceptLanguageList::remove(Uint32 index)
139 kumpf 1.1 {
140               _rep->languageTags.remove(index);
141               _rep->qualityValues.remove(index);
142           }
143           
144           Uint32 AcceptLanguageList::find(const LanguageTag& languageTag) const
145           {
146               for (Uint32 i = 0; i < _rep->languageTags.size(); i++)
147               {
148                   if (languageTag == _rep->languageTags[i])
149                   {
150                       return i;
151                   }
152               }
153               return PEG_NOT_FOUND;
154           }
155           
156           void AcceptLanguageList::clear()
157           {
158               _rep->languageTags.clear();
159               _rep->qualityValues.clear();
160 kumpf 1.1 }
161           
162           Boolean AcceptLanguageList::operator==(
163               const AcceptLanguageList& acceptLanguages) const
164           {
165               if (_rep->languageTags.size() != acceptLanguages._rep->languageTags.size())
166               {
167                   return false;
168               }
169           
170               for (Uint32 i = 0; i < _rep->languageTags.size(); i++)
171               {
172                   if ((_rep->languageTags[i] != acceptLanguages._rep->languageTags[i]) ||
173                       (_rep->qualityValues[i] != acceptLanguages._rep->qualityValues[i]))
174                   {
175                       return false;
176                   }
177               }
178               return true;
179           }
180           
181 kumpf 1.1 Boolean AcceptLanguageList::operator!=(
182               const AcceptLanguageList& acceptLanguages) const
183           {
184               return !(*this == acceptLanguages);
185           }
186           
187           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2