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.
|
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: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <Pegasus/Common/ContentLanguageList.h>
39 #include <Pegasus/Common/LanguageParser.h>
40 #include <Pegasus/Common/AutoPtr.h>
41 #include <Pegasus/Common/InternalException.h>
42 #include <Pegasus/Common/ArrayInternal.h>
43
44 PEGASUS_NAMESPACE_BEGIN
45
46 //////////////////////////////////////////////////////////////
47 //
48 // ContentLanguageListRep
49 //
50 //////////////////////////////////////////////////////////////
51
52 class ContentLanguageListRep
53 {
54 public:
55 kumpf 1.1 Array<LanguageTag> container;
56 };
57
58 //////////////////////////////////////////////////////////////
59 //
60 // ContentLanguageList
61 //
62 //////////////////////////////////////////////////////////////
63
64 ContentLanguageList::ContentLanguageList()
65 {
66 _rep = new ContentLanguageListRep();
67 }
68
69 ContentLanguageList::ContentLanguageList(
70 const ContentLanguageList& contentLanguages)
71 {
72 _rep = new ContentLanguageListRep();
73 AutoPtr<ContentLanguageListRep> rep(_rep);
74
75 _rep->container = contentLanguages._rep->container;
76 kumpf 1.1
77 rep.release();
78 }
79
80 ContentLanguageList::~ContentLanguageList()
81 {
82 delete _rep;
83 }
84
85 ContentLanguageList& ContentLanguageList::operator=(
86 const ContentLanguageList& contentLanguages)
87 {
88 if (&contentLanguages != this)
89 {
90 _rep->container = contentLanguages._rep->container;
91 }
92 return *this;
93 }
94
95 Uint32 ContentLanguageList::size() const
96 {
97 kumpf 1.1 return _rep->container.size();
98 }
99
100 LanguageTag ContentLanguageList::getLanguageTag(Uint32 index) const
101 {
102 return LanguageTag(_rep->container[index]);
103 }
104
105 void ContentLanguageList::append(const LanguageTag& languageTag)
106 {
107 // 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 _rep->container.append(languageTag);
117 }
118 kumpf 1.1
119 void ContentLanguageList::remove(Uint32 index)
120 {
121 _rep->container.remove(index);
122 }
123
124 Uint32 ContentLanguageList::find(const LanguageTag& languageTag) const
125 {
126 for (Uint32 i = 0; i < _rep->container.size(); i++)
127 {
128 if (languageTag == _rep->container[i])
129 {
130 return i;
131 }
132 }
133 return PEG_NOT_FOUND;
134 }
135
136 void ContentLanguageList::clear()
137 {
138 _rep->container.clear();
139 kumpf 1.1 }
140
141 Boolean ContentLanguageList::operator==(
142 const ContentLanguageList& contentLanguages) const
143 {
144 if (_rep->container.size() != contentLanguages._rep->container.size())
145 {
146 return false;
147 }
148
149 for (Uint32 i = 0; i < _rep->container.size(); i++)
150 {
151 if (_rep->container[i] != contentLanguages._rep->container[i])
152 {
153 return false;
154 }
155 }
156 return true;
157 }
158
159 Boolean ContentLanguageList::operator!=(
160 kumpf 1.1 const ContentLanguageList& contentLanguages) const
161 {
162 return !(*this == contentLanguages);
163 }
164
165 PEGASUS_NAMESPACE_END
|