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