1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 // -*- c++ -*- 19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 20 21 // O S C L_ S T R I N G _ C O N T A I N E R S 22 // 23 // This file contains a standardized set of string containers that 24 // can be used in place of character arrays. 25 26 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 27 28 /*! \addtogroup osclutil OSCL Util 29 * 30 * @{ 31 */ 32 33 34 /*! 35 * \file oscl_string_containers.h 36 * \brief Provides a standardized set of string containers that 37 * can be used in place of character arrays. 38 * 39 */ 40 41 42 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED 43 #define OSCL_STRING_CONTAINERS_H_INCLUDED 44 45 46 #ifndef OSCL_STRING_H_INCLUDED 47 #include "oscl_string.h" 48 #endif 49 50 #ifndef OSCL_DEFALLOC_H_INCLUDED 51 #include "oscl_defalloc.h" 52 #endif 53 54 #ifndef OSCL_REFCOUNTER_H_INCLUDED 55 #include "oscl_refcounter.h" 56 #endif 57 58 #ifndef OSCL_ERROR_H_INCLUDED 59 #include "oscl_error.h" 60 #endif 61 62 #ifndef OSCL_STRING_REP_H_INCLUDED 63 #include "oscl_string_rep.h" 64 #endif 65 66 #ifndef OSCL_STDSTRING_H_INCLUDED 67 #include "oscl_stdstring.h" 68 #endif 69 70 #ifndef OSCL_MEM_H_INCLUDED 71 #include "oscl_mem.h" 72 #endif 73 74 /** 75 OSCL_HeapString is a simple string class, compatible with 76 regular character array strings. 77 78 The string array is variable length, is allocated from the heap, 79 and is modifiable. 80 A copy-on-write mechanism is used to minimize unnecessary copying when 81 multiple instances of a string are created for reading. 82 Allocated memory is automatically freed by the class destructor when 83 the last string referencing the memory is destroyed. 84 85 The class HAS NO thread synchronization built-in, so it is NOT MT-SAFE. 86 External locks should be used if the class is to be shared across threads. 87 88 @param Alloc: memory allocator, derived from Oscl_DefAlloc. 89 */ 90 template <class Alloc> 91 class OSCL_HeapString : public OSCL_String 92 { 93 public: 94 typedef OSCL_String::chartype chartype; 95 96 /** 97 The default constructor creates an empty string. 98 */ 99 OSCL_HeapString(); 100 101 /** 102 Creates a heap string that contains a copy of the input 103 string. 104 @param src: input string. 105 */ 106 OSCL_HeapString(const OSCL_HeapString& src); 107 OSCL_HeapString(const OSCL_String& src); 108 109 /** 110 Creates a heap string that contains a copy of the input 111 string. 112 @param cp: null-terminated string. 113 */ 114 OSCL_HeapString(const chartype* cstr); 115 116 /** 117 Creates a heap string that contains a copy of the input 118 string or character array. 119 @param src: character array, not necessarily null-terminated. 120 @param length: number of characters to copy. 121 */ 122 OSCL_HeapString(const chartype* buf, uint32 length); 123 124 ~OSCL_HeapString(); 125 126 /** Pure virtuals from OSCL_String 127 */ 128 uint32 get_size() const; 129 uint32 get_maxsize() const; 130 const chartype* get_cstr() const; 131 chartype* get_str() const; 132 133 /** Assignment operators 134 */ 135 OSCL_HeapString& operator=(const OSCL_HeapString& src); 136 OSCL_HeapString& operator=(const OSCL_String& src); 137 OSCL_HeapString& operator=(const chartype* cstr); 138 139 /** 140 Set the contents of this string to a new string or 141 character array. 142 @param buf: string or character array. 143 @param length: number of characters to copy. 144 */ 145 void set(const chartype* buf, uint32 length); 146 147 private: 148 CHeapRep *iRep; 149 Alloc iAlloc; 150 void create(); 151 void set_rep(const chartype*, uint32); 152 void append_rep(const chartype*, uint32); 153 154 /** Pure virtuals from OSCL_String. 155 */ 156 void set_rep(const chartype* cstr); 157 void append_rep(const chartype* cstr); 158 void set_rep(const OSCL_String& src); 159 void append_rep(const OSCL_String& src); 160 void set_len(uint32 len); 161 friend class OSCL_String; 162 }; 163 164 /** 165 OSCL_wHeapString is identical to OSCL_HeapString 166 except that it uses wide-character format. 167 For descriptions, see OSCL_HeapString. 168 */ 169 template <class Alloc> 170 class OSCL_wHeapString : public OSCL_wString 171 { 172 public: 173 typedef OSCL_wString::chartype chartype; 174 175 OSCL_wHeapString(); 176 177 OSCL_wHeapString(const OSCL_wHeapString& src); 178 OSCL_wHeapString(const OSCL_wString& src); 179 180 OSCL_wHeapString(const chartype* cstr); 181 OSCL_wHeapString(const chartype* buf, uint32 length); 182 183 ~OSCL_wHeapString(); 184 185 uint32 get_size() const; 186 uint32 get_maxsize() const; 187 const chartype* get_cstr() const; 188 chartype* get_str() const; 189 190 OSCL_wHeapString& operator=(const OSCL_wHeapString& src); 191 OSCL_wHeapString& operator=(const OSCL_wString& src); 192 OSCL_wHeapString& operator=(const chartype* cstr); 193 194 void set(const chartype* buf, uint32 length); 195 196 private: 197 CHeapRep *iRep; 198 Alloc iAlloc; 199 void create(); 200 void set_rep(const chartype*, uint32); 201 void append_rep(const chartype*, uint32); 202 203 void set_rep(const chartype* cstr); 204 void append_rep(const chartype* cstr); 205 void set_rep(const OSCL_wString& src); 206 void append_rep(const OSCL_wString& src); 207 void set_len(uint32 len); 208 friend class OSCL_wString; 209 }; 210 211 /** 212 OSCL_HeapStringA is a simple string class, compatible with 213 regular character array strings. It is similar to 214 OSCL_HeapString, except that the allocator is passed at 215 run-time instead of compile-time. 216 The allocator pointer is passed in the constructor, and 217 may be a reference-counted object. 218 If the allocator is not a reference-counted object then it must 219 persist over the lifetime of all OSCL_HeapStringA objects that use it. 220 If no allocator is provided, then an OsclMemAllocator 221 will be used. 222 223 The string array is variable length, is allocated from the heap, 224 and is modifiable. 225 A copy-on-write mechanism is used to minimize unnecessary copying when 226 multiple instances of a string are created for reading. 227 Allocated memory is automatically freed by the class destructor when 228 the last string referencing the memory is destroyed. 229 230 The class HAS NO thread synchronization built-in, so it is NOT MT-SAFE. 231 External locks should be used if the class is to be shared across threads. 232 233 */ 234 class OSCL_HeapStringA : public OSCL_String 235 { 236 public: 237 typedef OSCL_String::chartype chartype; 238 239 240 /** 241 The default constructor creates an empty string. 242 @param: (optional) allocator or reference-counted allocator. 243 @param: (optional) reference counter associated with allocator object. 244 If no allocator is provided, this this object will use 245 an OsclMemAllocator. 246 */ 247 OSCL_IMPORT_REF OSCL_HeapStringA(); 248 OSCL_IMPORT_REF OSCL_HeapStringA(Oscl_DefAlloc *alloc, OsclRefCounter *ref = NULL); 249 250 /** 251 Creates a heap string that contains a copy of the input 252 string. 253 @param src: input string. 254 @param: (optional) allocator or reference-counted allocator. 255 @param: (optional) reference counter associated with allocator object. 256 If no allocator is provided, this this object will use 257 an OsclMemAllocator. 258 */ 259 OSCL_IMPORT_REF OSCL_HeapStringA(const OSCL_HeapStringA& src); 260 OSCL_IMPORT_REF OSCL_HeapStringA(const OSCL_HeapStringA& src, Oscl_DefAlloc *alloc, OsclRefCounter *ref = NULL); 261 OSCL_IMPORT_REF OSCL_HeapStringA(const OSCL_String& src, Oscl_DefAlloc *alloc = NULL, OsclRefCounter *ref = NULL); 262 263 /** 264 Creates a heap string that contains a copy of the input 265 string. 266 @param cp: null-terminated string. 267 @param: (optional) allocator or reference-counted allocator. 268 @param: (optional) reference counter associated with allocator object. 269 If no allocator is provided, this this object will use 270 an OsclMemAllocator. 271 */ 272 OSCL_IMPORT_REF OSCL_HeapStringA(const chartype* cstr, Oscl_DefAlloc *alloc = NULL, OsclRefCounter *ref = NULL); 273 274 /** 275 Creates a heap string that contains a copy of the input 276 string or character array. 277 @param src: character array, not necessarily null-terminated. 278 @param length: number of characters to copy. 279 @param: (optional) allocator or reference-counted allocator. 280 @param: (optional) reference counter associated with allocator object. 281 If no allocator is provided, this this object will use 282 an OsclMemAllocator. 283 */ 284 OSCL_IMPORT_REF OSCL_HeapStringA(const chartype* buf, uint32 length, Oscl_DefAlloc *alloc = NULL, OsclRefCounter *ref = NULL); 285 286 OSCL_IMPORT_REF ~OSCL_HeapStringA(); 287 288 /** Pure virtuals from OSCL_String 289 */ 290 OSCL_IMPORT_REF uint32 get_size() const; 291 OSCL_IMPORT_REF uint32 get_maxsize() const; 292 OSCL_IMPORT_REF const chartype* get_cstr() const; 293 OSCL_IMPORT_REF chartype* get_str() const; 294 295 /** Assignment operators 296 */ 297 OSCL_IMPORT_REF OSCL_HeapStringA& operator=(const OSCL_HeapStringA& src); 298 OSCL_IMPORT_REF OSCL_HeapStringA& operator=(const OSCL_String& src); 299 OSCL_IMPORT_REF OSCL_HeapStringA& operator=(const chartype* cstr); 300 301 /** 302 Set the contents of this string to a new string or 303 character array. 304 @param buf: string or character array. 305 @param length: number of characters to copy. 306 */ 307 OSCL_IMPORT_REF void set(const chartype* buf, uint32 length); 308 309 private: 310 CHeapRep *iRep; 311 OsclRefCounter *iAllocRef; 312 Oscl_DefAlloc *iAlloc; 313 OsclMemAllocator iDefAlloc; 314 void create(Oscl_DefAlloc *, OsclRefCounter*); 315 void set_rep(const chartype*, uint32); 316 void append_rep(const chartype*, uint32); 317 318 /** Pure virtuals from OSCL_String. 319 */ 320 void set_rep(const chartype* cstr); 321 void append_rep(const chartype* cstr); 322 void set_rep(const OSCL_String& src); 323 void append_rep(const OSCL_String& src); 324 void set_len(uint32 len); 325 friend class OSCL_String; 326 }; 327 328 /** 329 OSCL_wHeapStringA is identical to OSCL_HeapStringA 330 except that it uses wide-character format. 331 For descriptions, see OSCL_HeapStringA. 332 */ 333 class OSCL_wHeapStringA : public OSCL_wString 334 { 335 public: 336 typedef OSCL_wString::chartype chartype; 337 338 OSCL_IMPORT_REF OSCL_wHeapStringA(); 339 OSCL_IMPORT_REF OSCL_wHeapStringA(Oscl_DefAlloc *alloc, OsclRefCounter *ref = NULL); 340 341 OSCL_IMPORT_REF OSCL_wHeapStringA(const OSCL_wHeapStringA& src); 342 OSCL_IMPORT_REF OSCL_wHeapStringA(const OSCL_wHeapStringA& src, Oscl_DefAlloc *alloc, OsclRefCounter *ref = NULL); 343 OSCL_IMPORT_REF OSCL_wHeapStringA(const OSCL_wString& src, Oscl_DefAlloc *alloc = NULL, OsclRefCounter *ref = NULL); 344 345 OSCL_IMPORT_REF OSCL_wHeapStringA(const chartype* cstr, Oscl_DefAlloc *alloc = NULL, OsclRefCounter *ref = NULL); 346 347 OSCL_IMPORT_REF OSCL_wHeapStringA(const chartype* buf, uint32 length, Oscl_DefAlloc *alloc = NULL, OsclRefCounter *ref = NULL); 348 349 OSCL_IMPORT_REF ~OSCL_wHeapStringA(); 350 351 OSCL_IMPORT_REF uint32 get_size() const; 352 OSCL_IMPORT_REF uint32 get_maxsize() const; 353 OSCL_IMPORT_REF const chartype* get_cstr() const; 354 OSCL_IMPORT_REF chartype* get_str() const; 355 356 OSCL_IMPORT_REF OSCL_wHeapStringA& operator=(const OSCL_wHeapStringA& src); 357 OSCL_IMPORT_REF OSCL_wHeapStringA& operator=(const OSCL_wString& src); 358 OSCL_IMPORT_REF OSCL_wHeapStringA& operator=(const chartype* cstr); 359 360 OSCL_IMPORT_REF void set(const chartype* buf, uint32 length); 361 362 private: 363 CHeapRep *iRep; 364 OsclRefCounter *iAllocRef; 365 Oscl_DefAlloc *iAlloc; 366 OsclMemAllocator iDefAlloc; 367 void create(Oscl_DefAlloc *, OsclRefCounter*); 368 void set_rep(const chartype*, uint32); 369 void append_rep(const chartype*, uint32); 370 371 void set_rep(const chartype* cstr); 372 void append_rep(const chartype* cstr); 373 void set_rep(const OSCL_wString& src); 374 void append_rep(const OSCL_wString& src); 375 void set_len(uint32 len); 376 friend class OSCL_wString; 377 }; 378 379 380 /** 381 OSCL_StackString is a simple string class, compatible with 382 regular character array strings. 383 384 The string array is fixed length, is allocated from the stack, 385 and is modifiable. Operations that update the string will automatically 386 truncate it to fit the fixed size storage. 387 This is recommended for use for short strings (<255). 388 Use OSCL_HeapString for very large strings to avoid stack overflow. 389 390 @param C: type of character. 391 @param MaxBufSize: maximum string length not including null terminator. 392 */ 393 template <uint32 MaxBufSize> 394 class OSCL_StackString : public OSCL_String 395 { 396 public: 397 typedef OSCL_String::chartype chartype; 398 399 /** Creates an OSCL_StackString initialized with an empty string. 400 */ 401 OSCL_StackString(); 402 403 /** Creates an OSCL_StackString with a copy of the input string. 404 The string may be truncated to fit the available storage. 405 @param src: input string. 406 */ 407 OSCL_StackString(const OSCL_StackString& src); 408 OSCL_StackString(const OSCL_String& src); 409 410 /** Creates an OSCL_StackString with a copy of the input string. 411 The string may be truncated to fit the available storage. 412 @param cp: a null-terminated string. 413 */ 414 OSCL_StackString(const chartype* cstr); 415 416 /** Creates an OSCL_StackString with a copy of the input string. 417 The string may be truncated to fit the available storage. 418 @param src: a character array, not necessarily null-terminated. 419 @param length: the number of characters to copy. 420 */ 421 OSCL_StackString(const chartype* buf, uint32 length); 422 423 ~OSCL_StackString(); 424 425 /** Pure virtuals from OSCL_String 426 */ 427 uint32 get_size() const; 428 uint32 get_maxsize() const; 429 const chartype* get_cstr() const; 430 chartype* get_str() const; 431 432 /** Assignment operators 433 */ 434 OSCL_StackString& operator=(const OSCL_StackString& src); 435 OSCL_StackString& operator=(const OSCL_String& src); 436 OSCL_StackString& operator=(const chartype* cstr); 437 438 /** 439 Set the contents of this string to a new string or 440 character array. 441 @param buf: string or character array. 442 @param length: number of characters to copy. 443 */ 444 void set(const chartype* buf, uint32 length); 445 446 private: 447 CStackRep rep; 448 char buffer[MaxBufSize+1];//fixed string buffer. 449 void create(); 450 451 /** Pure virtuals from OSCL_String 452 */ 453 void set_rep(const chartype* cstr); 454 void append_rep(const chartype* cstr); 455 void set_rep(const OSCL_String& src); 456 void append_rep(const OSCL_String& src); 457 void set_len(uint32 len); 458 friend class OSCL_String; 459 }; 460 461 /** 462 OSCL_wStackString is identical to OSCL_StackString 463 except that it uses wide-character format. 464 For descriptions, see OSCL_StackString. 465 */ 466 template <uint32 MaxBufSize> 467 class OSCL_wStackString : public OSCL_wString 468 { 469 public: 470 typedef OSCL_wString::chartype chartype; 471 472 OSCL_wStackString(); 473 474 OSCL_wStackString(const OSCL_wStackString& src); 475 OSCL_wStackString(const OSCL_wString& src); 476 477 OSCL_wStackString(const chartype* cstr); 478 OSCL_wStackString(const chartype* buf, uint32 length); 479 480 ~OSCL_wStackString(); 481 482 uint32 get_size() const; 483 uint32 get_maxsize() const; 484 const chartype* get_cstr() const; 485 chartype* get_str() const; 486 487 OSCL_wStackString& operator=(const OSCL_wStackString& src); 488 OSCL_wStackString& operator=(const OSCL_wString& src); 489 OSCL_wStackString& operator=(const chartype* cstr); 490 491 void set(const chartype* buf, uint32 length); 492 493 private: 494 CStackRep rep; 495 chartype buffer[MaxBufSize+1];//fixed string buffer. 496 void create(); 497 498 void set_rep(const chartype* cstr); 499 void append_rep(const chartype* cstr); 500 void set_rep(const OSCL_wString& src); 501 void append_rep(const OSCL_wString& src); 502 void set_len(uint32 len); 503 friend class OSCL_wString; 504 }; 505 506 /** 507 OSCL_FastString is a simple string class, compatible with 508 regular character array strings. 509 510 This class does not allocate internal memory for the string but acts as 511 a container for a user-defined buffer. This means no copying of the string 512 is done and provides a faster way of manipulating strings. 513 Depending on initialization, this container provides either read-only 514 or read-write access to the string. 515 516 Implementation assumes the input string is null-terminated. 517 518 @param C: type of character. 519 */ 520 class OSCL_FastString : public OSCL_String 521 { 522 public: 523 typedef OSCL_String::chartype chartype; 524 525 /** 526 Default constructor. 527 */ 528 OSCL_IMPORT_REF OSCL_FastString(); 529 530 /** 531 Creates a fast string that contains a copy of the input 532 string. 533 The string inherits the writable-ness of the source string. 534 @param src: input string. 535 */ 536 OSCL_IMPORT_REF OSCL_FastString(const OSCL_FastString& src); 537 538 /** 539 Create the string and initialize it to contain the input string. 540 The string is not writable. 541 @param: null-terminated string. 542 */ 543 OSCL_IMPORT_REF OSCL_FastString(const chartype* cstr); 544 545 /** 546 Create the string and initialize it to contain the input string. 547 The string is writable. 548 @param cp: null-terminated string. 549 @param maxlen: maximum size of storage at cp, not incl null terminator. 550 If input string is not null-terminated, the function leaves. 551 */ 552 OSCL_IMPORT_REF OSCL_FastString(chartype* buf, uint32 maxlen); 553 554 OSCL_IMPORT_REF ~OSCL_FastString(); 555 556 /** Pure virtuals from OSCL_String 557 */ 558 OSCL_IMPORT_REF uint32 get_size() const; 559 OSCL_IMPORT_REF uint32 get_maxsize() const; 560 OSCL_IMPORT_REF const chartype* get_cstr() const; 561 OSCL_IMPORT_REF chartype* get_str() const; 562 563 /** Assignment operators 564 */ 565 OSCL_IMPORT_REF OSCL_FastString& operator=(const OSCL_FastString& src); 566 OSCL_IMPORT_REF OSCL_FastString& operator=(const chartype* cstr); 567 568 /** 569 This function can be used to reassign the string to a new 570 writable string. 571 If input string is not null-terminated, the function leaves. 572 */ 573 OSCL_IMPORT_REF void set(chartype* cstr, uint32 maxlen); 574 575 /** 576 This function can be used to refresh the string size in case the 577 contents of the string buffer have been modified since the 578 container was created. 579 */ 580 OSCL_IMPORT_REF void set_length(); 581 582 private: 583 CFastRep rep; 584 585 /** Pure virtuals from OSCL_String 586 */ 587 void set_rep(const chartype* cstr); 588 void append_rep(const chartype* cstr); 589 void set_rep(const OSCL_String& src); 590 void append_rep(const OSCL_String& src); 591 void set_len(uint32 len); 592 friend class OSCL_String; 593 }; 594 595 /** 596 OSCL_wFastString is identical to OSCL_FastString 597 except that it uses wide-character format. 598 For descriptions, see OSCL_FastString. 599 */ 600 class OSCL_wFastString : public OSCL_wString 601 { 602 public: 603 typedef OSCL_wString::chartype chartype; 604 605 OSCL_IMPORT_REF OSCL_wFastString(); 606 607 OSCL_IMPORT_REF OSCL_wFastString(const OSCL_wFastString& src); 608 609 OSCL_IMPORT_REF OSCL_wFastString(const chartype* cstr); 610 OSCL_IMPORT_REF OSCL_wFastString(chartype* buf, uint32 maxlen); 611 612 OSCL_IMPORT_REF ~OSCL_wFastString(); 613 614 OSCL_IMPORT_REF uint32 get_size() const; 615 OSCL_IMPORT_REF uint32 get_maxsize() const; 616 OSCL_IMPORT_REF const chartype* get_cstr() const; 617 OSCL_IMPORT_REF chartype* get_str() const; 618 619 OSCL_IMPORT_REF OSCL_wFastString& operator=(const OSCL_wFastString& src); 620 OSCL_IMPORT_REF OSCL_wFastString& operator=(const chartype* cstr); 621 622 OSCL_IMPORT_REF void set(chartype* cstr, uint32 maxlen); 623 624 OSCL_IMPORT_REF void set_length(); 625 626 private: 627 CFastRep rep; 628 629 void set_rep(const chartype* cstr); 630 void append_rep(const chartype* cstr); 631 void set_rep(const OSCL_wString& src); 632 void append_rep(const OSCL_wString& src); 633 void set_len(uint32 len); 634 friend class OSCL_wString; 635 }; 636 637 638 // ************************************************************** 639 // OSCL_HeapString<Alloc> Implementation 640 // OSCL_wHeapString<Alloc> Implementation 641 // ************************************************************** 642 643 template<class Alloc> 644 void OSCL_HeapString<Alloc>::set_rep(const chartype* cp, uint32 len) 645 //set heap rep to new string. 646 { 647 CHeapRep::set_rep(iRep, iAlloc, cp, len); 648 } 649 650 template<class Alloc> 651 void OSCL_wHeapString<Alloc>::set_rep(const chartype* cp, uint32 len) 652 //set heap rep to new string. 653 { 654 CHeapRep::set_rep(iRep, iAlloc, cp, len); 655 } 656 657 // ************************************************************** 658 template<class Alloc> 659 void OSCL_HeapString<Alloc>::append_rep(const chartype* cp, uint32 len) 660 //set heap rep to current string plus new string. 661 { 662 CHeapRep::append_rep(iRep, iAlloc, cp, len); 663 } 664 665 template<class Alloc> 666 void OSCL_wHeapString<Alloc>::append_rep(const chartype* cp, uint32 len) 667 //set heap rep to current string plus new string. 668 { 669 CHeapRep::append_rep(iRep, iAlloc, cp, len); 670 } 671 672 // ************************************************************** 673 template<class Alloc> 674 void OSCL_HeapString<Alloc>::set_rep(const chartype* cp) 675 { 676 set_rep(cp, (cp) ? oscl_strlen(cp) : 0); 677 } 678 679 template<class Alloc> 680 void OSCL_wHeapString<Alloc>::set_rep(const chartype* cp) 681 { 682 set_rep(cp, (cp) ? oscl_strlen(cp) : 0); 683 } 684 685 686 // ************************************************************** 687 template<class Alloc> 688 void OSCL_HeapString<Alloc>::append_rep(const chartype* cp) 689 { 690 append_rep(cp, (cp) ? oscl_strlen(cp) : 0); 691 } 692 693 template<class Alloc> 694 void OSCL_wHeapString<Alloc>::append_rep(const chartype* cp) 695 { 696 append_rep(cp, (cp) ? oscl_strlen(cp) : 0); 697 } 698 699 700 // ************************************************************** 701 template<class Alloc> 702 void OSCL_HeapString<Alloc>::set_rep(const OSCL_String& src) 703 { 704 set_rep(src.get_cstr(), src.get_size()); 705 } 706 707 template<class Alloc> 708 void OSCL_wHeapString<Alloc>::set_rep(const OSCL_wString& src) 709 { 710 set_rep(src.get_cstr(), src.get_size()); 711 } 712 713 714 // ************************************************************** 715 template<class Alloc> 716 void OSCL_HeapString<Alloc>::append_rep(const OSCL_String& src) 717 { 718 append_rep(src.get_cstr(), src.get_size()); 719 } 720 721 template<class Alloc> 722 void OSCL_wHeapString<Alloc>::append_rep(const OSCL_wString& src) 723 { 724 append_rep(src.get_cstr(), src.get_size()); 725 } 726 727 728 // ************************************************************** 729 template<class Alloc> 730 uint32 OSCL_HeapString<Alloc>::get_size() const 731 { 732 if (iRep) 733 return iRep->size; 734 return 0; 735 } 736 737 template<class Alloc> 738 uint32 OSCL_wHeapString<Alloc>::get_size() const 739 { 740 if (iRep) 741 return iRep->size; 742 return 0; 743 } 744 745 // ************************************************************** 746 template<class Alloc> 747 void OSCL_HeapString<Alloc>::set_len(uint32 len) 748 { 749 iRep->size = len; 750 } 751 752 template<class Alloc> 753 void OSCL_wHeapString<Alloc>::set_len(uint32 len) 754 { 755 iRep->size = len; 756 } 757 758 759 // ************************************************************** 760 template<class Alloc> 761 uint32 OSCL_HeapString<Alloc>::get_maxsize() const 762 { 763 if (iRep) 764 return iRep->maxsize; 765 return 0; 766 } 767 768 template<class Alloc> 769 uint32 OSCL_wHeapString<Alloc>::get_maxsize() const 770 { 771 if (iRep) 772 return iRep->maxsize; 773 return 0; 774 } 775 776 777 // ************************************************************** 778 template<class Alloc> 779 const typename OSCL_HeapString<Alloc>::chartype* OSCL_HeapString<Alloc>::get_cstr() const 780 { 781 if (iRep) 782 return (chartype*)iRep->buffer; 783 return NULL; 784 } 785 786 template<class Alloc> 787 const typename OSCL_wHeapString<Alloc>::chartype* OSCL_wHeapString<Alloc>::get_cstr() const 788 { 789 if (iRep) 790 return (chartype*)iRep->buffer; 791 return NULL; 792 } 793 794 795 // ************************************************************** 796 template<class Alloc> 797 typename OSCL_HeapString<Alloc>::chartype* OSCL_HeapString<Alloc>::get_str() const 798 { 799 if (iRep) 800 return (chartype*)iRep->buffer; 801 return NULL; 802 } 803 804 template<class Alloc> 805 typename OSCL_wHeapString<Alloc>::chartype* OSCL_wHeapString<Alloc>::get_str() const 806 { 807 if (iRep) 808 return (chartype*)iRep->buffer; 809 return NULL; 810 } 811 812 813 // ************************************************************** 814 template<class Alloc> 815 void OSCL_HeapString<Alloc>::create() 816 { 817 iRep = NULL; 818 } 819 820 template<class Alloc> 821 void OSCL_wHeapString<Alloc>::create() 822 { 823 iRep = NULL; 824 } 825 826 827 // ************************************************************** 828 template<class Alloc> 829 OSCL_HeapString<Alloc>::OSCL_HeapString() 830 { 831 create(); 832 set_rep(NULL); 833 } 834 835 template<class Alloc> 836 OSCL_wHeapString<Alloc>::OSCL_wHeapString() 837 { 838 create(); 839 set_rep(NULL); 840 } 841 842 843 // ************************************************************** 844 template<class Alloc> 845 OSCL_HeapString<Alloc>::OSCL_HeapString(const chartype* cp) 846 { 847 create(); 848 set_rep(cp); 849 } 850 851 template<class Alloc> 852 OSCL_wHeapString<Alloc>::OSCL_wHeapString(const chartype* cp) 853 { 854 create(); 855 set_rep(cp); 856 } 857 858 859 // ************************************************************** 860 template<class Alloc> 861 void OSCL_HeapString<Alloc>::set(const chartype* cp, uint32 length) 862 { 863 set_rep(cp, length); 864 //just in case input string is shorter than 'length' 865 iRep->size = oscl_strlen(get_cstr()); 866 } 867 868 template<class Alloc> 869 void OSCL_wHeapString<Alloc>::set(const chartype* cp, uint32 length) 870 { 871 set_rep(cp, length); 872 //just in case input string is shorter than 'length' 873 iRep->size = oscl_strlen(get_cstr()); 874 } 875 876 877 // ************************************************************** 878 template<class Alloc> 879 OSCL_HeapString<Alloc>::OSCL_HeapString(const chartype* cp, uint32 length) 880 { 881 create(); 882 set(cp, length); 883 } 884 885 template<class Alloc> 886 OSCL_wHeapString<Alloc>::OSCL_wHeapString(const chartype* cp, uint32 length) 887 { 888 create(); 889 set(cp, length); 890 } 891 892 // ************************************************************** 893 template<class Alloc> 894 OSCL_HeapString<Alloc>::OSCL_HeapString(const OSCL_HeapString<Alloc>& src) : OSCL_String(src) 895 { 896 create(); 897 if (src.iRep) 898 CHeapRep::assign(iRep, src.iRep, iAlloc); 899 else 900 set_rep(src); 901 } 902 903 template<class Alloc> 904 OSCL_wHeapString<Alloc>::OSCL_wHeapString(const OSCL_wHeapString<Alloc>& src) : OSCL_wString(src) 905 { 906 create(); 907 if (src.iRep) 908 CHeapRep::assign(iRep, src.iRep, iAlloc); 909 else 910 set_rep(src); 911 } 912 913 // ************************************************************** 914 template<class Alloc> 915 OSCL_HeapString<Alloc>::OSCL_HeapString(const OSCL_String& src) 916 { 917 create(); 918 set_rep(src); 919 } 920 921 template<class Alloc> 922 OSCL_wHeapString<Alloc>::OSCL_wHeapString(const OSCL_wString& src) 923 { 924 create(); 925 set_rep(src); 926 } 927 928 // ************************************************************** 929 template<class Alloc> 930 OSCL_HeapString<Alloc>::~OSCL_HeapString() 931 { 932 if (iRep) 933 iRep->remove_ref(iAlloc); 934 } 935 936 template<class Alloc> 937 OSCL_wHeapString<Alloc>::~OSCL_wHeapString() 938 { 939 if (iRep) 940 iRep->remove_ref(iAlloc); 941 } 942 943 944 // ************************************************************** 945 template<class Alloc> 946 OSCL_HeapString<Alloc>& OSCL_HeapString<Alloc>::operator=(const OSCL_HeapString<Alloc>& src) 947 { 948 if (src.iRep) 949 CHeapRep::assign(iRep, src.iRep, iAlloc); 950 else 951 set_rep(src); 952 return (*this); 953 } 954 955 template<class Alloc> 956 OSCL_wHeapString<Alloc>& OSCL_wHeapString<Alloc>::operator=(const OSCL_wHeapString<Alloc>& src) 957 { 958 if (src.iRep) 959 CHeapRep::assign(iRep, src.iRep, iAlloc); 960 else 961 set_rep(src); 962 return (*this); 963 } 964 965 // ************************************************************** 966 template<class Alloc> 967 OSCL_HeapString<Alloc>& OSCL_HeapString<Alloc>::operator=(const OSCL_String & src) 968 { 969 set_rep(src); 970 return (*this); 971 } 972 973 template<class Alloc> 974 OSCL_wHeapString<Alloc>& OSCL_wHeapString<Alloc>::operator=(const OSCL_wString & src) 975 { 976 set_rep(src); 977 return (*this); 978 } 979 980 // ************************************************************** 981 template<class Alloc> 982 OSCL_HeapString<Alloc>& OSCL_HeapString<Alloc>::operator=(const chartype * cp) 983 { 984 set_rep(cp); 985 return (*this); 986 } 987 988 template<class Alloc> 989 OSCL_wHeapString<Alloc>& OSCL_wHeapString<Alloc>::operator=(const chartype * cp) 990 { 991 set_rep(cp); 992 return (*this); 993 } 994 995 // ************************************************************** 996 // OSCL_StackString<MaxBufSize> Implementation 997 // OSCL_wStackString<MaxBufSize> Implementation 998 // ************************************************************** 999 template<uint32 MaxBufSize> 1000 void OSCL_StackString<MaxBufSize>::set_rep(const chartype* cp) 1001 { 1002 rep.set(cp, (cp) ? oscl_strlen(cp) : 0); 1003 } 1004 1005 template<uint32 MaxBufSize> 1006 void OSCL_wStackString<MaxBufSize>::set_rep(const chartype* cp) 1007 { 1008 rep.set(cp, (cp) ? oscl_strlen(cp) : 0); 1009 } 1010 1011 1012 // ************************************************************** 1013 template<uint32 MaxBufSize> 1014 void OSCL_StackString<MaxBufSize>::append_rep(const chartype* cp) 1015 { 1016 rep.append(cp, (cp) ? oscl_strlen(cp) : 0); 1017 } 1018 1019 template<uint32 MaxBufSize> 1020 void OSCL_wStackString<MaxBufSize>::append_rep(const chartype* cp) 1021 { 1022 rep.append(cp, (cp) ? oscl_strlen(cp) : 0); 1023 } 1024 1025 // ************************************************************** 1026 template<uint32 MaxBufSize> 1027 void OSCL_StackString<MaxBufSize>::set_rep(const OSCL_String& src) 1028 { 1029 rep.set(src.get_cstr(), src.get_size()); 1030 } 1031 1032 template<uint32 MaxBufSize> 1033 void OSCL_wStackString<MaxBufSize>::set_rep(const OSCL_wString& src) 1034 { 1035 rep.set(src.get_cstr(), src.get_size()); 1036 } 1037 1038 // ************************************************************** 1039 template<uint32 MaxBufSize> 1040 void OSCL_StackString<MaxBufSize>::append_rep(const OSCL_String& src) 1041 { 1042 rep.append(src.get_cstr(), src.get_size()); 1043 } 1044 1045 template<uint32 MaxBufSize> 1046 void OSCL_wStackString<MaxBufSize>::append_rep(const OSCL_wString& src) 1047 { 1048 rep.append(src.get_cstr(), src.get_size()); 1049 } 1050 1051 // ************************************************************** 1052 template<uint32 MaxBufSize> 1053 void OSCL_StackString<MaxBufSize>::set_len(uint32 len) 1054 { 1055 rep.size = len; 1056 } 1057 1058 template<uint32 MaxBufSize> 1059 void OSCL_wStackString<MaxBufSize>::set_len(uint32 len) 1060 { 1061 rep.size = len; 1062 } 1063 1064 // ************************************************************** 1065 template<uint32 MaxBufSize> 1066 uint32 OSCL_StackString<MaxBufSize>::get_size() const 1067 { 1068 return rep.size; 1069 } 1070 1071 template<uint32 MaxBufSize> 1072 uint32 OSCL_wStackString<MaxBufSize>::get_size() const 1073 { 1074 return rep.size; 1075 } 1076 1077 // ************************************************************** 1078 template<uint32 MaxBufSize> 1079 uint32 OSCL_StackString<MaxBufSize>::get_maxsize() const 1080 { 1081 return rep.maxsize; 1082 } 1083 1084 template<uint32 MaxBufSize> 1085 uint32 OSCL_wStackString<MaxBufSize>::get_maxsize() const 1086 { 1087 return rep.maxsize; 1088 } 1089 1090 // ************************************************************** 1091 template<uint32 MaxBufSize> 1092 const typename OSCL_StackString<MaxBufSize>::chartype* OSCL_StackString<MaxBufSize>::get_cstr() const 1093 { 1094 return (chartype*)rep.buffer; 1095 } 1096 1097 template<uint32 MaxBufSize> 1098 const typename OSCL_wStackString<MaxBufSize>::chartype* OSCL_wStackString<MaxBufSize>::get_cstr() const 1099 { 1100 return (chartype*)rep.buffer; 1101 } 1102 1103 // ************************************************************** 1104 template<uint32 MaxBufSize> 1105 typename OSCL_StackString<MaxBufSize>::chartype* OSCL_StackString<MaxBufSize>::get_str() const 1106 { 1107 return (chartype*)rep.buffer; 1108 } 1109 1110 template<uint32 MaxBufSize> 1111 typename OSCL_wStackString<MaxBufSize>::chartype* OSCL_wStackString<MaxBufSize>::get_str() const 1112 { 1113 return (chartype*)rep.buffer; 1114 } 1115 1116 // ************************************************************** 1117 template<uint32 MaxBufSize> 1118 void OSCL_StackString<MaxBufSize>::create() 1119 { 1120 rep.buffer = &buffer[0]; 1121 rep.maxsize = MaxBufSize; 1122 } 1123 1124 template<uint32 MaxBufSize> 1125 void OSCL_wStackString<MaxBufSize>::create() 1126 { 1127 rep.buffer = &buffer[0]; 1128 rep.maxsize = MaxBufSize; 1129 } 1130 1131 // ************************************************************** 1132 template<uint32 MaxBufSize> 1133 OSCL_StackString<MaxBufSize>::OSCL_StackString() 1134 { 1135 create(); 1136 set_rep(NULL); 1137 } 1138 1139 template<uint32 MaxBufSize> 1140 OSCL_wStackString<MaxBufSize>::OSCL_wStackString() 1141 { 1142 create(); 1143 set_rep(NULL); 1144 } 1145 1146 // ************************************************************** 1147 template<uint32 MaxBufSize> 1148 OSCL_StackString<MaxBufSize>::OSCL_StackString(const chartype* cp) 1149 { 1150 create(); 1151 set_rep(cp); 1152 } 1153 1154 template<uint32 MaxBufSize> 1155 OSCL_wStackString<MaxBufSize>::OSCL_wStackString(const chartype* cp) 1156 { 1157 create(); 1158 set_rep(cp); 1159 } 1160 1161 // ************************************************************** 1162 template<uint32 MaxBufSize> 1163 void OSCL_StackString<MaxBufSize>::set(const chartype* cp, uint32 length) 1164 { 1165 rep.set(cp, length); 1166 //just in case input string is shorter than 'length'; 1167 rep.size = oscl_strlen(get_cstr()); 1168 } 1169 1170 template<uint32 MaxBufSize> 1171 void OSCL_wStackString<MaxBufSize>::set(const chartype* cp, uint32 length) 1172 { 1173 rep.set(cp, length); 1174 //just in case input string is shorter than 'length'; 1175 rep.size = oscl_strlen(get_cstr()); 1176 } 1177 1178 // ************************************************************** 1179 template<uint32 MaxBufSize> 1180 OSCL_StackString<MaxBufSize>::OSCL_StackString(const chartype* cp, uint32 length) 1181 { 1182 create(); 1183 set(cp, length); 1184 } 1185 1186 template<uint32 MaxBufSize> 1187 OSCL_wStackString<MaxBufSize>::OSCL_wStackString(const chartype* cp, uint32 length) 1188 { 1189 create(); 1190 set(cp, length); 1191 } 1192 1193 // ************************************************************** 1194 template<uint32 MaxBufSize> 1195 OSCL_StackString<MaxBufSize>::OSCL_StackString(const OSCL_StackString<MaxBufSize>& src) : OSCL_String(src) 1196 { 1197 create(); 1198 set_rep(src); 1199 } 1200 1201 template<uint32 MaxBufSize> 1202 OSCL_wStackString<MaxBufSize>::OSCL_wStackString(const OSCL_wStackString<MaxBufSize>& src) 1203 { 1204 create(); 1205 set_rep(src); 1206 } 1207 1208 // ************************************************************** 1209 template<uint32 MaxBufSize> 1210 OSCL_StackString<MaxBufSize>::OSCL_StackString(const OSCL_String& src) 1211 { 1212 create(); 1213 set_rep(src); 1214 } 1215 1216 template<uint32 MaxBufSize> 1217 OSCL_wStackString<MaxBufSize>::OSCL_wStackString(const OSCL_wString& src) 1218 { 1219 create(); 1220 set_rep(src); 1221 } 1222 1223 // ************************************************************** 1224 template<uint32 MaxBufSize> 1225 OSCL_StackString<MaxBufSize>::~OSCL_StackString() 1226 {} 1227 1228 template<uint32 MaxBufSize> 1229 OSCL_wStackString<MaxBufSize>::~OSCL_wStackString() 1230 {} 1231 1232 // ************************************************************** 1233 template<uint32 MaxBufSize> 1234 OSCL_StackString<MaxBufSize>& OSCL_StackString<MaxBufSize>::operator=(const OSCL_StackString<MaxBufSize>& src) 1235 { 1236 set_rep(src); 1237 return (*this); 1238 } 1239 1240 template<uint32 MaxBufSize> 1241 OSCL_wStackString<MaxBufSize>& OSCL_wStackString<MaxBufSize>::operator=(const OSCL_wStackString<MaxBufSize>& src) 1242 { 1243 set_rep(src); 1244 return (*this); 1245 } 1246 1247 // ************************************************************** 1248 template<uint32 MaxBufSize> 1249 OSCL_StackString<MaxBufSize>& OSCL_StackString<MaxBufSize>::operator=(const OSCL_String & src) 1250 { 1251 set_rep(src); 1252 return (*this); 1253 } 1254 1255 template<uint32 MaxBufSize> 1256 OSCL_wStackString<MaxBufSize>& OSCL_wStackString<MaxBufSize>::operator=(const OSCL_wString & src) 1257 { 1258 set_rep(src); 1259 return (*this); 1260 } 1261 1262 // ************************************************************** 1263 template<uint32 MaxBufSize> 1264 OSCL_StackString<MaxBufSize>& OSCL_StackString<MaxBufSize>::operator=(const chartype * cp) 1265 { 1266 set_rep(cp); 1267 return (*this); 1268 } 1269 1270 template<uint32 MaxBufSize> 1271 OSCL_wStackString<MaxBufSize>& OSCL_wStackString<MaxBufSize>::operator=(const chartype * cp) 1272 { 1273 set_rep(cp); 1274 return (*this); 1275 } 1276 1277 #endif // OSCL_STRING_H_INCLUDED 1278 1279 /*! @} */ 1280