f6a13bb000f7b695fad5ed3d9beda7585bb6712b
[m6w6/libmemcached] / libmemcached / string.h
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: String structure used for libmemcached.
9 *
10 */
11
12 #pragma once
13 #ifndef __LIBMEMCACHED_STRING_H__
14 #define __LIBMEMCACHED_STRING_H__
15
16 /**
17 Strings are always under our control so we make some assumptions
18 about them.
19
20 1) is_initialized is always valid.
21 2) A string once intialized will always be, until free where we
22 unset this flag.
23 3) A string always has a root.
24 */
25
26 struct memcached_string_st {
27 char *end;
28 char *string;
29 size_t current_size;
30 const memcached_st *root;
31 struct {
32 bool is_allocated:1;
33 bool is_initialized:1;
34 } options;
35 };
36
37 struct memcached_string_t {
38 size_t size;
39 const char *c_str;
40 };
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 LIBMEMCACHED_LOCAL
47 memcached_string_st *memcached_string_create(const memcached_st *ptr,
48 memcached_string_st *string,
49 size_t initial_size);
50 LIBMEMCACHED_LOCAL
51 memcached_return_t memcached_string_check(memcached_string_st *string, size_t need);
52
53 LIBMEMCACHED_LOCAL
54 char *memcached_string_c_copy(memcached_string_st *string);
55
56 LIBMEMCACHED_LOCAL
57 memcached_return_t memcached_string_append_character(memcached_string_st *string,
58 char character);
59 LIBMEMCACHED_LOCAL
60 memcached_return_t memcached_string_append(memcached_string_st *string,
61 const char *value, size_t length);
62 LIBMEMCACHED_LOCAL
63 memcached_return_t memcached_string_reset(memcached_string_st *string);
64
65 LIBMEMCACHED_LOCAL
66 void memcached_string_free(memcached_string_st *string);
67
68 LIBMEMCACHED_LOCAL
69 size_t memcached_string_length(const memcached_string_st *self);
70
71 LIBMEMCACHED_LOCAL
72 size_t memcached_string_size(const memcached_string_st *self);
73
74 LIBMEMCACHED_LOCAL
75 const char *memcached_string_value(const memcached_string_st *self);
76
77 LIBMEMCACHED_LOCAL
78 char *memcached_string_value_mutable(const memcached_string_st *self);
79
80 LIBMEMCACHED_LOCAL
81 void memcached_string_set_length(memcached_string_st *self, size_t length);
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87
88 #ifdef __cplusplus
89 #define memcached_string_with_size(X) (X), (static_cast<size_t>((sizeof(X) - 1)))
90 #else
91 #define memcached_string_with_size(X) (X), ((size_t)((sizeof(X) - 1)))
92 #endif
93
94 #endif /* __LIBMEMCACHED_STRING_H__ */