Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

class_debug_string.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_CLASS_DEBUG_STRING_H
19 #define LIBCWD_CLASS_DEBUG_STRING_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include "config.h"
23 #endif
24 #ifndef LIBCW_CSTDDEF
25 #define LIBCW_CSTDDEF
26 #include <cstddef> // Needed for size_t
27 #endif
28 #ifndef LIBCW_STRING
29 #define LIBCW_STRING
30 #include <string>
31 #endif
32 
33 namespace libcwd {
34 
35 // String class for debug_ct::margin and debug_ct::marker.
36 // This class can not have a constructor.
37 
38 struct debug_string_stack_element_ct;
39 struct debug_tsd_st;
40 class debug_ct;
41 
49  friend class debug_ct; // Needs access to the private functions.
50  friend struct debug_tsd_st;
51 private:
52  char* M_str; // Pointer to malloc-ed (zero terminated) string.
53  size_t M_size; // Size of string (exclusive terminating zero).
54  size_t M_capacity; // Size of allocated area (excl. terminating zero).
55  size_t M_default_capacity; // Current minimum capacity as set with `reserve'.
56  static size_t const min_capacity_c = 64; // Minimum capacity.
57 
58  size_t calculate_capacity(size_t);
59  void internal_assign(char const* s, size_t l);
60  void internal_append(char const* s, size_t l);
61  void internal_prepend(char const* s, size_t l);
62  void internal_swallow(debug_string_ct const&);
63 
64 private:
65  void NS_internal_init(char const* s, size_t l);
66  void deinitialize();
67  debug_string_ct() { }
68  ~debug_string_ct();
69 
70 private:
71  friend struct debug_string_stack_element_ct;
73 
74 public:
75  size_t size() const;
76  size_t capacity() const;
77  void reserve(size_t);
78  char const* c_str() const;
79  void assign(char const* str, size_t len);
80  void append(char const* str, size_t len);
81  void prepend(char const* str, size_t len);
82  void assign(std::string const& str);
83  void append(std::string const& str);
84  void prepend(std::string const& str);
85 };
86 
87 // Used for the margin and marker stacks.
88 struct debug_string_stack_element_ct {
89 public:
90  debug_string_stack_element_ct* next;
91  debug_string_ct debug_string;
92  debug_string_stack_element_ct(debug_string_ct const& ds);
93 };
94 
95 } // namespace libcwd
96 
97 #endif // LIBCWD_CLASS_DEBUG_STRING_H
The Debug Object class, this object represents one output device (ostream).
Definition: class_debug.h:77
A string class used for the debug output margin and marker.
Definition: class_debug_string.h:48
size_t size() const
The size of the string.
Definition: class_debug_string.inl:89
void reserve(size_t)
Reserve memory for the string in advance.
Definition: debug.cc:905
void prepend(char const *str, size_t len)
Prepend str with size len to the string.
Definition: class_debug_string.inl:76
void assign(char const *str, size_t len)
Assign str with size len to the string.
Definition: class_debug_string.inl:50
char const * c_str() const
A zero terminated char const pointer.
Definition: class_debug_string.inl:109
void append(char const *str, size_t len)
Append str with size len to the string.
Definition: class_debug_string.inl:63
size_t capacity() const
The capacity of the string.
Definition: class_debug_string.inl:99
namespace for libcwd.
Definition: debug.cc:87
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.