Updating tree for new function work in libhashkit.
[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 #ifndef __MEMCACHED_STRING_H__
13 #define __MEMCACHED_STRING_H__
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /**
20 Strings are always under our control so we make some assumptions
21 about them.
22
23 1) is_initialized is always valid.
24 2) A string once intialized will always be, until free where we
25 unset this flag.
26 3) A string always has a root.
27 */
28
29 struct memcached_string_st {
30 char *end;
31 char *string;
32 size_t current_size;
33 const memcached_st *root;
34 struct {
35 bool is_allocated:1;
36 bool is_initialized:1;
37 } options;
38 };
39
40 static inline size_t memcached_string_length(const memcached_string_st *self)
41 {
42 return (size_t)(self->end - self->string);
43 }
44
45 static inline size_t memcached_string_size(const memcached_string_st *self)
46 {
47 return self->current_size;
48 }
49
50 static inline const char *memcached_string_value(const memcached_string_st *self)
51 {
52 return self->string;
53 }
54
55 static inline char *memcached_string_value_mutable(const memcached_string_st *self)
56 {
57 return self->string;
58 }
59
60 #define memcached_string_set_length(A, B) (A)->end= (A)->string + B
61
62 LIBMEMCACHED_LOCAL
63 memcached_string_st *memcached_string_create(const memcached_st *ptr,
64 memcached_string_st *string,
65 size_t initial_size);
66 LIBMEMCACHED_LOCAL
67 memcached_return_t memcached_string_check(memcached_string_st *string, size_t need);
68
69 LIBMEMCACHED_LOCAL
70 char *memcached_string_c_copy(memcached_string_st *string);
71
72 LIBMEMCACHED_LOCAL
73 memcached_return_t memcached_string_append_character(memcached_string_st *string,
74 char character);
75 LIBMEMCACHED_LOCAL
76 memcached_return_t memcached_string_append(memcached_string_st *string,
77 const char *value, size_t length);
78 LIBMEMCACHED_LOCAL
79 memcached_return_t memcached_string_reset(memcached_string_st *string);
80
81 LIBMEMCACHED_LOCAL
82 void memcached_string_free(memcached_string_st *string);
83
84 #ifdef __cplusplus
85 }
86 #endif
87
88 #endif /* __MEMCACHED_STRING_H__ */