Couchbase C Client  2.4.4
_cxxwrap.h
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2014 Couchbase, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef LCB_CXXWRAP_H
19 #define LCB_CXXWRAP_H
20 
21 /* Note that the contents of this file are here only to provide inline
22  * definitions for backwards compatibility with older code. Users of the library
23  * should assume that structures do _not_ behave differently under C++ and must
24  * be explicitly initialized with their appropriate members.
25  */
26 
27 #ifdef __cplusplus
28 
29 #include <cstdlib>
30 #include <cstring>
31 
32 
33 #define LCB_DEPR_CTORS_GET \
34  lcb_get_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
35  lcb_get_cmd_st(const void *key, lcb_size_t nkey=0, lcb_time_t exptime=0, int lock=0) { \
36  version = 0; \
37  v.v0.key = key; \
38  if (key != NULL && nkey == 0) { \
39  v.v0.nkey = std::strlen((const char *)key); \
40  } else { \
41  v.v0.nkey = nkey; \
42  } \
43  v.v0.exptime = exptime; v.v0.lock = lock; v.v0.hashkey = NULL; v.v0.nhashkey = 0; \
44  }
45 
46 
47 #define LCB_DEPR_CTORS_RGET \
48  lcb_get_replica_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
49  lcb_get_replica_cmd_st(const void *key, lcb_size_t nkey, lcb_replica_t strategy=LCB_REPLICA_FIRST, int index=0) { \
50  version = 1; v.v1.key = key; v.v1.nkey = nkey; v.v1.hashkey = NULL; v.v1.nhashkey = 0; v.v1.strategy = strategy; v.v1.index = index; \
51  }
52 
53 #define LCB_DEPR_CTORS_UNL \
54  lcb_unlock_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
55  lcb_unlock_cmd_st(const void *key, lcb_size_t nkey, lcb_cas_t cas) { \
56  version = 0; v.v0.key = key; v.v0.nkey = nkey; v.v0.cas = cas; v.v0.hashkey = NULL; v.v0.nhashkey = 0; \
57  }
58 
59 #define LCB_DEPR_CTORS_STORE \
60  lcb_store_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
61  lcb_store_cmd_st(lcb_storage_t operation, const void *key, lcb_size_t nkey, \
62  const void *bytes=NULL, lcb_size_t nbytes=0, lcb_uint32_t flags=0, \
63  lcb_time_t exptime=0, lcb_cas_t cas=0, lcb_datatype_t datatype=0) { \
64  version = 0; v.v0.operation = operation; v.v0.key = key; v.v0.nkey = nkey; v.v0.cas = cas; \
65  v.v0.bytes = bytes; v.v0.nbytes = nbytes; v.v0.flags = flags; v.v0.datatype = datatype; \
66  v.v0.exptime = exptime; v.v0.hashkey = NULL; v.v0.nhashkey = 0; \
67  }
68 
69 #define LCB_DEPR_CTORS_ARITH \
70  lcb_arithmetic_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
71  lcb_arithmetic_cmd_st(const void *key, lcb_size_t nkey, lcb_int64_t delta, int create=0, \
72  lcb_uint64_t initial=0, lcb_time_t exptime=0) { \
73  version = 0; v.v0.key = key; v.v0.nkey = nkey; v.v0.exptime = exptime; \
74  v.v0.delta = delta; v.v0.create = create; v.v0.initial = initial; \
75  v.v0.hashkey = NULL; v.v0.nhashkey = 0; \
76  }
77 
78 
79 #define LCB_DEPR_CTORS_OBS \
80  lcb_observe_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
81  lcb_observe_cmd_st(const void *key, lcb_size_t nkey) { \
82  version = 0; v.v0.key = key; v.v0.nkey = nkey; v.v0.hashkey = NULL; v.v0.nhashkey = 0; \
83  }
84 
85 #define LCB_DEPR_CTORS_RM \
86  lcb_remove_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
87  lcb_remove_cmd_st(const void *key, lcb_size_t nkey=0, lcb_cas_t cas=0) { \
88  version = 0; v.v0.key = key; \
89  if (key != NULL && nkey == 0) { v.v0.nkey = std::strlen((const char *)key);}\
90  else { v.v0.nkey = nkey; } \
91  v.v0.cas = cas; v.v0.hashkey = NULL; v.v0.nhashkey = 0; \
92  }
93 
94 #define LCB_DEPR_CTORS_STATS \
95  lcb_server_stats_cmd_st(const char *name=NULL, lcb_size_t nname=0) { \
96  version = 0; v.v0.name = name; v.v0.nname = nname; \
97  if (name != NULL && nname == 0) { v.v0.nname = std::strlen(name); } \
98  else { v.v0.nname = nname; } \
99  }
100 
101 #define LCB_DEPR_CTORS_VERBOSITY \
102  lcb_verbosity_cmd_st(lcb_verbosity_level_t level=LCB_VERBOSITY_WARNING, const char *server=NULL) { \
103  version = 0; v.v0.server = server; v.v0.level = level; \
104  }
105 
106 #define LCB_DEPR_CTORS_VERSIONS \
107  lcb_server_version_cmd_st() { std::memset(this, 0, sizeof(*this)); }
108 
109 #define LCB_DEPR_CTORS_FLUSH \
110  lcb_flush_cmd_st() { std::memset(this, 0, sizeof(*this)); }
111 
112 #define LCB_DEPR_CTORS_CRST \
113  lcb_create_st(const char *host=NULL, const char *user=NULL,\
114  const char *passwd=NULL, const char *bucket=NULL, \
115  struct lcb_io_opt_st *io=NULL, lcb_type_t type=LCB_TYPE_BUCKET) { \
116  version = 2; v.v2.host = host; v.v2.user = user; v.v2.passwd = passwd; \
117  v.v2.bucket = bucket; v.v2.io = io; v.v2.type = type; v.v2.mchosts = NULL; \
118  v.v2.transports = NULL; \
119  }
120 
121 #define LCB_DEPR_CTORS_HTTP \
122  lcb_http_cmd_st() { std::memset(this, 0, sizeof(*this)); } \
123  lcb_http_cmd_st(const char *path, lcb_size_t npath, const void *body, \
124  lcb_size_t nbody, lcb_http_method_t method, \
125  int chunked, const char *content_type) { \
126  version = 0; v.v0.path = path; v.v0.npath = npath; v.v0.body = body; \
127  v.v0.nbody = nbody; v.v0.method = method; v.v0.chunked = chunked; \
128  v.v0.content_type = content_type; \
129  }
130 #else
131 /* Not C++ */
132 #define LCB_DEPR_CTORS_GET
133 #define LCB_DEPR_CTORS_RGET
134 #define LCB_DEPR_CTORS_UNL
135 #define LCB_DEPR_CTORS_STORE
136 #define LCB_DEPR_CTORS_ARITH
137 #define LCB_DEPR_CTORS_OBS
138 #define LCB_DEPR_CTORS_RM
139 #define LCB_DEPR_CTORS_STATS
140 #define LCB_DEPR_CTORS_VERBOSITY
141 #define LCB_DEPR_CTORS_VERSIONS
142 #define LCB_DEPR_CTORS_FLUSH
143 #define LCB_DEPR_CTORS_HTTP
144 #define LCB_DEPR_CTORS_CRST
145 #endif
146 #endif /* LCB_CXXWRAP_H */