00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file String_Base.h 00006 * 00007 * $Id: String_Base.h 88793 2010-02-01 17:50:34Z cleeland $ 00008 * 00009 * @author Douglas C. Schmidt (schmidt@cs.wustl.edu) 00010 * @author Nanbor Wang <nanbor@cs.wustl.edu> 00011 */ 00012 //============================================================================= 00013 00014 #ifndef ACE_STRING_BASE_H 00015 #define ACE_STRING_BASE_H 00016 00017 #include /**/ "ace/pre.h" 00018 00019 #include "ace/Global_Macros.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "ace/String_Base_Const.h" 00026 #include <iterator> 00027 00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00029 00030 // Forward decl. 00031 template <class ACE_CHAR_T> 00032 class ACE_String_Base_Iterator; 00033 00034 // Forward decl. 00035 template <class ACE_CHAR_T> 00036 class ACE_String_Base_Const_Iterator; 00037 00038 /** 00039 * @class ACE_String_Base 00040 * 00041 * @brief This class provides a wrapper facade for C strings. 00042 * 00043 * This class uses an ACE_Allocator to allocate memory. The 00044 * user can make this a persistant class by providing an 00045 * ACE_Allocator with a persistable memory pool. This class is 00046 * optimized for efficiency, so it doesn't provide any internal 00047 * locking. 00048 * @note If an instance of this class is constructed from or 00049 * assigned an empty string (with first element of '\0'), then it 00050 * is not allocated new space. Instead, its internal 00051 * representation is set equal to a global empty string. 00052 * CAUTION: in cases when ACE_String_Base is constructed from a 00053 * provided buffer with the release parameter set to false, 00054 * ACE_String_Base is not guaranteed to be '\0' terminated. 00055 * 00056 * \li Do not use a "@c -1" magic number to refer to the "no position" 00057 * condition. This was never the right thing to do. The "@c npos" 00058 * constant should be used in such cases. 00059 * \li Do not assign or pass string positions to or from signed types. 00060 * Use the "@c size_type" @c typedef found in all ACE string 00061 * classes. This typedef is analogous to the "@c size_type" 00062 * @c typedef found in the standard C++ string class as well as 00063 * many STL class templates. If you find yourself casting you're 00064 * probably doing something wrong. 00065 */ 00066 template <class ACE_CHAR_T> 00067 class ACE_String_Base : public ACE_String_Base_Const 00068 { 00069 public: 00070 using ACE_String_Base_Const::size_type; 00071 00072 friend class ACE_String_Base_Iterator <ACE_CHAR_T>; 00073 friend class ACE_String_Base_Const_Iterator <ACE_CHAR_T>; 00074 00075 // ACE-style iterators 00076 typedef ACE_String_Base_Iterator <ACE_CHAR_T> ITERATOR; 00077 typedef ACE_String_Base_Const_Iterator <ACE_CHAR_T> CONST_ITERATOR; 00078 00079 // STL-style iterators 00080 typedef ACE_String_Base_Iterator <ACE_CHAR_T> iterator; 00081 typedef ACE_String_Base_Const_Iterator <ACE_CHAR_T> const_iterator; 00082 00083 /** 00084 * Default constructor. 00085 * 00086 * @param the_allocator ACE_Allocator associated with string 00087 * @return Default ACE_String_Base string. 00088 */ 00089 ACE_String_Base (ACE_Allocator *the_allocator = 0); 00090 00091 /** 00092 * Constructor that copies @a s into dynamically allocated memory. 00093 * 00094 * if release == true then a new buffer is allocated internally, and 00095 * s is copied to the internal buffer. 00096 * if release == false then the s buffer is used directly. If s == 0 00097 * then it will _not_ be used, and instead the internal buffer 00098 * is set to NULL_String_. 00099 * 00100 * @param s Zero terminated input string 00101 * @param the_allocator ACE_Allocator associated with string 00102 * @param release Allocator responsible(true)/not reponsible(false) for 00103 * freeing memory. 00104 * @return ACE_String_Base containing const ACE_CHAR_T *s 00105 */ 00106 ACE_String_Base (const ACE_CHAR_T *s, 00107 ACE_Allocator *the_allocator = 0, 00108 bool release = true); 00109 00110 /** 00111 * Constructor that copies @a len CHARs of @a s into dynamically 00112 * allocated memory (will zero terminate the result). 00113 * 00114 * if release == true then a new buffer is allocated internally. 00115 * s is copied to the internal buffer. 00116 * if release == false then the s buffer is used directly. If s == 0 00117 * then it will _not_ be used, and instead the internal buffer 00118 * is set to NULL_String_. 00119 * 00120 * @param s Non-zero terminated input string 00121 * @param len Length of non-zero terminated input string 00122 * @param the_allocator ACE_Allocator associated with string 00123 * @param release Allocator responsible(true)/not reponsible(false) for 00124 * freeing memory. 00125 * @return ACE_String_Base containing const ACE_CHAR_T *s 00126 */ 00127 ACE_String_Base (const ACE_CHAR_T *s, 00128 size_type len, 00129 ACE_Allocator *the_allocator = 0, 00130 bool release = true); 00131 00132 /** 00133 * Copy constructor. 00134 * 00135 * @param s Input ACE_String_Base string to copy 00136 * @return Copy of input string @a s 00137 */ 00138 ACE_String_Base (const ACE_String_Base < ACE_CHAR_T > &s); 00139 00140 /** 00141 * Constructor that copies @a c into dynamically allocated memory. 00142 * 00143 * @param c Single input character. 00144 * @param the_allocator ACE_Allocator associated with string 00145 * @return ACE_String_Base containing ACE_CHAR_T 'c' 00146 */ 00147 ACE_String_Base (ACE_CHAR_T c, ACE_Allocator *the_allocator = 0); 00148 00149 /** 00150 * Constructor that allocates a len long string. 00151 * 00152 * Warning : This constructor was incorrectly documented in the past. 00153 * It simply calls resize(len, c). 00154 * It is probably not advisable to use the second parameter. See 00155 * resize() for more information. 00156 * 00157 * @param len Amount of space to reserve for the string. 00158 * @param c The array is filled with c's 00159 * @param the_allocator ACE_Allocator associated with string 00160 * @return Empty ACE_String_Base with room for len CHARs 00161 */ 00162 ACE_String_Base (size_type len, 00163 ACE_CHAR_T c = 0, 00164 ACE_Allocator *the_allocator = 0); 00165 00166 /** 00167 * Deletes the memory... 00168 */ 00169 ~ACE_String_Base (void); 00170 00171 /** 00172 * Return the <slot'th> character in the string (doesn't perform 00173 * bounds checking). 00174 * 00175 * @param slot Index of the desired character 00176 * @return The character at index @a slot 00177 */ 00178 const ACE_CHAR_T & operator[] (size_type slot) const; 00179 00180 /** 00181 * Return the <slot'th> character by reference in the string 00182 * (doesn't perform bounds checking). 00183 * 00184 * @param slot Index of the desired character 00185 * @return The character at index @a slot 00186 */ 00187 ACE_CHAR_T & operator[] (size_type slot); 00188 00189 /** 00190 * Assignment operator (does copy memory). 00191 * 00192 * @param s Input null-terminated ACE_CHAR_T string to assign to this object. 00193 * @return Return a copy of the this string. 00194 */ 00195 ACE_String_Base < ACE_CHAR_T > &operator = (const ACE_CHAR_T * s); 00196 00197 /** 00198 * Assignment operator (does copy memory). 00199 * 00200 * @param s Input ACE_String_Base string to assign to this object. 00201 * @return Return a copy of the this string. 00202 */ 00203 ACE_String_Base < ACE_CHAR_T > &operator = (const ACE_String_Base < ACE_CHAR_T > &s); 00204 00205 /** 00206 * Assignment alternative method (does not copy memory). 00207 * 00208 * @param s Input ACE_String_Base string to assign to this object. 00209 * @return Return this string. 00210 */ 00211 ACE_String_Base < ACE_CHAR_T > &assign_nocopy (const ACE_String_Base < ACE_CHAR_T > &s); 00212 00213 /** 00214 * Copy @a s into this @a ACE_String_Base. 00215 * 00216 * If release == true then a new buffer is allocated internally if the 00217 * existing one is not big enough to hold s. If the existing 00218 * buffer is big enough, then it will be used. This means that 00219 * set(*, 1) can be illegal when the string is constructed with a 00220 * const char*. (e.g. ACE_String_Base("test", 0, false)). 00221 * 00222 * if release == false then the s buffer is used directly, and any 00223 * existing buffer is destroyed. If s == 0 then it will _not_ be 00224 * used, and instead the internal buffer is set to NULL_String_. 00225 * 00226 * @param s Null terminated input string 00227 * @param release Allocator responsible(true)/not reponsible(false) for 00228 * freeing memory. 00229 */ 00230 void set (const ACE_CHAR_T * s, bool release = true); 00231 00232 /** 00233 * Copy @a len bytes of @a s (will zero terminate the result). 00234 * 00235 * If release == true then a new buffer is allocated internally if the 00236 * existing one is not big enough to hold s. If the existing 00237 * buffer is big enough, then it will be used. This means that 00238 * set(*, *, 1) is illegal when the string is constructed with a 00239 * non-owned const char*. (e.g. ACE_String_Base("test", 0, 0)) 00240 * 00241 * If release == false then the s buffer is used directly, and any 00242 * existing buffer is destroyed. If s == 0 then it will _not_ be 00243 * used, and instead the internal buffer is set to NULL_String_. 00244 * 00245 * @param s Non-zero terminated input string 00246 * @param len Length of input string 's' 00247 * @param release Allocator responsible(true)/not reponsible(false) for 00248 * freeing memory. 00249 */ 00250 void set (const ACE_CHAR_T * s, size_type len, bool release); 00251 00252 /** 00253 * Clear this string. Memory is _not_ freed if @a release is false. 00254 * 00255 * Warning: This method was incorrectly documented in the past, but 00256 * the current implementation has been changed to match the documented 00257 * behavior. 00258 * 00259 * Warning: clear(false) behaves like fast_clear() below. 00260 * 00261 * @param release Memory is freed if true, and not freed if false. 00262 */ 00263 void clear (bool release = false); 00264 00265 /** 00266 * A more specialized version of clear(): "fast clear". fast_clear() 00267 * resets the string to 0 length. If the string owns the buffer 00268 * (@arg release_== true): 00269 * - the string buffer is not freed 00270 * - the first character of the buffer is set to 0. 00271 * 00272 * If @arg release_ is false (this object does not own the buffer): 00273 * - the buffer pointer is reset to the NULL_String_ and does not 00274 * maintain a pointer to the caller-supplied buffer on return 00275 * - the maximum string length is reset to 0. 00276 * 00277 * Warning : Calling clear(false) or fast_clear() can have unintended 00278 * side-effects if the string was constructed (or set()) with an 00279 * external buffer. The string will be disassociated with the buffer 00280 * and the next append() or +=() will cause a new buffer to be 00281 * allocated internally. 00282 */ 00283 void fast_clear (void); 00284 00285 /** 00286 * Return a substring given an offset and length. 00287 * If length == @c npos use rest of str. Return empty substring if 00288 * offset or offset/length are invalid. 00289 * 00290 * @param offset Index of first desired character of the substring. 00291 * @param length How many characters to return starting at the offset. 00292 * @return The string containing the desired substring 00293 */ 00294 ACE_String_Base < ACE_CHAR_T > substring (size_type offset, 00295 size_type length = npos) const; 00296 00297 /** 00298 * Same as <substring>. 00299 * 00300 * @param offset Index of first desired character of the substring. 00301 * @param length How many characters to return starting at the offset. 00302 * @return The string containing the desired substring 00303 */ 00304 ACE_String_Base < ACE_CHAR_T > substr (size_type offset, 00305 size_type length = npos) const; 00306 00307 /** 00308 * Concat operator (copies memory). 00309 * 00310 * @param s Input ACE_String_Base string to concatenate to this string. 00311 * @return The combined string (input append to the end of the old). New 00312 * string is zero terminated. 00313 */ 00314 ACE_String_Base < ACE_CHAR_T > &operator += (const ACE_String_Base < ACE_CHAR_T > &s); 00315 00316 /** 00317 * Concat operator (copies memory). 00318 * 00319 * @param s Input C string to concatenate to this string. 00320 * @return The combined string (input append to the end of the old). New 00321 * string is zero terminated. 00322 */ 00323 ACE_String_Base < ACE_CHAR_T >& operator += (const ACE_CHAR_T* s); 00324 00325 /** 00326 * Concat operator (copies memory). 00327 * 00328 * @param c Input ACE_CHAR_T to concatenate to this string. 00329 * @return The combined string (input append to the end of the old). New 00330 * string is zero terminated. 00331 */ 00332 ACE_String_Base < ACE_CHAR_T >& operator += (const ACE_CHAR_T c); 00333 00334 /** 00335 * Append function (copies memory). 00336 * 00337 * @param s Input ACE_CHAR_T array to concatenate to this string. 00338 * @param slen The length of the array. 00339 * @return The combined string (input append to the end of the old). New 00340 * string is zero terminated. 00341 */ 00342 ACE_String_Base < ACE_CHAR_T >& append (const ACE_CHAR_T* s, size_type slen); 00343 00344 /** 00345 * Returns a hash value for this string. 00346 * 00347 * @return Hash value of string 00348 */ 00349 u_long hash (void) const; 00350 00351 /** 00352 * Return the length of the string. 00353 * 00354 * @return Length of stored string 00355 */ 00356 size_type length (void) const; 00357 00358 /** 00359 * Return the number of allocated CHARs in the string object. 00360 * This may be greater than the current length of the string. 00361 * 00362 * @return Maximum number of ACE_CHAR_T units that can be stored, including 00363 * any terminating nul that may be needed. 00364 */ 00365 size_t capacity (void) const; 00366 00367 /** 00368 * Return @c true if the length of the string is zero, else @c false. 00369 */ 00370 bool is_empty (void) const; 00371 00372 /** 00373 * Return @c true if the length of the string is zero, else @c 00374 * false. We recommend using @c is_empty() instead since it's more 00375 * consistent with the ACE container naming conventions. 00376 */ 00377 bool empty (void) const; 00378 00379 /** 00380 * Get a copy of the underlying representation. 00381 * 00382 * This method allocates memory for a copy of the string and returns 00383 * a pointer to the new area. The caller is responsible for freeing 00384 * the memory when finished; use delete [] 00385 * 00386 * @return Pointer reference to the string data. Returned string is 00387 * zero terminated. 00388 */ 00389 ACE_CHAR_T *rep (void) const; 00390 00391 /** 00392 * Get at the underlying representation directly! 00393 * _Don't_ even think about casting the result to (char *) and modifying it, 00394 * if it has length 0! 00395 * 00396 * @return Pointer reference to the stored string data. No guarantee is 00397 * that the string is zero terminated. 00398 * 00399 */ 00400 const ACE_CHAR_T *fast_rep (void) const; 00401 00402 /** 00403 * Same as STL String's <c_str> and <fast_rep>. 00404 */ 00405 const ACE_CHAR_T *c_str (void) const; 00406 00407 /** 00408 * Comparison operator that will match substrings. Returns the 00409 * slot of the first location that matches, else @c npos. 00410 * 00411 * @param s Input ACE_String_Base string 00412 * @return Integer index value of the first location of string @a s or 00413 * @c npos (not found). 00414 */ 00415 size_type strstr (const ACE_String_Base<ACE_CHAR_T> &s) const; 00416 00417 /** 00418 * Find <str> starting at pos. Returns the slot of the first 00419 * location that matches (will be >= pos), else @c npos. 00420 * 00421 * @param str Input ACE_String_Base string to search for in stored string. 00422 * @param pos Starting index position to start searching for string @a str. 00423 * @return Index value of the first location of string @a str else 00424 * @c npos. 00425 */ 00426 size_type find (const ACE_String_Base<ACE_CHAR_T> &str, size_type pos = 0) const; 00427 00428 /** 00429 * Find @a s starting at pos. Returns the slot of the first 00430 * location that matches (will be >= pos), else @c npos. 00431 * 00432 * @param s non-zero input string to search for in stored string. 00433 * @param pos Starting index position to start searching for string @a str. 00434 * @return Index value of the first location of string @a str else 00435 * @c npos. 00436 */ 00437 size_type find (const ACE_CHAR_T *s, size_type pos = 0) const; 00438 00439 /** 00440 * Find @a c starting at pos. Returns the slot of the first 00441 * location that matches (will be >= pos), else @c npos. 00442 * 00443 * @param c Input character to search for in stored string. 00444 * @param pos Starting index position to start searching for string @a str. 00445 * @return Index value of the first location of string @a str else 00446 * @c npos. 00447 */ 00448 size_type find (ACE_CHAR_T c, size_type pos = 0) const; 00449 00450 /** 00451 * Find @a c starting at pos (counting from the end). Returns the 00452 * slot of the first location that matches, else @c npos. 00453 * 00454 * @param c Input character to search for in stored string. 00455 * @param pos Starting index position to start searching for string @a str. 00456 * @return Index value of the first location of string @a str else 00457 * @c npos. 00458 */ 00459 size_type rfind (ACE_CHAR_T c, size_type pos = npos) const; 00460 00461 /** 00462 * Equality comparison operator (must match entire string). 00463 * 00464 * @param s Input ACE_String_Base string to compare against stored string. 00465 * @return @c true if equal, @c false otherwise. 00466 */ 00467 bool operator == (const ACE_String_Base<ACE_CHAR_T> &s) const; 00468 00469 /** 00470 * Equality comparison operator (must match entire string). 00471 * 00472 * @param s Null terminated string to compare against stored string. 00473 * @return @c true if equal, @c false otherwise. 00474 */ 00475 bool operator == (const ACE_CHAR_T *s) const; 00476 00477 /** 00478 * Less than comparison operator. 00479 * 00480 * @param s Input ACE_String_Base string to compare against stored string. 00481 * @return @c true if less than, @c false otherwise. 00482 */ 00483 bool operator < (const ACE_String_Base<ACE_CHAR_T> &s) const; 00484 00485 /** 00486 * Greater than comparison operator. 00487 * 00488 * @param s Input ACE_String_Base string to compare against stored string. 00489 * @return @c true if greater than, @c false otherwise. 00490 */ 00491 bool operator > (const ACE_String_Base<ACE_CHAR_T> &s) const; 00492 00493 /** 00494 * Inequality comparison operator. 00495 * 00496 * @param s String to compare against stored string. 00497 * @return @c true if not equal, @c false otherwise. 00498 */ 00499 bool operator != (const ACE_String_Base<ACE_CHAR_T> &s) const; 00500 00501 /** 00502 * Inequality comparison operator. 00503 * 00504 * @param s Null terminated string to compare against stored string. 00505 * @return @c true if not equal, @c false otherwise. 00506 */ 00507 bool operator != (const ACE_CHAR_T *s) const; 00508 00509 /** 00510 * Performs a strncmp comparison. 00511 * 00512 * @param s Input ACE_String_Base string to compare against stored string. 00513 * @return Integer value of result (less than 0, 0, greater than 0) 00514 * depending on how input string @a s is to the stored string. 00515 */ 00516 int compare (const ACE_String_Base<ACE_CHAR_T> &s) const; 00517 00518 /** 00519 * Dump the state of an object. 00520 */ 00521 void dump (void) const; 00522 00523 /** 00524 * This method is designed for high-performance. Please use with 00525 * care ;-) 00526 * 00527 * Warning : This method was documented incorrectly in the past. 00528 * The original intention was to change the length of the string to 00529 * len, and to fill the whole thing with c CHARs. 00530 * However, what was actually done was to set the length of the 00531 * string to zero, and fill the buffer with c's. The buffer was 00532 * also not null-terminated unless c happened to be zero. 00533 * Rather than fix the method to work as documented, the code is 00534 * left as is, but the second parameter should probably not be used. 00535 * 00536 * fast_resize just adjusts the buffer if needed and sets the length, 00537 * it doesn't fill the buffer, so is much faster. 00538 * 00539 * @param len The number of CHARs to reserve 00540 * @param c The ACE_CHAR_T to use when filling the string. 00541 */ 00542 void resize (size_type len, ACE_CHAR_T c = 0); 00543 void fast_resize (size_t len); 00544 00545 /// Swap the contents of this @c ACE_String_Base with @a str. 00546 /** 00547 * @note This is non-throwing operation. 00548 */ 00549 void swap (ACE_String_Base<ACE_CHAR_T> & str); 00550 00551 iterator begin (void); 00552 const_iterator begin (void) const; 00553 00554 iterator end (void); 00555 const_iterator end (void) const; 00556 00557 /** 00558 * Declare the dynamic allocation hooks. 00559 */ 00560 ACE_ALLOC_HOOK_DECLARE; 00561 00562 protected: 00563 /** 00564 * Pointer to a memory allocator. 00565 */ 00566 ACE_Allocator *allocator_; 00567 00568 /** 00569 * Length of the ACE_String_Base data (not counting the trailing '\0'). 00570 */ 00571 size_type len_; 00572 00573 /** 00574 * Length of the ACE_String_Base data buffer. Keeping track of the 00575 * length allows to avoid unnecessary dynamic allocations. 00576 */ 00577 size_type buf_len_; 00578 00579 /** 00580 * Pointer to data. 00581 */ 00582 ACE_CHAR_T *rep_; 00583 00584 /** 00585 * Flag that indicates if we own the memory 00586 */ 00587 bool release_; 00588 00589 /** 00590 * Represents the "NULL" string to simplify the internal logic. 00591 */ 00592 static ACE_CHAR_T NULL_String_; 00593 }; 00594 00595 /** 00596 * @class ACE_String_Base_Iterator 00597 * 00598 * @brief Iterator class for the ACE_String_Base class. 00599 * 00600 * This class is an implementation of an iterator that allows client 00601 * applications it iterator over the contents of a string. Currently, 00602 * now this iterator fall under the std::bidirectional_iterator_tag 00603 * category. Future versions of the class will support the operations 00604 * of std::random_access_iterator_tag. 00605 */ 00606 template <class ACE_CHAR_T> 00607 class ACE_String_Base_Iterator 00608 { 00609 public: 00610 // = std::iterator_traits typedefs/traits. 00611 typedef std::bidirectional_iterator_tag iterator_category; 00612 typedef ACE_CHAR_T value_type; 00613 typedef ACE_CHAR_T & reference; 00614 typedef ACE_CHAR_T * pointer; 00615 typedef ptrdiff_t difference_type; 00616 00617 /** 00618 * Initializing constructor 00619 * 00620 * @param[in] str Target string for iterator. 00621 */ 00622 ACE_String_Base_Iterator (ACE_String_Base <ACE_CHAR_T> & str, int end = 0); 00623 00624 /** 00625 * Copy constructor 00626 * 00627 * @param[in] iter Iterator to copy. 00628 */ 00629 ACE_String_Base_Iterator (const ACE_String_Base_Iterator <ACE_CHAR_T> & iter); 00630 00631 /// Destructor. 00632 ~ACE_String_Base_Iterator (void); 00633 00634 /** 00635 * Test if the iterator has seen all characters. 00636 * 00637 * @retval 0 Characters still remain. 00638 * @retval 1 All characters have been seen. 00639 */ 00640 int done (void) const; 00641 00642 /** 00643 * Get the current character. 00644 * 00645 * @param[out] ch The current character. 00646 * @retval 0 All characters have been seen. 00647 * @retval 1 Items still remain to be seen. 00648 */ 00649 int next (ACE_CHAR_T * & ch) const; 00650 00651 /** 00652 * Move to the next character in the string. 00653 * 00654 * @retval 0 All characters have been seen. 00655 * @retval 1 Items still remain to be seen. 00656 */ 00657 int advance (void); 00658 00659 /** 00660 * Assignment operator 00661 * 00662 * @param[in] iter Right-hand side of operator. 00663 * @return Reference to self. 00664 */ 00665 const ACE_String_Base_Iterator <ACE_CHAR_T> & operator = (const ACE_String_Base_Iterator <ACE_CHAR_T> & iter); 00666 00667 /** 00668 * Dereference operator 00669 * 00670 * @return Reference to current character seen by iterator. 00671 */ 00672 ACE_CHAR_T & operator * (void); 00673 00674 /** 00675 * Prefix operator 00676 */ 00677 ACE_String_Base_Iterator <ACE_CHAR_T> & operator ++ (void); 00678 00679 /** 00680 * Postfix operator 00681 */ 00682 ACE_String_Base_Iterator <ACE_CHAR_T> operator ++ (int); 00683 00684 /** 00685 * Prefix operator 00686 */ 00687 ACE_String_Base_Iterator <ACE_CHAR_T> & operator -- (void); 00688 00689 /** 00690 * Postfix operator 00691 */ 00692 ACE_String_Base_Iterator <ACE_CHAR_T> operator -- (int); 00693 00694 /** 00695 * Eqaulity comparison operator 00696 * 00697 * @param[in] rhs Right-hand side of operator. 00698 */ 00699 bool operator == (const ACE_String_Base_Iterator <ACE_CHAR_T> & rhs) const; 00700 00701 /** 00702 * Ineqaulity comparison operator 00703 * 00704 * @param[in] rhs Right-hand side of operator. 00705 */ 00706 bool operator != (const ACE_String_Base_Iterator <ACE_CHAR_T> & rhs) const; 00707 00708 bool operator < (const ACE_String_Base_Iterator <ACE_CHAR_T> & rhs) const; 00709 bool operator > (const ACE_String_Base_Iterator <ACE_CHAR_T> & rhs) const; 00710 00711 bool operator <= (const ACE_String_Base_Iterator <ACE_CHAR_T> & rhs) const; 00712 bool operator >= (const ACE_String_Base_Iterator <ACE_CHAR_T> & rhs) const; 00713 00714 private: 00715 /// Target string to iterate over. 00716 ACE_String_Base <ACE_CHAR_T> * str_; 00717 00718 /// Current location in the string. 00719 size_t index_; 00720 }; 00721 00722 /** 00723 * @class ACE_String_Base_Const_Iterator 00724 * 00725 * @brief Const iterator class for the ACE_String_Base class. 00726 * 00727 * This class is an implementation of an iterator that allows client 00728 * applications it iterator over the contents of a string. Currently, 00729 * now this iterator fall under the std::bidirectional_iterator_tag 00730 * category. Future versions of the class will support the operations 00731 * of std::random_access_iterator_tag. 00732 */ 00733 template <class ACE_CHAR_T> 00734 class ACE_String_Base_Const_Iterator 00735 { 00736 public: 00737 // = std::iterator_traits typedefs/traits. 00738 typedef std::bidirectional_iterator_tag iterator_category; 00739 typedef const ACE_CHAR_T value_type; 00740 typedef const ACE_CHAR_T & reference; 00741 typedef const ACE_CHAR_T * pointer; 00742 typedef ptrdiff_t difference_type; 00743 00744 /** 00745 * Initializing constructor 00746 * 00747 * @param[in] str Target string for iterator. 00748 */ 00749 ACE_String_Base_Const_Iterator (const ACE_String_Base <ACE_CHAR_T> & str, int end = 0); 00750 00751 /** 00752 * Copy constructor 00753 * 00754 * @param[in] iter Iterator to copy. 00755 */ 00756 ACE_String_Base_Const_Iterator (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & iter); 00757 00758 /// Destructor. 00759 ~ACE_String_Base_Const_Iterator (void); 00760 00761 /** 00762 * Test if the iterator has seen all characters. 00763 * 00764 * @retval 0 Characters still remain. 00765 * @retval 1 All characters have been seen. 00766 */ 00767 int done (void) const; 00768 00769 /** 00770 * Get the current character. 00771 * 00772 * @param[out] ch The current character. 00773 * @retval 0 All characters have been seen. 00774 * @retval 1 Items still remain to be seen. 00775 */ 00776 int next (const ACE_CHAR_T * & ch) const; 00777 00778 /** 00779 * Move to the next character in the string. 00780 * 00781 * @retval 0 All characters have been seen. 00782 * @retval 1 Items still remain to be seen. 00783 */ 00784 int advance (void); 00785 00786 /** 00787 * Assignment operator 00788 * 00789 * @param[in] iter Right-hand side of operator. 00790 * @return Reference to self. 00791 */ 00792 const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & operator = (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & iter); 00793 00794 /** 00795 * Dereference operator 00796 * 00797 * @return Reference to current character seen by iterator. 00798 */ 00799 const ACE_CHAR_T & operator * (void); 00800 00801 /** 00802 * Prefix operator 00803 */ 00804 ACE_String_Base_Const_Iterator <ACE_CHAR_T> & operator ++ (void); 00805 00806 /** 00807 * Postfix operator 00808 */ 00809 ACE_String_Base_Const_Iterator <ACE_CHAR_T> operator ++ (int); 00810 00811 /** 00812 * Prefix operator 00813 */ 00814 ACE_String_Base_Const_Iterator <ACE_CHAR_T> & operator -- (void); 00815 00816 /** 00817 * Postfix operator 00818 */ 00819 ACE_String_Base_Const_Iterator <ACE_CHAR_T> operator -- (int); 00820 00821 /** 00822 * Eqaulity comparison operator 00823 * 00824 * @param[in] rhs Right-hand side of operator. 00825 */ 00826 bool operator == (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const; 00827 00828 /** 00829 * Ineqaulity comparison operator 00830 * 00831 * @param[in] rhs Right-hand side of operator. 00832 */ 00833 bool operator != (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const; 00834 00835 bool operator < (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const; 00836 bool operator > (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const; 00837 00838 bool operator <= (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const; 00839 bool operator >= (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const; 00840 00841 private: 00842 /// Target string to iterate over. 00843 const ACE_String_Base <ACE_CHAR_T> * str_; 00844 00845 /// Current location in the string. 00846 size_t index_; 00847 }; 00848 00849 template < class ACE_CHAR_T > 00850 ACE_String_Base < ACE_CHAR_T > operator + (const ACE_String_Base < ACE_CHAR_T > &, 00851 const ACE_String_Base < ACE_CHAR_T > &); 00852 template < class ACE_CHAR_T > 00853 ACE_String_Base < ACE_CHAR_T > operator + (const ACE_String_Base < ACE_CHAR_T > &, 00854 const ACE_CHAR_T *); 00855 template < class ACE_CHAR_T > 00856 ACE_String_Base < ACE_CHAR_T > operator + (const ACE_CHAR_T *, 00857 const ACE_String_Base < ACE_CHAR_T > &); 00858 00859 template < class ACE_CHAR_T > 00860 ACE_String_Base < ACE_CHAR_T > operator + (const ACE_String_Base < ACE_CHAR_T > &t, 00861 const ACE_CHAR_T c); 00862 00863 template < class ACE_CHAR_T > 00864 ACE_String_Base < ACE_CHAR_T > operator + (const ACE_CHAR_T c, 00865 const ACE_String_Base < ACE_CHAR_T > &t); 00866 00867 template <class ACE_CHAR_T> 00868 bool operator == (const ACE_CHAR_T *s, 00869 const ACE_String_Base<ACE_CHAR_T> &t); 00870 00871 template <class ACE_CHAR_T> 00872 bool operator != (const ACE_CHAR_T *s, 00873 const ACE_String_Base<ACE_CHAR_T> &t); 00874 00875 ACE_END_VERSIONED_NAMESPACE_DECL 00876 00877 #if defined (__ACE_INLINE__) 00878 #include "ace/String_Base.inl" 00879 #endif /* __ACE_INLINE__ */ 00880 00881 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00882 #include "ace/String_Base.cpp" 00883 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00884 00885 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00886 #pragma implementation ("String_Base.cpp") 00887 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00888 00889 #include /**/ "ace/post.h" 00890 00891 #endif /* ACE_STRING_BASE_H */