(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           //%/////////////////////////////////////////////////////////////////////////////
 33           
 34 kumpf 1.1 #include <Pegasus/Common/AcceptLanguageList.h>
 35           #include <Pegasus/Common/LanguageParser.h>
 36           #include <Pegasus/Common/InternalException.h>
 37           #include <Pegasus/Common/AutoPtr.h>
 38           #include <Pegasus/Common/ArrayInternal.h>
 39           
 40           PEGASUS_NAMESPACE_BEGIN
 41           
 42           //////////////////////////////////////////////////////////////
 43           //
 44           // AcceptLanguageListRep
 45           //
 46           //////////////////////////////////////////////////////////////
 47           
 48           class AcceptLanguageListRep
 49           {
 50           public:
 51               Array<LanguageTag> languageTags;
 52               Array<Real32> qualityValues;
 53           };
 54           
 55 kumpf 1.1 //////////////////////////////////////////////////////////////
 56           //
 57           // AcceptLanguageList
 58           //
 59           //////////////////////////////////////////////////////////////
 60           
 61           AcceptLanguageList::AcceptLanguageList()
 62           {
 63               _rep = new AcceptLanguageListRep();
 64           }
 65           
 66           AcceptLanguageList::AcceptLanguageList(
 67               const AcceptLanguageList& acceptLanguages)
 68           {
 69               _rep = new AcceptLanguageListRep();
 70               AutoPtr<AcceptLanguageListRep> rep(_rep);
 71           
 72               _rep->languageTags = acceptLanguages._rep->languageTags;
 73               _rep->qualityValues = acceptLanguages._rep->qualityValues;
 74           
 75               rep.release();
 76 kumpf 1.1 }
 77           
 78           AcceptLanguageList::~AcceptLanguageList()
 79           {
 80               delete _rep;
 81           }
 82           
 83           AcceptLanguageList& AcceptLanguageList::operator=(
 84               const AcceptLanguageList& acceptLanguages)
 85           {
 86               if (&acceptLanguages != this)
 87               {
 88                   _rep->languageTags = acceptLanguages._rep->languageTags;
 89                   _rep->qualityValues = acceptLanguages._rep->qualityValues;
 90               }
 91               return *this;
 92           }
 93           
 94           Uint32 AcceptLanguageList::size() const
 95           {
 96               return _rep->languageTags.size();
 97 kumpf 1.1 }
 98           
 99           LanguageTag AcceptLanguageList::getLanguageTag(Uint32 index) const
100           {
101               return _rep->languageTags[index];
102           }
103           
104           Real32 AcceptLanguageList::getQualityValue(Uint32 index) const
105           {
106               return _rep->qualityValues[index];
107           }
108           
109           void AcceptLanguageList::insert(
110               const LanguageTag& languageTag,
111               Real32 qualityValue)
112           {
113               LanguageParser::validateQualityValue(qualityValue);
114           
115               // Insert in order of descending quality value
116           
117               Uint32 index;
118 kumpf 1.1     const Uint32 maxIndex = _rep->languageTags.size();
119           
120               for (index = 0; index < maxIndex; index++)
121               {
122                   if (_rep->qualityValues[index] < qualityValue)
123                   {
124                       // Insert the new element before the element at this index
125                       break;
126                   }
127               }
128           
129               _rep->languageTags.insert(index, languageTag);
130               _rep->qualityValues.insert(index, qualityValue);
131           }
132           
133           void AcceptLanguageList::remove(Uint32 index)
134           {
135               _rep->languageTags.remove(index);
136               _rep->qualityValues.remove(index);
137           }
138           
139 kumpf 1.1 Uint32 AcceptLanguageList::find(const LanguageTag& languageTag) const
140           {
141               for (Uint32 i = 0; i < _rep->languageTags.size(); i++)
142               {
143                   if (languageTag == _rep->languageTags[i])
144                   {
145                       return i;
146                   }
147               }
148               return PEG_NOT_FOUND;
149           }
150           
151           void AcceptLanguageList::clear()
152           {
153               _rep->languageTags.clear();
154               _rep->qualityValues.clear();
155           }
156           
157           Boolean AcceptLanguageList::operator==(
158               const AcceptLanguageList& acceptLanguages) const
159           {
160 kumpf 1.1     if (_rep->languageTags.size() != acceptLanguages._rep->languageTags.size())
161               {
162                   return false;
163               }
164           
165               for (Uint32 i = 0; i < _rep->languageTags.size(); i++)
166               {
167                   if ((_rep->languageTags[i] != acceptLanguages._rep->languageTags[i]) ||
168                       (_rep->qualityValues[i] != acceptLanguages._rep->qualityValues[i]))
169                   {
170                       return false;
171                   }
172               }
173               return true;
174           }
175           
176           Boolean AcceptLanguageList::operator!=(
177               const AcceptLanguageList& acceptLanguages) const
178           {
179               return !(*this == acceptLanguages);
180           }
181 kumpf 1.1 
182           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2