Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_tempbuffer.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_TEMP_BUFFER_H
7 #define TB_TEMP_BUFFER_H
8 
9 #include "tb_str.h"
10 
11 namespace tb {
12 
19 {
20 public:
21  TBTempBuffer();
22  ~TBTempBuffer();
23 
26  bool Reserve(int size);
27 
29  char *GetData() const { return m_data; }
30 
32  int GetCapacity() const { return m_data_size; }
33 
37  bool Append(const char *data, int size);
38 
43  bool AppendSpace(int size);
44 
50  bool AppendString(const char *str);
51 
53  bool AppendString(const TBStr & str) { return AppendString((const char *)str); }
54 
58  bool AppendPath(const char *full_path_and_filename);
59 
65  bool AppendFile(const TBStr & filename);
66 
68  void SetAppendPos(int append_pos);
69 
71  void ResetAppendPos() { m_append_pos = 0; }
72 
74  int GetAppendPos() const { return m_append_pos; }
75 private:
76  int GetAppendReserveSize(int needed_size) const;
77  char *m_data;
78  int m_data_size;
79  int m_append_pos;
80 };
81 
82 } // namespace tb
83 
84 #endif // TB_TEMP_BUFFER_H
bool AppendFile(const TBStr &filename)
Append file content at the end of the buffer.
Definition: tb_tempbuffer.cpp:114
int GetAppendPos() const
Return the current append position in in bytes.
Definition: tb_tempbuffer.h:74
bool Reserve(int size)
Make sure the buffer has at least size bytes.
Definition: tb_tempbuffer.cpp:38
char * GetData() const
Get a pointer to the buffer data.
Definition: tb_tempbuffer.h:29
bool AppendString(const TBStr &str)
Append a TBStr.
Definition: tb_tempbuffer.h:53
void SetAppendPos(int append_pos)
Set the position (in bytes) in the buffer where Append should write.
Definition: tb_tempbuffer.cpp:32
bool AppendString(const char *str)
Append a null terminated string (including the null termination) at the end of the buffer...
Definition: tb_tempbuffer.cpp:75
int GetCapacity() const
Return the size of the buffer in bytes.
Definition: tb_tempbuffer.h:32
bool AppendPath(const char *full_path_and_filename)
Append a path without the ending filename.
Definition: tb_tempbuffer.cpp:89
TBStr is a simple string class.
Definition: tb_str.h:62
bool Append(const char *data, int size)
Append data with size bytes at the end of the buffer and increase the append position with the same a...
Definition: tb_tempbuffer.cpp:58
bool AppendSpace(int size)
Increase the append position with size bytes without writing any data.
Definition: tb_tempbuffer.cpp:67
void ResetAppendPos()
Reset the append position to 0.
Definition: tb_tempbuffer.h:71
TBTempBuffer manages a buffer that will be deleted on destruction.
Definition: tb_tempbuffer.h:18