From: Date: Mon, 14 Jan 2008 05:53:41 +0000 (-0500) Subject: First push of example C++ interface. X-Git-Tag: 0.14~16 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=9cfc3faa3f8471083350cecce7e49114ce827c89;p=m6w6%2Flibmemcached First push of example C++ interface. --- diff --git a/.hgignore b/.hgignore index dcab7dd6..cd363e7a 100644 --- a/.hgignore +++ b/.hgignore @@ -8,6 +8,9 @@ ^autom4te.cache$ ^include/(libmemcached_config.h(.in)?|stamp-h1)$ ^stamp-h1$ +^lib/libmemcachedPlus.la$ +^tests/testplus$ + # Build artifacts ^lib/libmemcached.la$ diff --git a/ChangeLog b/ChangeLog index da2fd9f1..7fddc017 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * First prototype of C++ interface * Updated docs for uint16_t changes in previous release 0.13 Sun Jan 13 06:51:50 PST 2008 diff --git a/include/memcached.hh b/include/memcached.hh new file mode 100644 index 00000000..a359488d --- /dev/null +++ b/include/memcached.hh @@ -0,0 +1,23 @@ +#ifdef USE_PRAGMA_INTERFACE +#pragma interface /* gcc class implementation */ +#endif + +#include +#include + +class Memcached +{ + memcached_st memc; + +public: + + Memcached(); + Memcached(memcached_st *clone); + ~Memcached() + { + memcached_free(&memc); + } + + char *get(char *key, size_t *value_length); + memcached_return set(char *key, char *value, size_t value_length); +}; diff --git a/lib/Makefile.am b/lib/Makefile.am index d63ef583..7012db66 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -24,7 +24,8 @@ noinst_HEADERS = libmemcached_probes.h \ memcached_io.h \ common.h -lib_LTLIBRARIES = libmemcached.la +lib_LTLIBRARIES = libmemcached.la libmemcachedPlus.la + libmemcached_la_SOURCES = crc.c \ hsieh_hash.c \ memcached.c \ @@ -55,6 +56,10 @@ libmemcached_la_SOURCES = crc.c \ libmemcached_la_LIBADD = libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) +libmemcachedPlus_la_SOURCES = memcachedplus.cpp +libmemcachedPlus_la_LIBADD = +libmemcachedPlus_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) + if HAVE_DTRACE libmemcached_la_LIBADD += libmemcached_probes.o endif diff --git a/lib/memcachedplus.cpp b/lib/memcachedplus.cpp new file mode 100644 index 00000000..f092aa56 --- /dev/null +++ b/lib/memcachedplus.cpp @@ -0,0 +1,38 @@ +/* + Memcached library +*/ + +#ifdef USE_PRAGMA_IMPLEMENTATION +#pragma implementation // gcc: Class implementation +#endif + +#include +#include + +Memcached::Memcached() +{ + memcached_create(&memc); +} + +Memcached::Memcached(memcached_st *clone) +{ + WATCHPOINT; + memcached_clone(&memc, clone); + WATCHPOINT; +} + +char *Memcached::get(char *key, size_t *value_length) +{ + uint32_t flags; + memcached_return rc; + + return memcached_get(&memc, key, strlen(key), + value_length, &flags, &rc); +} + +memcached_return Memcached::set(char *key, char *value, size_t value_length) +{ + return memcached_set(&memc, key, strlen(key), + value, value_length, + (time_t)0, (uint32_t)0); +} diff --git a/tests/Makefile.am b/tests/Makefile.am index dc8ee2d2..06818c3a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -16,11 +16,14 @@ EXTRA_DIST = output.res output2.res\ LIBS = noinst_HEADERS = test.h -noinst_PROGRAMS = testapp +noinst_PROGRAMS = testapp testplus testapp_SOURCES = test.c function.c ../src/generator.c ../src/execute.c testapp_LDADD = $(LDADDS) +testplus_SOURCES = test.c plus.cpp +testplus_LDADD = $(LDADDS) ../lib/libmemcachedPlus.la + record: ./testapp > output.res diff --git a/tests/plus.cpp b/tests/plus.cpp new file mode 100644 index 00000000..37b6260e --- /dev/null +++ b/tests/plus.cpp @@ -0,0 +1,46 @@ +/* + C++ interface test +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "test.h" + +uint8_t basic_test(memcached_st *memc) +{ + Memcached foo; + char *value_set= "This is some data"; + char *value; + size_t value_length; + + foo.set("mine", value_set, strlen(value_set)); + value= foo.get("mine", &value_length); + + assert((memcmp(value, value_set, value_length) == 0)); + + return 0; +} + +test_st tests[] ={ + {"basic", 0, basic_test }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"block", 0, 0, tests}, + {0, 0, 0, 0} +}; + +collection_st *gets_collections(void) +{ + return collection; +} diff --git a/tests/test.h b/tests/test.h index 4e695d26..8bc4d7a9 100644 --- a/tests/test.h +++ b/tests/test.h @@ -1,6 +1,10 @@ /* Structures for generic tests. */ +#ifdef __cplusplus +extern "C" { + +#endif #include #include "../lib/common.h" @@ -22,3 +26,7 @@ struct collection_st { /* How we make all of this work :) */ collection_st *gets_collections(void); + +#ifdef __cplusplus +} +#endif