MCPcopy Create free account
hub / github.com/apache/trafficserver / ats_scoped_str

Class ats_scoped_str

include/tscore/ink_memory.h:493–548  ·  view source on GitHub ↗

Specialization of @c ats_scoped_resource for strings. This contains an allocated string that is cleaned up if not explicitly released. */

Source from the content-addressed store, hash-verified

491 This contains an allocated string that is cleaned up if not explicitly released.
492*/
493class ats_scoped_str : public ats_scoped_resource<detail::SCOPED_MALLOC_TRAITS<char>>
494{
495public:
496 using super = ats_scoped_resource<detail::SCOPED_MALLOC_TRAITS<char>>; ///< Super type.
497 using self_type = ats_scoped_str; ///< Self reference type.
498
499 /** Default constructor.
500 * Constructs an empty container.
501 */
502 ats_scoped_str() = default;
503
504 /** Construct an empty buffer of @a n bytes.
505 *
506 * @param n Size of the contained buffer.
507 *
508 * The memory is left uninitialized, presumably ready for a @c memcpy.
509 */
510 explicit ats_scoped_str(size_t n) : super(static_cast<char *>(ats_malloc(n))) {}
511
512 /** Construct with an existing buffer.
513 *
514 * @param s The string.
515 *
516 * This container takes ownership of the string memory. For this reason @a s must be independently
517 * allocated, not part of a larger memory allocation.
518 */
519 explicit ats_scoped_str(char *s) : super(s) {}
520
521 /** Construct from a @c string_view.
522 *
523 * @param s The string to copy.
524 *
525 * The string in @a s is duplicated into this container.
526 */
527 explicit ats_scoped_str(std::string_view s);
528
529 /** Put an existing buffer in this container.
530 *
531 * @param s The string buffer.
532 * @return @a this
533 *
534 * The container takes ownership of @a s. For this reason @a s must be independently allocated,
535 * not part of a larger memory allocation. Any currently contained resource is destroyed.
536 */
537 self_type &operator=(char *s);
538
539 /** Assign from a @c string_view
540 *
541 * @param s The source string.
542 * @return @a this
543 *
544 * The string data is duplicated into this object and guaranteed to be null terminated. Any currently
545 * contained resource is destroyed.
546 */
547 self_type &operator=(std::string_view s);
548};
549
550inline ats_scoped_str::ats_scoped_str(std::string_view s)

Callers 1

IpAllowMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected