libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
DebugString.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2000-2004, 2018, 2020, 2023, 2026 Carlo Wood
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
9
10#ifndef LIBCWD_CLASS_DEBUG_STRING_H
11#define LIBCWD_CLASS_DEBUG_STRING_H
12
13#include "libcwd/config.h"
14
15#include <cstddef> // Needed for size_t
16#include <string>
17
18namespace libcwd {
19
20// String class for DebugObject::margin and DebugObject::marker.
21// This class can not have a constructor.
22
23struct DebugStringStackElement;
24struct DebugObject_ThreadSpecificData;
25class DebugObject;
26
33class DebugString
34{
35 friend class DebugObject; // Needs access to the private functions.
36 friend struct DebugObject_ThreadSpecificData;
37
38 private:
39 char* str_; // Pointer to malloc-ed (zero terminated) string.
40 size_t size_; // Size of string (exclusive terminating zero).
41 size_t capacity_; // Size of allocated area (excl. terminating zero).
42 size_t default_capacity_; // Current minimum capacity as set with `reserve'.
43 static constexpr size_t min_capacity = 64; // Minimum capacity.
44
45 size_t calculate_capacity(size_t);
46 void internal_assign(char const* s, size_t l);
47 void internal_append(char const* s, size_t l);
48 void internal_prepend(char const* s, size_t l);
49 void internal_swallow(DebugString const&);
50
51 private:
52 void NS_internal_init(char const* s, size_t l);
53 void deinitialize();
54 DebugString() { }
55 ~DebugString();
56
57 private:
58 friend struct DebugStringStackElement;
59 DebugString(DebugString const& ds);
60
61 public:
62 size_t size() const;
63 size_t capacity() const;
64 void reserve(size_t);
65 char const* c_str() const;
66 void assign(char const* str, size_t len);
67 void append(char const* str, size_t len);
68 void prepend(char const* str, size_t len);
69 void assign(std::string const& str);
70 void append(std::string const& str);
71 void prepend(std::string const& str);
72};
73
74// Used for the margin and marker stacks.
75struct DebugStringStackElement
76{
77 public:
78 DebugStringStackElement* next;
79 DebugString debug_string;
80 DebugStringStackElement(DebugString const& ds);
81};
82
83} // namespace libcwd
84
85#endif // LIBCWD_CLASS_DEBUG_STRING_H
The Debug Object class, this object represents one output device (ostream).
Definition DebugObject.h:110
A string class used for the debug output margin and marker.
Definition DebugString.h:34
void append(char const *str, size_t len)
Append str with size len to the string.
Definition DebugString.inl.h:37
void assign(char const *str, size_t len)
Assign str with size len to the string.
Definition DebugString.inl.h:29
void prepend(char const *str, size_t len)
Prepend str with size len to the string.
Definition DebugString.inl.h:45
size_t size() const
The size of the string.
Definition DebugString.inl.h:53
size_t capacity() const
The capacity of the string.
Definition DebugString.inl.h:61
char const * c_str() const
A zero terminated char const pointer.
Definition DebugString.inl.h:69
void reserve(size_t)
Reserve memory for the string in advance.
Definition debug.cxx:777
namespace for libcwd.