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

  1 a.dunfey 1.2.2.2 //%2006////////////////////////////////////////////////////////////////////////
  2                  //
  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                  // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12                  // EMC Corporation; Symantec Corporation; The Open Group.
 13                  //
 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 a.dunfey 1.2.2.2 // 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                  // 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 a.dunfey 1.2.2.2 
 44                  PEGASUS_NAMESPACE_BEGIN
 45                  
 46                  //////////////////////////////////////////////////////////////
 47                  //
 48                  // ContentLanguageListRep
 49                  //
 50                  //////////////////////////////////////////////////////////////
 51                  
 52                  class ContentLanguageListRep
 53                  {
 54                  public:
 55                      Array<LanguageTag> container;
 56                  };
 57                  
 58                  //////////////////////////////////////////////////////////////
 59                  //
 60                  // ContentLanguageList
 61                  //
 62                  //////////////////////////////////////////////////////////////
 63                  
 64 a.dunfey 1.2.2.2 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                  
 77                      rep.release();
 78                  }
 79                  
 80                  ContentLanguageList::~ContentLanguageList()
 81                  {
 82                      delete _rep;
 83                  }
 84                  
 85 a.dunfey 1.2.2.2 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                      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 a.dunfey 1.2.2.2 {
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                  
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 a.dunfey 1.2.2.2     {
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                  }
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 a.dunfey 1.2.2.2 
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                      const ContentLanguageList& contentLanguages) const
161                  {
162                      return !(*this == contentLanguages);
163                  }
164                  
165                  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2