projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Updated the C++ interface to return values as std::vector<char> instead of
[awesomized/libmemcached]
/
libmemcached
/
memcached.hh
diff --git
a/libmemcached/memcached.hh
b/libmemcached/memcached.hh
index 689a3bce068f21ff8421a33f264836d2f75f7b6f..fa535c0c0e266768d134d89dfd887889d35338dd 100644
(file)
--- a/
libmemcached/memcached.hh
+++ b/
libmemcached/memcached.hh
@@
-1,5
+1,18
@@
+/*
+ * Summary: C++ interface for memcached server
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Authors: Padraig O'Sullivan, Patrick Galbraith
+ */
+
+#ifndef LIBMEMCACHEDPP_H
+#define LIBMEMCACHEDPP_H
+
#include <libmemcached/memcached.h>
#include <libmemcached/memcached.h>
+#include <string.h>
+
#include <string>
#include <vector>
#include <string>
#include <vector>
@@
-29,77
+42,81
@@
public:
}
bool fetch(std::string &key,
}
bool fetch(std::string &key,
- std::string &ret_val,
- size_t *key_length,
- size_t *value_length,
+ std::vector<char> &ret_val,
uint32_t *flags,
memcached_return *rc)
{
char ret_key[MEMCACHED_MAX_KEY];
uint32_t *flags,
memcached_return *rc)
{
char ret_key[MEMCACHED_MAX_KEY];
- char *value= memcached_fetch(&memc, ret_key, key_length,
- value_length, flags, rc);
+ size_t value_length= 0;
+ size_t key_length= 0;
+ char *value= memcached_fetch(&memc, ret_key, &key_length,
+ &value_length, flags, rc);
if (value)
{
if (value)
{
- ret_val.assign(value);
+ ret_val.reserve(value_length);
+ memcpy(&*ret_val.begin(), value, value_length);
key.assign(ret_key);
return true;
}
return false;
}
key.assign(ret_key);
return true;
}
return false;
}
- std::string get(const std::string &key, size_t *value_length)
+ std::vector<char> &get(const std::string &key,
+ std::vector<char> &ret_val)
{
{
- uint32_t flags;
+ uint32_t flags
= 0
;
memcached_return rc;
memcached_return rc;
- s
td::string ret_val
;
+ s
ize_t value_length= 0
;
char *value= memcached_get(&memc, key.c_str(), key.length(),
char *value= memcached_get(&memc, key.c_str(), key.length(),
- value_length, &flags, &rc);
- if (value)
+
&
value_length, &flags, &rc);
+ if (value
!= NULL
)
{
{
- ret_val.assign(value);
+ ret_val.reserve(value_length);
+ memcpy(&ret_val[0], value, value_length);
}
return ret_val;
}
}
return ret_val;
}
- std::
string get_by_k
ey(const std::string &master_key,
- const std::string &key,
-
size_t *value_length
)
+ std::
vector<char> &getByK
ey(const std::string &master_key,
+
const std::string &key,
+
std::vector<char> &ret_val
)
{
{
- uint32_t flags;
+ uint32_t flags
= 0
;
memcached_return rc;
memcached_return rc;
- s
td::string ret_val
;
+ s
ize_t value_length= 0
;
- char *value= memcached_get_by_key(&memc, master_key.c_str(), master_key.length(),
+ char *value= memcached_get_by_key(&memc,
+ master_key.c_str(), master_key.length(),
key.c_str(), key.length(),
key.c_str(), key.length(),
- value_length, &flags, &rc);
+
&
value_length, &flags, &rc);
if (value)
{
if (value)
{
- ret_val.assign(value);
+ ret_val.reserve(value_length);
+ memcpy(&*ret_val.begin(), value, value_length);
}
return ret_val;
}
bool mget(std::vector<std::string> &keys)
{
}
return ret_val;
}
bool mget(std::vector<std::string> &keys)
{
+ std::vector<const char *> real_keys;
+ std::vector<size_t> key_len;
/*
* Construct an array which will contain the length
* of each of the strings in the input vector. Also, to
* interface with the memcached C API, we need to convert
* the vector of std::string's to a vector of char *.
*/
/*
* Construct an array which will contain the length
* of each of the strings in the input vector. Also, to
* interface with the memcached C API, we need to convert
* the vector of std::string's to a vector of char *.
*/
- size_t *key_len= static_cast<size_t *>(malloc(keys.size() * sizeof(size_t)));
- if (key_len == NULL)
- {
- return false;
- }
- std::vector<char *> real_keys;
+ real_keys.reserve(keys.size());
+ key_len.reserve(keys.size());
+
std::vector<std::string>::iterator it= keys.begin();
std::vector<std::string>::iterator it= keys.begin();
- int i= 0;
+
while (it != keys.end())
{
real_keys.push_back(const_cast<char *>((*it).c_str()));
while (it != keys.end())
{
real_keys.push_back(const_cast<char *>((*it).c_str()));
- key_len
[i++]= (*it).length(
);
+ key_len
.push_back((*it).length()
);
++it;
}
++it;
}
@@
-109,8
+126,8
@@
public:
*/
if (!real_keys.empty())
{
*/
if (!real_keys.empty())
{
- memcached_return rc= memcached_mget(&memc, &real_keys[0],
key_len
,
-
static_cast<unsigned int>(real_keys.size()
));
+ memcached_return rc= memcached_mget(&memc, &real_keys[0],
&key_len[0]
,
+
real_keys.size(
));
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
@@
-118,21
+135,21
@@
public:
}
bool set(const std::string &key,
}
bool set(const std::string &key,
- const std::
string
&value,
+ const std::
vector<char>
&value,
time_t expiration,
uint32_t flags)
{
memcached_return rc= memcached_set(&memc,
key.c_str(), key.length(),
time_t expiration,
uint32_t flags)
{
memcached_return rc= memcached_set(&memc,
key.c_str(), key.length(),
-
value.c_str(), value.length
(),
+
&value[0], value.size
(),
expiration, flags);
return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
}
expiration, flags);
return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
}
- bool set
_a
ll(std::vector<std::string> &keys,
-
std::vector<std::string
> &values,
-
time_t expiration,
-
uint32_t flags)
+ bool set
A
ll(std::vector<std::string> &keys,
+
std::vector< std::vector<char>
> &values,
+ time_t expiration,
+ uint32_t flags)
{
if (keys.size() != values.size())
{
{
if (keys.size() != values.size())
{
@@
-140,7
+157,7
@@
public:
}
bool retval= true;
std::vector<std::string>::iterator key_it= keys.begin();
}
bool retval= true;
std::vector<std::string>::iterator key_it= keys.begin();
- std::vector<
std::string
>::iterator val_it= values.begin();
+ std::vector<
std::vector<char>
>::iterator val_it= values.begin();
while (key_it != keys.end())
{
retval= set((*key_it), (*val_it), expiration, flags);
while (key_it != keys.end())
{
retval= set((*key_it), (*val_it), expiration, flags);
@@
-154,16
+171,16
@@
public:
return retval;
}
return retval;
}
- bool set
_by_k
ey(const std::string &master_key,
-
const std::string &key,
-
const std::string
&value,
-
time_t expiration,
-
uint32_t flags)
+ bool set
ByK
ey(const std::string &master_key,
+ const std::string &key,
+
const std::vector<char>
&value,
+ time_t expiration,
+ uint32_t flags)
{
memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(),
master_key.length(),
key.c_str(), key.length(),
{
memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(),
master_key.length(),
key.c_str(), key.length(),
-
value.c_str(), value.length
(),
+
&value[0], value.size
(),
expiration,
flags);
return (rc == MEMCACHED_SUCCESS);
expiration,
flags);
return (rc == MEMCACHED_SUCCESS);
@@
-192,9
+209,9
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool add
_by_k
ey(const std::string &master_key,
-
const std::string &key,
-
const std::string &value)
+ bool add
ByK
ey(const std::string &master_key,
+ const std::string &key,
+ const std::string &value)
{
memcached_return rc= memcached_add_by_key(&memc,
master_key.c_str(),
{
memcached_return rc= memcached_add_by_key(&memc,
master_key.c_str(),
@@
-215,9
+232,9
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool replace
_by_k
ey(const std::string &master_key,
-
const std::string &key,
-
const std::string &value)
+ bool replace
ByK
ey(const std::string &master_key,
+ const std::string &key,
+ const std::string &value)
{
memcached_return rc= memcached_replace_by_key(&memc,
master_key.c_str(),
{
memcached_return rc= memcached_replace_by_key(&memc,
master_key.c_str(),
@@
-237,9
+254,9
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool prepend
_by_k
ey(const std::string &master_key,
-
const std::string &key,
-
const std::string &value)
+ bool prepend
ByK
ey(const std::string &master_key,
+ const std::string &key,
+ const std::string &value)
{
memcached_return rc= memcached_prepend_by_key(&memc,
master_key.c_str(),
{
memcached_return rc= memcached_prepend_by_key(&memc,
master_key.c_str(),
@@
-264,9
+281,9
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool append
_by_k
ey(const std::string &master_key,
-
const std::string &key,
-
const std::string &value)
+ bool append
ByK
ey(const std::string &master_key,
+ const std::string &key,
+ const std::string &value)
{
memcached_return rc= memcached_append_by_key(&memc,
master_key.c_str(),
{
memcached_return rc= memcached_append_by_key(&memc,
master_key.c_str(),
@@
-289,10
+306,10
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool cas
_by_k
ey(const std::string &master_key,
-
const std::string &key,
-
const std::string &value,
-
uint64_t cas_arg)
+ bool cas
ByK
ey(const std::string &master_key,
+ const std::string &key,
+ const std::string &value,
+ uint64_t cas_arg)
{
memcached_return rc= memcached_cas_by_key(&memc,
master_key.c_str(),
{
memcached_return rc= memcached_cas_by_key(&memc,
master_key.c_str(),
@@
-312,8
+329,8
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool
delete_by_k
ey(const std::string &master_key,
-
const std::string &key)
+ bool
removeByK
ey(const std::string &master_key,
+ const std::string &key)
{
memcached_return rc= memcached_delete_by_key(&memc,
master_key.c_str(),
{
memcached_return rc= memcached_delete_by_key(&memc,
master_key.c_str(),
@@
-330,9
+347,9
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- bool fetch
_e
xecute(memcached_execute_function *callback,
-
void *context,
-
unsigned int num_of_callbacks)
+ bool fetch
E
xecute(memcached_execute_function *callback,
+ void *context,
+ unsigned int num_of_callbacks)
{
memcached_return rc= memcached_fetch_execute(&memc,
callback,
{
memcached_return rc= memcached_fetch_execute(&memc,
callback,
@@
-341,7
+358,7
@@
public:
return (rc == MEMCACHED_SUCCESS);
}
return (rc == MEMCACHED_SUCCESS);
}
- const std::string lib
_v
ersion() const
+ const std::string lib
V
ersion() const
{
const char *ver= memcached_lib_version();
const std::string version(ver);
{
const char *ver= memcached_lib_version();
const std::string version(ver);
@@
-352,3
+369,5
@@
private:
memcached_st memc;
memcached_result_st result;
};
memcached_st memc;
memcached_result_st result;
};
+
+#endif /* LIBMEMCACHEDPP_H */