libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

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

# libcwd/class_debug_string.h

Go to the documentation of this file.

    00001 // $Header$
    00002 //
    00003 // Copyright (C) 2000 - 2004, by
    00004 //
    00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
    00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
    00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
    00008 //
    00009 // This file may be distributed under the terms of the Q Public License
    00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
    00011 // packaging of this file.
    00012 //
    00013
    00018 #ifndef LIBCWD_CLASS_DEBUG_STRING_H
    00019 #define LIBCWD_CLASS_DEBUG_STRING_H
    00020
    00021 #ifndef LIBCWD_CONFIG_H
    00022 #include <libcwd/config.h>
    00023 #endif
    00024 #ifndef LIBCW_CSTDDEF
    00025 #define LIBCW_CSTDDEF
    00026 #include <cstddef>              // Needed for size_t
    00027 #endif
    00028 #ifndef LIBCW_STRING
    00029 #define LIBCW_STRING
    00030 #include <string>
    00031 #endif
    00032
    00033 namespace libcwd {
    00034
    00035 // String class for debug_ct::margin and debug_ct::marker.
    00036 // This class can not have a constructor.
    00037
    00038 struct debug_string_stack_element_ct;
    00039 struct debug_tsd_st;
    00040 class debug_ct;
    00041
    00048 class debug_string_ct {
    00049   friend class debug_ct;                        // Needs access to the private functions.
    00050   friend struct debug_tsd_st;
    00051 private:
    00052   char* M_str;                                  // Pointer to malloc-ed (zero terminated) string.
    00053   size_t M_size;                                // Size of string (exclusive terminating zero).
    00054   size_t M_capacity;                            // Size of allocated area (excl. terminating zero).
    00055   size_t M_default_capacity;                    // Current minimum capacity as set with `reserve'.
    00056   static size_t const min_capacity_c = 64;      // Minimum capacity.
    00057
    00058   size_t calculate_capacity(size_t);
    00059   void internal_assign(char const* s, size_t l);
    00060   void internal_append(char const* s, size_t l);
    00061   void internal_prepend(char const* s, size_t l);
    00062   void internal_swallow(debug_string_ct const&);
    00063
    00064 private:
    00065   void NS_internal_init(char const* s, size_t l);
    00066   void deinitialize(void);
    00067   debug_string_ct(void) { }
    00068   ~debug_string_ct(void);
    00069
    00070 private:
    00071   friend struct debug_string_stack_element_ct;
    00072   debug_string_ct(debug_string_ct const& ds);
    00073
    00074 public:
    00075   size_t size(void) const;
    00076   size_t capacity(void) const;
    00077   void reserve(size_t);
    00078   char const* c_str(void) const;
    00079   void assign(char const* str, size_t len);
    00080   void append(char const* str, size_t len);
    00081   void prepend(char const* str, size_t len);
    00082   void assign(std::string const& str);
    00083   void append(std::string const& str);
    00084   void prepend(std::string const& str);
    00085 };
    00086
    00087 // Used for the margin and marker stacks.
    00088 struct debug_string_stack_element_ct {
    00089 public:
    00090   debug_string_stack_element_ct* next;
    00091   debug_string_ct debug_string;
    00092   debug_string_stack_element_ct(debug_string_ct const& ds);
    00093 };
    00094
    00095 }  // namespace libcwd
    00096
    00097 #endif // LIBCWD_CLASS_DEBUG_STRING_H