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

  1 martin 1.6 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.7 //
  3 martin 1.6 // 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.7 //
 10 martin 1.6 // 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.7 //
 17 martin 1.6 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.7 //
 20 martin 1.6 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.7 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.6 // 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.7 //
 28 martin 1.6 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include <Pegasus/Common/ContentLanguageList.h>
 33            #include <Pegasus/Common/LanguageParser.h>
 34            #include <Pegasus/Common/AutoPtr.h>
 35            #include <Pegasus/Common/InternalException.h>
 36            #include <Pegasus/Common/ArrayInternal.h>
 37            
 38            PEGASUS_NAMESPACE_BEGIN
 39            
 40 martin 1.7 //
 41 mike   1.4 // Implementation Notes:
 42            // =====================
 43 kumpf  1.1 //
 44 mike   1.4 // See the implemetnation notes in AcceptLanguageList.cpp for an explanation
 45            // of how we overlay the _rep pointer with the array class.
 46 kumpf  1.1 //
 47            
 48 mike   1.4 typedef Array<LanguageTag> LanguageTagArray;
 49 kumpf  1.1 
 50 kumpf  1.5 static inline LanguageTagArray& GetLanguageTagArray(
 51                ContentLanguageList* list)
 52            {
 53                return *reinterpret_cast<LanguageTagArray*>(list);
 54            }
 55            
 56            static inline const LanguageTagArray& GetLanguageTagArray(
 57                const ContentLanguageList* list)
 58            {
 59                return *reinterpret_cast<const LanguageTagArray*>(list);
 60            }
 61            
 62 kumpf  1.1 ContentLanguageList::ContentLanguageList()
 63            {
 64 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
 65 mike   1.4     new (&self) LanguageTagArray();
 66 kumpf  1.1 }
 67            
 68            ContentLanguageList::ContentLanguageList(
 69 mike   1.4     const ContentLanguageList& x)
 70 kumpf  1.1 {
 71 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
 72                const LanguageTagArray& other = GetLanguageTagArray(&x);
 73 mike   1.4     new (&self) LanguageTagArray(other);
 74 kumpf  1.1 }
 75            
 76            ContentLanguageList::~ContentLanguageList()
 77            {
 78 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
 79 mike   1.4     self.~LanguageTagArray();
 80 kumpf  1.1 }
 81            
 82            ContentLanguageList& ContentLanguageList::operator=(
 83 mike   1.4     const ContentLanguageList& x)
 84 kumpf  1.1 {
 85 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
 86                const LanguageTagArray& other = GetLanguageTagArray(&x);
 87 mike   1.4     self = other;
 88 kumpf  1.1     return *this;
 89            }
 90            
 91            Uint32 ContentLanguageList::size() const
 92            {
 93 kumpf  1.5     const LanguageTagArray& self = GetLanguageTagArray(this);
 94 mike   1.4     return self.size();
 95 kumpf  1.1 }
 96            
 97            LanguageTag ContentLanguageList::getLanguageTag(Uint32 index) const
 98            {
 99 kumpf  1.5     const LanguageTagArray& self = GetLanguageTagArray(this);
100 mike   1.4     return self[index];
101 kumpf  1.1 }
102            
103            void ContentLanguageList::append(const LanguageTag& languageTag)
104            {
105 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
106 mike   1.4 
107 kumpf  1.1     // Disallow "*" language tag
108                if (languageTag.toString() == "*")
109                {
110                    MessageLoaderParms parms(
111                        "Common.LanguageParser.INVALID_LANGUAGE_TAG",
112                        "Invalid language tag \"$0\".", languageTag.toString());
113                    throw InvalidContentLanguageHeader(MessageLoader::getMessage(parms));
114                }
115            
116 mike   1.4     self.append(languageTag);
117 kumpf  1.1 }
118            
119            void ContentLanguageList::remove(Uint32 index)
120            {
121 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
122 mike   1.4     self.remove(index);
123 kumpf  1.1 }
124            
125            Uint32 ContentLanguageList::find(const LanguageTag& languageTag) const
126            {
127 kumpf  1.5     const LanguageTagArray& self = GetLanguageTagArray(this);
128 mike   1.4 
129                for (Uint32 i = 0; i < self.size(); i++)
130 kumpf  1.1     {
131 mike   1.4         if (languageTag == self[i])
132 kumpf  1.1             return i;
133                }
134 mike   1.4 
135 kumpf  1.1     return PEG_NOT_FOUND;
136            }
137            
138            void ContentLanguageList::clear()
139            {
140 kumpf  1.5     LanguageTagArray& self = GetLanguageTagArray(this);
141 mike   1.4     self.clear();
142 kumpf  1.1 }
143            
144 mike   1.4 Boolean ContentLanguageList::operator==(const ContentLanguageList& x) const
145 kumpf  1.1 {
146 kumpf  1.5     const LanguageTagArray& self = GetLanguageTagArray(this);
147                const LanguageTagArray& other = GetLanguageTagArray(&x);
148 mike   1.4 
149                if (self.size() != other.size())
150 kumpf  1.1         return false;
151            
152 mike   1.4     for (Uint32 i = 0; i < self.size(); i++)
153 kumpf  1.1     {
154 mike   1.4         if (self[i] != other[i])
155 kumpf  1.1             return false;
156                }
157 mike   1.4 
158 kumpf  1.1     return true;
159            }
160            
161 mike   1.4 Boolean ContentLanguageList::operator!=( const ContentLanguageList& x) const
162 kumpf  1.1 {
163 mike   1.4     return !operator==(x);
164 kumpf  1.1 }
165            
166            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2