AttributesImpl.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-  AttributesImpl.cpp,v 1.8 2006/04/20 09:55:37 jwillemsen Exp
00002 
00003 #include "ACEXML/common/AttributesImpl.h"
00004 
00005 #if !defined (__ACEXML_INLINE__)
00006 # include "ACEXML/common/AttributesImpl.i"
00007 #endif /* __ACEXML_INLINE__ */
00008 
00009 ACEXML_AttributesImpl::ACEXML_AttributesImpl (int size)
00010   : attrs_ (size)
00011 {
00012   this->attrs_.size (0);        // attrs array contains nothing
00013 }
00014 
00015 ACEXML_AttributesImpl::ACEXML_AttributesImpl (const
00016                                               ACEXML_AttributesImpl &attrs)
00017   : ACEXML_Attributes (attrs),
00018     attrs_ (attrs.attrs_.size ())
00019 {
00020   for (size_t i = 0; i < attrs.attrs_.size (); i++)
00021     this->attrs_[i] = attrs.attrs_[i];
00022 }
00023 
00024 ACEXML_AttributesImpl::~ACEXML_AttributesImpl (void)
00025 {
00026 }
00027 
00028 int
00029 ACEXML_AttributesImpl::addAttribute (const ACEXML_Char *uri,
00030                                      const ACEXML_Char *localName,
00031                                      const ACEXML_Char *qName,
00032                                      const ACEXML_Char *type,
00033                                      const ACEXML_Char *value)
00034 {
00035   if (this->isDuplicate (uri, localName, qName))
00036     return -1;
00037   size_t length = this->attrs_.size ();
00038   this->attrs_.size (length+1);
00039   this->setAttribute (length,
00040                       uri,
00041                       localName,
00042                       qName,
00043                       type,
00044                       value);
00045   return static_cast<int> (length);
00046 }
00047 
00048 int
00049 ACEXML_AttributesImpl::addAttribute (const ACEXML_Attribute &att)
00050 {
00051   if (this->isDuplicate (att.uri(), att.localName(), att.qName()))
00052     return -1;
00053   size_t length = this->attrs_.size ();
00054   this->attrs_.size (length+1);
00055   this->attrs_[length] = att;
00056   return static_cast<int> (length);
00057 }
00058 
00059 int
00060 ACEXML_AttributesImpl::isDuplicate (const ACEXML_Char *uri,
00061                                     const ACEXML_Char *localName,
00062                                     const ACEXML_Char *qName)
00063 {
00064   for (size_t i = 0; i < this->attrs_.size(); ++i)
00065     {
00066       if (ACE_OS::strcmp (this->attrs_[i].localName(), localName) == 0)
00067         {
00068           if (qName != 0 && this->attrs_[i].qName() != 0
00069               && ACE_OS::strcmp (this->attrs_[i].qName(), qName) == 0)
00070             {
00071               if (uri != 0 && this->attrs_[i].uri() != 0
00072                   && ACE_OS::strcmp (this->attrs_[i].uri(), uri) == 0)
00073                 return 1;
00074             }
00075         }
00076     }
00077   return 0;
00078 }
00079 
00080 int
00081 ACEXML_AttributesImpl::removeAttribute (size_t index)
00082 {
00083   size_t length = this->attrs_.size ();
00084 
00085   if (index >= length)
00086     return -1;
00087 
00088   this->attrs_[index] = this->attrs_[length - 1];
00089   this->attrs_.size (length - 1);
00090 
00091   return 0;
00092 }
00093 
00094 
00095 int
00096 ACEXML_AttributesImpl::getIndex (const ACEXML_Char *qName)
00097 {
00098   for (size_t i = 0; i < this->attrs_.size (); i++)
00099     if (ACE_OS::strcmp (qName, this->attrs_[i].qName ()) == 0)
00100       return static_cast<int> (i);
00101 
00102   return -1;
00103 }
00104 
00105 int
00106 ACEXML_AttributesImpl::getIndex (const ACEXML_Char *uri,
00107                                  const ACEXML_Char *localPart)
00108 {
00109   for (size_t i = 0; i < this->attrs_.size (); i++)
00110     if (ACE_OS::strcmp (uri, this->attrs_[i].uri ()) == 0 &&
00111         ACE_OS::strcmp (localPart, this->attrs_[i].localName ()) == 0)
00112       return static_cast<int> (i);
00113 
00114   return -1;
00115 }
00116 
00117 size_t
00118 ACEXML_AttributesImpl::getLength (void)
00119 {
00120   return this->attrs_.size ();
00121 }
00122 
00123 const ACEXML_Char *
00124 ACEXML_AttributesImpl::getLocalName (size_t index)
00125 {
00126   if (index < this->attrs_.size ())
00127     return this->attrs_[index].localName ();
00128   return 0;
00129 }
00130 
00131 
00132 const ACEXML_Char *
00133 ACEXML_AttributesImpl::getQName (size_t index)
00134 {
00135   if (index < this->attrs_.size ())
00136     return this->attrs_[index].qName ();
00137   return 0;
00138 }
00139 
00140 const ACEXML_Char *
00141 ACEXML_AttributesImpl::getType (size_t index)
00142 {
00143   if (index < this->attrs_.size ())
00144     return this->attrs_[index].type ();
00145   return 0;
00146 }
00147 
00148 
00149 const ACEXML_Char *
00150 ACEXML_AttributesImpl::getType (const ACEXML_Char *qName)
00151 {
00152   for (size_t i = 0; i < this->attrs_.size (); i++)
00153     if (ACE_OS::strcmp (qName, this->attrs_[i].qName ()) == 0)
00154       return this->attrs_[i].type ();
00155 
00156   return 0;
00157 }
00158 
00159 const ACEXML_Char *
00160 ACEXML_AttributesImpl::getType (const ACEXML_Char *uri,
00161                                 const ACEXML_Char *localPart)
00162 {
00163   for (size_t i = 0; i < this->attrs_.size (); i++)
00164     if (ACE_OS::strcmp (uri, this->attrs_[i].uri ()) == 0 &&
00165         ACE_OS::strcmp (localPart, this->attrs_[i].localName ()) == 0)
00166       return this->attrs_[i].type ();
00167 
00168   return 0;
00169 }
00170 
00171 
00172 const ACEXML_Char *
00173 ACEXML_AttributesImpl::getURI (size_t index)
00174 {
00175   if (index < this->attrs_.size ())
00176     return this->attrs_[index].uri ();
00177   return 0;
00178 }
00179 
00180 
00181 const ACEXML_Char *
00182 ACEXML_AttributesImpl::getValue (size_t index)
00183 {
00184   if (index < this->attrs_.size ())
00185     return this->attrs_[index].value ();
00186   return 0;
00187 }
00188 
00189 const ACEXML_Char *
00190 ACEXML_AttributesImpl::getValue (const ACEXML_Char *qName)
00191 {
00192   for (size_t i = 0; i < this->attrs_.size (); i++)
00193     if (ACE_OS::strcmp (qName, this->attrs_[i].qName ()) == 0)
00194       return this->attrs_[i].value ();
00195 
00196   return 0;
00197 }
00198 
00199 const ACEXML_Char *
00200 ACEXML_AttributesImpl::getValue (const ACEXML_Char *uri,
00201                                  const ACEXML_Char *localPart)
00202 {
00203   for (size_t i = 0; i < this->attrs_.size (); i++)
00204     if (ACE_OS::strcmp (uri, this->attrs_[i].uri ()) == 0 &&
00205         ACE_OS::strcmp (localPart, this->attrs_[i].localName ()) == 0)
00206       return this->attrs_[i].value ();
00207 
00208   return 0;
00209 }
00210 
00211 int
00212 ACEXML_AttributesImpl::setAttribute (size_t index,
00213                                      const ACEXML_Char *uri,
00214                                      const ACEXML_Char *localName,
00215                                      const ACEXML_Char *qName,
00216                                      const ACEXML_Char *type,
00217                                      const ACEXML_Char *value)
00218 {
00219   if (index < this->attrs_.size ())
00220     {
00221       this->attrs_[index].setAttribute (uri,
00222                                         localName,
00223                                         qName,
00224                                         type,
00225                                         value);
00226       return 0;
00227     }
00228 
00229   return -1;
00230 }
00231 
00232 
00233 int
00234 ACEXML_AttributesImpl::setLocalName (size_t index,
00235                                      const ACEXML_Char *localName)
00236 {
00237   if (index < this->attrs_.size ())
00238     {
00239       this->attrs_[index].localName (localName);
00240       return 0;
00241     }
00242   return -1;
00243 }
00244 
00245 int
00246 ACEXML_AttributesImpl::setQName (size_t index,
00247                                  const ACEXML_Char *qName)
00248 {
00249   if (index < this->attrs_.size ())
00250     {
00251       this->attrs_[index].qName (qName);
00252       return 0;
00253     }
00254   return -1;
00255 }
00256 
00257 
00258 int
00259 ACEXML_AttributesImpl::setURI (size_t index,
00260                                const ACEXML_Char *uri)
00261 {
00262   if (index < this->attrs_.size ())
00263     {
00264       this->attrs_[index].uri (uri);
00265       return 0;
00266     }
00267   return -1;
00268 }
00269 
00270 int
00271 ACEXML_AttributesImpl::setType (size_t index,
00272                                 const ACEXML_Char *type)
00273 {
00274   if (index < this->attrs_.size ())
00275     {
00276       this->attrs_[index].type (type);
00277       return 0;
00278     }
00279   return -1;
00280 }
00281 
00282 int
00283 ACEXML_AttributesImpl::setValue (size_t index,
00284                                  const ACEXML_Char *value)
00285 {
00286   if (index < this->attrs_.size ())
00287     {
00288       this->attrs_[index].value (value);
00289       return 0;
00290     }
00291   return -1;
00292 }
00293 

Generated on Thu Nov 9 11:45:35 2006 for ACEXML by doxygen 1.3.6