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