First push of example C++ interface.
author <brian@gir.local> <>
Mon, 14 Jan 2008 05:53:41 +0000 (00:53 -0500)
committer <brian@gir.local> <>
Mon, 14 Jan 2008 05:53:41 +0000 (00:53 -0500)
.hgignore
ChangeLog
include/memcached.hh [new file with mode: 0644]
lib/Makefile.am
lib/memcachedplus.cpp [new file with mode: 0644]
tests/Makefile.am
tests/plus.cpp [new file with mode: 0644]
tests/test.h

index dcab7dd66559d2d6ba28ce1cd4add5e4a1ceb3c6..cd363e7a47bb2ab981807bc358cba8c612ba3034 100644 (file)
--- 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$
index da2fd9f1d03a6c975c508bc25364b8f591a7ae0e..7fddc017a8574d8126fc73260d2ad4daee10adcf 100644 (file)
--- 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 (file)
index 0000000..a359488
--- /dev/null
@@ -0,0 +1,23 @@
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface                       /* gcc class implementation */
+#endif
+
+#include <memcached.h>
+#include <stdio.h>
+
+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);
+};
index d63ef5839872761a1e4a783aa94b8208a4681f91..7012db66e1f68934272c69578f130994cd9d84d9 100644 (file)
@@ -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 (file)
index 0000000..f092aa5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+  Memcached library
+*/
+
+#ifdef USE_PRAGMA_IMPLEMENTATION
+#pragma implementation        // gcc: Class implementation
+#endif
+
+#include <strings.h>
+#include <memcached.hh>
+
+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);
+}
index dc8ee2d242d3f1739ea5a5280c6cb378c74f7ab0..06818c3af7b9aae839b87b01521e182e803687aa 100644 (file)
@@ -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 (file)
index 0000000..37b6260
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+  C++ interface test
+*/
+#include <assert.h>
+#include <memcached.h>
+#include <memcached.hh>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
+
+#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;
+}
index 4e695d26ca468ca637f596155b0de1571ef0613b..8bc4d7a9ab1e329d1650bb720e389dbea4759ff1 100644 (file)
@@ -1,6 +1,10 @@
 /*
   Structures for generic tests.
 */
+#ifdef __cplusplus
+extern "C" {
+
+#endif
 #include <memcached.h>
 #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