53 template<
typename Allocator = MemoryAllocator<u
int8_t> >
57 Buffer(
size_t initial_size = 64);
111 inline const char*
c_str();
122 inline uint8_t*
data();
123 inline const uint8_t*
data()
const;
126 inline size_t size();
142 inline void rewind(
size_t bytes_to_drop);
184 template<
typename Allocator>
187 _start = _alloc.allocate(initial_size);
188 _end = _start + initial_size;
192 template<
typename Allocator>
195 _alloc.deallocate(_start, _end - _start);
196 _start = _end = _pos = 0;
206 template<
typename Allocator>
219 template<
typename Allocator>
232 template<
typename Allocator>
235 return write(cs, strlen(cs));
245 template<
typename Allocator>
250 memcpy(_pos, cs,
sizeof(
char) * sz);
264 template<
typename Allocator>
279 template<
typename Allocator>
296 template<
typename Allocator>
298 size_t sz = std::strlen(cs);
302 const char* src = cs;
303 const char* end = cs + sz;
305 for ( ; src != end; ++_pos, ++src ) {
308 *_pos = (c ==
'/') ?
'.' : c;
314 template<
typename Allocator>
316 ensure_capacity(u.
size());
318 const char* src = u.
begin();
319 const char* end = u.
end();
321 for ( ; src != end; ++_pos, ++src ) {
324 *_pos = (c ==
'/') ?
'.' : c;
337 template<
typename Allocator>
339 ensure_capacity(u.
size());
341 const char* src = u.
begin();
342 const char* end = u.
end();
344 for ( ; src != end; ++_pos, ++src ) {
347 *_pos = (c ==
'.') ?
'/' : c;
360 template<
typename Allocator>
362 return writef(
"0x%" PRIxPTR, (uintptr_t) ptr);
365 template<
typename Allocator>
367 return writef(
"%d", n);
370 template<
typename Allocator>
372 return writef(
"0x%" PRId64, n);
375 template<
typename Allocator>
377 return writef(
"%g", n);
380 template<
typename Allocator>
382 return writef(
"%g", n);
385 template<
typename Allocator>
387 return writef(
"%08x", n);
390 template<
typename Allocator>
392 return writef(
"0x%" PRIx64, n);
395 template<
typename Allocator>
404 return write_hex(u.i);
407 template<
typename Allocator>
416 return write_hex(u.l);
425 template<
typename Allocator>
437 template<
typename Allocator>
443 size_t size = _end - _pos;
444 size_t written = vsnprintf((
char*) _pos, size, fmt, ap);
446 if (written > size) {
448 ensure_capacity(written + 1);
451 written = vsnprintf((
char*) _pos, size, fmt, ap2);
452 assert(written <= size);
469 template<
typename Allocator>
488 template<
typename Allocator>
493 return (
const char*) _start;
505 template<
typename Allocator>
522 template<
typename Allocator>
528 template<
typename Allocator>
540 template<
typename Allocator>
543 return _pos - _start;
552 template<
typename Allocator>
573 template<
typename Allocator>
576 _pos -= bytes_to_drop;
590 template<
typename Allocator>
593 size_t free_space = _end - _pos;
595 if (free_space < write_size) {
597 size_t old_size = _pos - _start;
598 size_t old_capacity = _end - _start;
600 size_t new_capacity =
MAX(old_capacity, write_size) * 2 + 1;
601 assert(new_capacity > (old_capacity + write_size));
604 _start = _alloc.reallocate(_start, old_capacity, new_capacity);
605 _end = _start + new_capacity;
606 _pos = _start + old_size;
611 #endif // CACAO_BUFFER_HPP_
Utf8String utf8_str()
get utf-8 string contents of buffer as utf8-string
Buffer & zero_terminate()
ensure string in buffer is zero terminated
Buffer(size_t initial_size=64)
Buffer & write_ptr(void *)
write address of pointer as hex to buffer
byte_iterator end() const
void skip(size_t num_bytes)
advance buffer position by n bytes O(1)
void reset()
Reset buffer position to start of buffer.
void ensure_capacity(size_t sz)
ensure buffer contains space for at least sz bytes
const char * c_str()
get contents of buffer as zero-terminated c-style-string This strings lifetime is tied to it's buffer...
Buffer & write_hex(s4)
write number to buffer as hexadecimal
JNIEnv jthread jobject jclass jlong size
Buffer & write_slash_to_dot(const char *)
write to buffer, replacing '/' by '.'
Buffer & write_dot_to_slash(Utf8String)
write to buffer, replacing '.' by '/'
static Utf8String from_utf8(const char *, size_t)
uint8_t * data()
get raw contents of buffer (not necessarily zero terminated).
const char * c_str_copy()
get copy contents of buffer as zero-terminated c-style-string You must free the returned string yours...
byte_iterator begin() const
Fn::ReturnType transform(Iterator begin, Iterator end, Fn)
Buffer & writevf(const char *fmt, va_list ap)
void rewind(size_t bytes_to_drop)
remove data from the back of this buffer.
Buffer & operator=(const Buffer &)
non-assignable
Buffer & write_dec(s4)
write number to buffer as decimal
Buffer & writef(const char *fmt,...)
size_t size()
get size of buffer contents
Buffer & write(Buffer< A > &src)
copy contents of buffer (calls c_str() on src)
size_t num_bytes(const uint16_t *, size_t)