From: Padraig O'Sullivan Date: Fri, 10 Jul 2009 04:40:34 +0000 (-0400) Subject: More modifications to the C++ interface. Changing the return type of a X-Git-Tag: 0.32~17^2~9 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=dbd274af6fc88a8f7a0456eb419a753dd842c88f;p=m6w6%2Flibmemcached More modifications to the C++ interface. Changing the return type of a number of functions to be boolean instead of memcached_return. --- diff --git a/libmemcached/memcached.hh b/libmemcached/memcached.hh index 55b09945..42334e29 100644 --- a/libmemcached/memcached.hh +++ b/libmemcached/memcached.hh @@ -87,131 +87,144 @@ public: return memcached_mget(&memc, keys, key_length, number_of_keys); } - memcached_return set(const std::string& key, const char *value, size_t value_length) + bool set(const std::string& key, const char *value, size_t value_length) { - return memcached_set(&memc, key.c_str(), key.length(), - value, value_length, - time_t(0), uint32_t(0)); + memcached_return rc= memcached_set(&memc, key.c_str(), key.length(), + value, value_length, + time_t(0), uint32_t(0)); + return (rc == MEMCACHED_SUCCESS); } - memcached_return set_by_key(const std::string& master_key, - const std::string& key, - const char *value, size_t value_length) + bool set_by_key(const std::string& master_key, + const std::string& key, + const char *value, size_t value_length) { - return memcached_set_by_key(&memc, master_key.c_str(), - master_key.length(), - key.c_str(), key.length(), - value, value_length, - time_t(0), - uint32_t(0)); + memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(), + master_key.length(), + key.c_str(), key.length(), + value, value_length, + time_t(0), + uint32_t(0)); + return (rc == MEMCACHED_SUCCESS); } - memcached_return - increment(const std::string& key, unsigned int offset, uint64_t *value) + bool increment(const std::string& key, unsigned int offset, uint64_t *value) { - return memcached_increment(&memc, key.c_str(), key.length(), - offset, value); + memcached_return rc= memcached_increment(&memc, key.c_str(), key.length(), + offset, value); + return (rc == MEMCACHED_SUCCESS); } - memcached_return - decrement(const char *key, unsigned int offset, uint64_t *value) + bool decrement(const char *key, unsigned int offset, uint64_t *value) { - return memcached_decrement(&memc, key, strlen(key), - offset, value); + memcached_return rc= memcached_decrement(&memc, key, strlen(key), + offset, value); + return (rc == MEMCACHED_SUCCESS); } - memcached_return add(const char *key, const char *value, size_t value_length) + bool add(const char *key, const char *value, size_t value_length) { - return memcached_add(&memc, key, strlen(key), value, value_length, 0, 0); + memcached_return rc= memcached_add(&memc, key, strlen(key), value, value_length, 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return add_by_key(const char *master_key, const char *key, - const char *value, size_t value_length) + bool add_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { - return memcached_add_by_key(&memc, master_key, strlen(master_key), - key, strlen(key), - value, value_length, - 0, 0); + memcached_return rc= memcached_add_by_key(&memc, master_key, strlen(master_key), + key, strlen(key), + value, value_length, + 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return replace(const char *key, const char *value, - size_t value_length) + bool replace(const char *key, const char *value, + size_t value_length) { - return memcached_replace(&memc, key, strlen(key), - value, value_length, - 0, 0); + memcached_return rc= memcached_replace(&memc, key, strlen(key), + value, value_length, + 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return replace_by_key(const char *master_key, const char *key, - const char *value, size_t value_length) + bool replace_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { - return memcached_replace_by_key(&memc, master_key, strlen(master_key), - key, strlen(key), - value, value_length, 0, 0); + memcached_return rc= memcached_replace_by_key(&memc, master_key, strlen(master_key), + key, strlen(key), + value, value_length, 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return prepend(const char *key, const char *value, - size_t value_length) + bool prepend(const char *key, const char *value, + size_t value_length) { - return memcached_prepend(&memc, key, strlen(key), - value, value_length, 0, 0); + memcached_return rc= memcached_prepend(&memc, key, strlen(key), + value, value_length, 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return prepend_by_key(const char *master_key, const char *key, - const char *value, size_t value_length) + bool prepend_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { - return memcached_prepend_by_key(&memc, master_key, strlen(master_key), - key, strlen(key), - value, value_length, - 0, - 0); + memcached_return rc= memcached_prepend_by_key(&memc, master_key, strlen(master_key), + key, strlen(key), + value, value_length, + 0, + 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return append(const char *key, const char *value, - size_t value_length) + bool append(const char *key, const char *value, + size_t value_length) { - return memcached_append(&memc, key, strlen(key), - value, value_length, 0, 0); + memcached_return rc= memcached_append(&memc, key, strlen(key), + value, value_length, 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return append_by_key(const char *master_key, const char *key, - const char *value, size_t value_length) + bool append_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { - return memcached_append_by_key(&memc, - master_key, strlen(master_key), - key, strlen(key), - value, value_length, 0, 0); + memcached_return rc= memcached_append_by_key(&memc, + master_key, strlen(master_key), + key, strlen(key), + value, value_length, 0, 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return cas(const char *key, const char *value, - size_t value_length, uint64_t cas_arg) + bool cas(const char *key, const char *value, + size_t value_length, uint64_t cas_arg) { - return memcached_cas(&memc, key, strlen(key), - value, value_length, 0, 0, cas_arg); + memcached_return rc= memcached_cas(&memc, key, strlen(key), + value, value_length, 0, 0, cas_arg); + return (rc == MEMCACHED_SUCCESS); } - memcached_return cas_by_key(const char *master_key, const char *key, - const char *value, size_t value_length, - uint64_t cas_arg) + bool cas_by_key(const char *master_key, const char *key, + const char *value, size_t value_length, + uint64_t cas_arg) { - return memcached_cas_by_key(&memc, - master_key, strlen(master_key), - key, strlen(key), - value, value_length, - 0, 0, cas_arg); + memcached_return rc= memcached_cas_by_key(&memc, + master_key, strlen(master_key), + key, strlen(key), + value, value_length, + 0, 0, cas_arg); + return (rc == MEMCACHED_SUCCESS); } // using 'remove' vs. 'delete' since 'delete' is a keyword - memcached_return remove(const char *key) + bool remove(const std::string& key) { - return memcached_delete (&memc, key, strlen(key), 0); - + memcached_return rc= memcached_delete(&memc, key.c_str(), key.length(), 0); + return (rc == MEMCACHED_SUCCESS); } - memcached_return delete_by_key(const char *master_key, const char *key) + bool delete_by_key(const char *master_key, const char *key) { - return memcached_delete_by_key(&memc, master_key, strlen(master_key), - key, strlen(key), 0); + memcached_return rc= memcached_delete_by_key(&memc, master_key, strlen(master_key), + key, strlen(key), 0); + return (rc == MEMCACHED_SUCCESS); } }; diff --git a/tests/plus.cpp b/tests/plus.cpp index 1b7be39d..323d6c20 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -46,7 +46,7 @@ test_return basic_test(memcached_st *memc) uint8_t increment_test(memcached_st *memc) { Memcached mcach(memc); - memcached_return rc; + bool rc; const string key("inctest"); const char *inc_value= "1"; string ret_value; @@ -62,15 +62,15 @@ uint8_t increment_test(memcached_st *memc) assert(int_ret_value == int_inc_value); rc= mcach.increment(key, 1, &int_ret_value); - assert(rc == MEMCACHED_SUCCESS); + assert(rc == true); assert(int_ret_value == 2); rc= mcach.increment(key, 1, &int_ret_value); - assert(rc == MEMCACHED_SUCCESS); + assert(rc == true); assert(int_ret_value == 3); rc= mcach.increment(key, 5, &int_ret_value); - assert(rc == MEMCACHED_SUCCESS); + assert(rc == true); assert(int_ret_value == 8); return 0;