Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

String_Base.i

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // $Id: String_Base.i,v 1.1.1.1.2.1 2003/06/10 11:54:49 chad Exp $
00003 
00004 #include "ace/Malloc_Base.h"
00005 
00006 // Default constructor.
00007 
00008 template <class CHAR> ACE_INLINE
00009 ACE_String_Base<CHAR>::ACE_String_Base (ACE_Allocator *alloc)
00010   : allocator_ (alloc ? alloc : ACE_Allocator::instance ()),
00011     len_ (0),
00012     buf_len_ (0),
00013     rep_ (&ACE_String_Base<CHAR>::NULL_String_),
00014     release_ (0)
00015 {
00016   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00017 }
00018 
00019 // Constructor that actually copies memory.
00020 
00021 template <class CHAR> ACE_INLINE
00022 ACE_String_Base<CHAR>::ACE_String_Base (const CHAR *s,
00023                                         ACE_Allocator *alloc,
00024                                         int release)
00025   : allocator_ (alloc ? alloc : ACE_Allocator::instance ()),
00026     len_ (0),
00027     buf_len_ (0),
00028     rep_ (0),
00029     release_ (0)
00030 {
00031   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00032 
00033   size_t length;
00034   if (s != 0)
00035     length = ACE_OS::strlen (s);
00036   else
00037     length = 0;
00038 
00039   this->set (s, length, release);
00040 }
00041 
00042 template <class CHAR> ACE_INLINE
00043 ACE_String_Base<CHAR>::ACE_String_Base (CHAR c,
00044                                         ACE_Allocator *alloc)
00045   : allocator_ (alloc ? alloc : ACE_Allocator::instance ()),
00046     len_ (0),
00047     buf_len_ (0),
00048     rep_ (0),
00049     release_ (0)
00050 {
00051   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00052 
00053   this->set (&c, 1, 1);
00054 }
00055 
00056 // Constructor that actually copies memory.
00057 
00058 template <class CHAR> ACE_INLINE
00059 ACE_String_Base<CHAR>::ACE_String_Base (const CHAR *s,
00060                                         size_t len,
00061                                         ACE_Allocator *alloc,
00062                                         int release)
00063   : allocator_ (alloc ? alloc : ACE_Allocator::instance ()),
00064     len_ (0),
00065     buf_len_ (0),
00066     rep_ (0),
00067     release_ (0)
00068 {
00069   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00070 
00071   this->set (s, len, release);
00072 }
00073 
00074 // Copy constructor.
00075 
00076 template <class CHAR> ACE_INLINE
00077 ACE_String_Base<CHAR>::ACE_String_Base (const ACE_String_Base<CHAR> &s)
00078   : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()),
00079     len_ (0),
00080     buf_len_ (0),
00081     rep_ (0),
00082     release_ (0)
00083 {
00084   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00085 
00086   this->set (s.rep_, s.len_, 1);
00087 }
00088 
00089 template <class CHAR> ACE_INLINE
00090 ACE_String_Base<CHAR>::ACE_String_Base (size_t len, CHAR c, ACE_Allocator *alloc)
00091   : allocator_ (alloc ? alloc : ACE_Allocator::instance ()),
00092     len_ (0),
00093     buf_len_ (0),
00094     rep_ (0),
00095     release_ (0)
00096 {
00097   ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
00098 
00099   this->resize (len, c);
00100 }
00101 
00102 template <class CHAR> ACE_INLINE
00103 ACE_String_Base<CHAR>::~ACE_String_Base (void)
00104 {
00105   ACE_TRACE ("ACE_String_Base<CHAR>::~ACE_String_Base");
00106 
00107   this->set (0, 0, 0);
00108 }
00109 
00110 template <class CHAR> ACE_INLINE void
00111 ACE_String_Base<CHAR>::dump (void) const
00112 {
00113   ACE_TRACE ("ACE_String_Base<CHAR>::dump");
00114 }
00115 
00116 // Assignment operator (does copy memory).
00117 template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> &
00118 ACE_String_Base<CHAR>::operator= (const ACE_String_Base<CHAR> &s)
00119 {
00120   ACE_TRACE ("ACE_String_Base<CHAR>::operator=");
00121 
00122   // Check for identify.
00123   if (this != &s)
00124     this->set (s.rep_, s.len_, 1);
00125 
00126   return *this;
00127 }
00128 
00129 // Assignment method (does not copy memory)
00130 template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> &
00131 ACE_String_Base<CHAR>::assign_nocopy (const ACE_String_Base<CHAR> &s)
00132 {
00133   this->set (s.rep_, s.len_, 0);
00134   return *this;
00135 }
00136 
00137 template <class CHAR> ACE_INLINE void
00138 ACE_String_Base<CHAR>::set (const CHAR *s, int release)
00139 {
00140   size_t length;
00141   if (s != 0)
00142     length = ACE_OS::strlen (s);
00143   else
00144     length = 0;
00145 
00146   this->set (s, length, release);
00147 }
00148 
00149 template <class CHAR> ACE_INLINE size_t
00150 ACE_String_Base<CHAR>::length (void) const
00151 {
00152   ACE_TRACE ("ACE_String_Base<CHAR>::length");
00153   return this->len_;
00154 }
00155 
00156 template <class CHAR> ACE_INLINE void
00157 ACE_String_Base<CHAR>::clear (int release)
00158 {
00159   this->set(0, 0, release);
00160 }
00161 
00162 template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
00163 ACE_String_Base<CHAR>::substr (size_t offset,
00164                                ssize_t length) const
00165 {
00166   return this->substring (offset, length);
00167 }
00168 
00169 // Return the <slot'th> character in the string.
00170 
00171 template <class CHAR> ACE_INLINE const CHAR &
00172 ACE_String_Base<CHAR>::operator[] (size_t slot) const
00173 {
00174   ACE_TRACE ("ACE_String_Base<CHAR>::operator[]");
00175   return this->rep_[slot];
00176 }
00177 
00178 // Return the <slot'th> character in the string by reference.
00179 
00180 template <class CHAR> ACE_INLINE CHAR &
00181 ACE_String_Base<CHAR>::operator[] (size_t slot)
00182 {
00183   ACE_TRACE ("ACE_String_Base<CHAR>::operator[]");
00184   return this->rep_[slot];
00185 }
00186 
00187 // Get a copy of the underlying representation.
00188 
00189 template <class CHAR> ACE_INLINE CHAR *
00190 ACE_String_Base<CHAR>::rep (void) const
00191 {
00192   ACE_TRACE ("ACE_String_Base<CHAR>::rep");
00193 
00194   CHAR *new_string;
00195   ACE_NEW_RETURN (new_string, CHAR[this->len_ + 1], 0);
00196   ACE_OS::strsncpy (new_string, this->rep_, this->len_+1);
00197 
00198   return new_string;
00199 }
00200 
00201 template <class CHAR> ACE_INLINE const CHAR *
00202 ACE_String_Base<CHAR>::fast_rep (void) const
00203 {
00204   return this->rep_;
00205 }
00206 
00207 template <class CHAR> ACE_INLINE const CHAR *
00208 ACE_String_Base<CHAR>::c_str (void) const
00209 {
00210   return this->rep_;
00211 }
00212 
00213 template <class CHAR> ACE_INLINE int
00214 ACE_String_Base<CHAR>::compare (const ACE_String_Base<CHAR> &s) const
00215 {
00216   ACE_TRACE ("ACE_String_Base<CHAR>::compare");
00217 
00218   // Pick smaller of the two lengths and perform the comparison.
00219   size_t smaller_length = ace_min (this->len_, s.len_);
00220 
00221   int result = ACE_OS::memcmp (this->rep_,
00222                                s.rep_,
00223                                smaller_length * sizeof (CHAR));
00224 
00225   if (!result)
00226     result = ACE_static_cast (int, (this->len_ - s.len_));
00227   return result;
00228 }
00229 
00230 
00231 // Comparison operator.
00232 
00233 template <class CHAR> ACE_INLINE int
00234 ACE_String_Base<CHAR>::operator== (const ACE_String_Base<CHAR> &s) const
00235 {
00236   ACE_TRACE ("ACE_String_Base<CHAR>::operator==");
00237 
00238   return compare (s) == 0;
00239 }
00240 
00241 // Less than comparison operator.
00242 
00243 template <class CHAR> ACE_INLINE int
00244 ACE_String_Base<CHAR>::operator < (const ACE_String_Base<CHAR> &s) const
00245 {
00246   ACE_TRACE ("ACE_String_Base<CHAR>::operator <");
00247   return compare (s) < 0;
00248 }
00249 
00250 // Greater than comparison operator.
00251 
00252 template <class CHAR> ACE_INLINE int
00253 ACE_String_Base<CHAR>::operator > (const ACE_String_Base &s) const
00254 {
00255   ACE_TRACE ("ACE_String_Base<CHAR>::operator >");
00256   return compare (s) > 0;
00257 }
00258 
00259 
00260 // Comparison operator.
00261 
00262 template <class CHAR> ACE_INLINE int
00263 ACE_String_Base<CHAR>::operator!= (const ACE_String_Base<CHAR> &s) const
00264 {
00265   ACE_TRACE ("ACE_String_Base<CHAR>::operator!=");
00266   return !(*this == s);
00267 }
00268 
00269 template <class CHAR> ACE_INLINE ssize_t
00270 ACE_String_Base<CHAR>::find (const CHAR *s, size_t pos) const
00271 {
00272   CHAR *substr = this->rep_ + pos;
00273   size_t len = ACE_OS::strlen (s);
00274   CHAR *pointer = ACE_OS::strnstr (substr, s, len);
00275   if (pointer == 0)
00276     return ACE_String_Base<CHAR>::npos;
00277   else
00278     return pointer - this->rep_;
00279 }
00280 
00281 template <class CHAR> ACE_INLINE ssize_t
00282 ACE_String_Base<CHAR>::find (CHAR c, size_t pos) const
00283 {
00284   CHAR *substr = this->rep_ + pos;
00285   CHAR *pointer = ACE_OS::strnchr (substr, c, this->len_ - pos);
00286   if (pointer == 0)
00287     return ACE_String_Base<CHAR>::npos;
00288   else
00289     return pointer - this->rep_;
00290 }
00291 
00292 template <class CHAR> ACE_INLINE ssize_t
00293 ACE_String_Base<CHAR>::find (const ACE_String_Base<CHAR>&str, size_t pos) const
00294 {
00295   return this->find (str.rep_, pos);
00296 }
00297 
00298 template <class CHAR> ACE_INLINE ssize_t
00299 ACE_String_Base<CHAR>::strstr (const ACE_String_Base<CHAR> &s) const
00300 {
00301   ACE_TRACE ("ACE_String_Base<CHAR>::strstr");
00302 
00303   return this->find (s.rep_);
00304 }
00305 
00306 template <class CHAR> ACE_INLINE ssize_t
00307 ACE_String_Base<CHAR>::rfind (CHAR c, ssize_t pos) const
00308 {
00309   if (pos == npos || pos > ACE_static_cast (ssize_t, this->len_))
00310     pos = ACE_static_cast (ssize_t, this->len_);
00311 
00312   for (ssize_t i = pos - 1; i >= 0; i--)
00313     if (this->rep_[i] == c)
00314       return i;
00315 
00316   return ACE_String_Base<CHAR>::npos;
00317 }
00318 
00319 template <class CHAR> ACE_INLINE u_long
00320 ACE_String_Base<CHAR>::hash (void) const
00321 {
00322   return ACE::hash_pjw ((ACE_reinterpret_cast (char *,
00323                                                ACE_const_cast (CHAR *,
00324                                                                this->rep_))),
00325                         this->len_ * sizeof (CHAR));
00326 }
00327 
00328 template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
00329 operator+ (const ACE_String_Base<CHAR> &s, const ACE_String_Base<CHAR> &t)
00330 {
00331   ACE_String_Base<CHAR> temp (s);
00332   temp += t;
00333   return temp;
00334 }
00335 
00336 template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
00337 operator+ (const CHAR *s, const ACE_String_Base<CHAR> &t)
00338 {
00339   ACE_String_Base<CHAR> temp (s);
00340   temp += t;
00341   return temp;
00342 }
00343 
00344 template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
00345 operator+ (const ACE_String_Base<CHAR> &s, const CHAR *t)
00346 {
00347   ACE_String_Base<CHAR> temp (s);
00348   temp += t;
00349   return temp;
00350 }
00351 
00352 template <class CHAR> ACE_INLINE
00353 ACE_String_Base<CHAR> operator + (const ACE_String_Base<CHAR> &t,
00354                                   const CHAR c)
00355 {
00356   ACE_String_Base<CHAR> temp (t);
00357   temp += c;
00358   return temp;
00359 }
00360 
00361 template <class CHAR> ACE_INLINE
00362 ACE_String_Base<CHAR> operator + (const CHAR c,
00363                                   const ACE_String_Base<CHAR> &t)
00364 {
00365   ACE_String_Base<CHAR> temp (c);
00366   temp += t;
00367   return temp;
00368 }

Generated on Mon Jun 16 11:21:31 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002