this repo has no description
1#ifndef XTRACE_STRING
2#define XTRACE_STRING
3
4#include "base.h"
5#include "memory.h"
6
7#include <stdio.h>
8
9
10XTRACE_DECLARATIONS_C_BEGIN
11
12typedef struct xtrace_string{
13 void* _unused;
14} *xtrace_string_t;
15
16xtrace_string_t xtrace_string_construct();
17void xtrace_string_destruct(xtrace_string_t obj);
18
19void xtrace_string_append_c_string(xtrace_string_t obj, const char* other);
20void xtrace_string_append_xtrace_string(xtrace_string_t obj, xtrace_string_t other);
21void xtrace_string_append_format_valist(xtrace_string_t obj, const char* format, va_list args);
22
23__attribute__((format(printf, 2, 3)))
24void xtrace_string_append_format(xtrace_string_t obj, const char* format, ...);
25
26void xtrace_string_clear(xtrace_string_t obj);
27
28const char* xtrace_string_c_str(xtrace_string_t obj);
29size_t xtrace_string_size(xtrace_string_t obj);
30size_t xtrace_string_capacity(xtrace_string_t obj);
31
32XTRACE_DECLARATIONS_C_END
33
34
35#ifdef XTRACE_CPP
36#include <string>
37
38namespace xtrace {
39 class String {
40 private:
41 char* buffer;
42 size_t buffer_size;
43 size_t buffer_capacity;
44
45 public:
46 // Static methods
47 static String* new_ptr();
48 static void free_ptr(String* obj);
49 static String* to_cxx_ptr(xtrace_string_t obj);
50 static xtrace_string_t to_c_ptr(String* obj);
51
52 // Constructor and destructor
53 String();
54 String(const char* other_buffer);
55 String(const String* other_obj);
56 ~String();
57
58 // Methods
59 void clear();
60 void append(const char* other);
61 void append(const String* other);
62 void append_format(const char* format, va_list args);
63
64 __attribute__((format(printf, 2, 3)))
65 void append_format(const char* format, ...);
66
67 // Getters
68 const char* c_str() const;
69 size_t size();
70 size_t capacity();
71
72 private:
73 // Methods
74 void constructor_internal();
75 void destructor_internal();
76 size_t increase_capacity_internal(size_t other_buffer_size);
77 };
78}
79#endif
80
81#endif // XTRACE_STRING