[pypy-svn] r76059 - pypy/branch/reflex-support/pypy/module/cppyy/test

wlav at codespeak.net wlav at codespeak.net
Fri Jul 9 10:45:57 CEST 2010


Author: wlav
Date: Fri Jul  9 10:45:56 2010
New Revision: 76059

Added:
   pypy/branch/reflex-support/pypy/module/cppyy/test/example01.h   (contents, props changed)
Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile
   pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
Log:
(cfbolz, wlav) Cleanup example01 C++ code in test.


Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile	Fri Jul  9 10:45:56 2010
@@ -16,6 +16,6 @@
   cppflags2=-Wno-pmf-conversions
 endif
 
-example01Dict.so: example01.cxx
-	$(genreflex) example01.cxx $(genreflexflags)
-	g++ -o $@ example01_rflx.cpp -shared -lReflex $(cppflags) $(cppflags2)
+example01Dict.so: example01.cxx example01.h
+	$(genreflex) example01.h $(genreflexflags)
+	g++ -o $@ example01_rflx.cpp example01.cxx -shared -lReflex $(cppflags) $(cppflags2)

Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx	Fri Jul  9 10:45:56 2010
@@ -4,98 +4,86 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "example01.h"
 
-class payload {
-public:
-    payload(double d) : m_data(d) {}
-
-// cctor needed as long as we have no converter for const& objects
-    payload( const payload& p ) : m_data(p.m_data) {}
-
-    double getData() { return m_data; }
-    void setData(double d) { m_data = d; }
-
-private:
-    double m_data;
-};
-
-
-class example01 {
-public:
-    static int count;
-    int somedata;
-
-    example01() : somedata(-99) {
-        count++;
-    }
-    example01(int a) : somedata(a) {
-        count++;
-        std::cout << "constructor called" << std::endl;
-    }
-    example01(const example01& e) : somedata(e.somedata) {
-        count++;
-        std::cout << "copy constructor called" << std::endl;
-    }
-    example01& operator=(const example01& e) {
-        if (this != &e) {
-            somedata = e.somedata;
-        }
-        return *this;
-    }
-    ~example01() {
-        count--;
-    }
+//===========================================================================
+payload::payload(double d) : m_data(d) {}
+payload::payload(const payload& p) : m_data(p.m_data) {}
+
+double payload::getData() { return m_data; }
+void payload::setData(double d) { m_data = d; }
+
+
+//===========================================================================
+example01::example01() : somedata(-99) {
+    count++;
+}
+example01::example01(int a) : somedata(a) {
+    count++;
+    std::cout << "constructor called" << std::endl;
+}
+example01::example01(const example01& e) : somedata(e.somedata) {
+    count++;
+    std::cout << "copy constructor called" << std::endl;
+}
+example01& example01::operator=(const example01& e) {
+    if (this != &e) {
+        somedata = e.somedata;
+    }
+    return *this;
+}
+example01::~example01() {
+    count--;
+}
 
 // class methods
-    static int staticAddOneToInt(int a) {
-        return a + 1;
-    }
-    static int staticAddOneToInt(int a, int b) {
-        return a + b + 1;
-    }
-    static double staticAddToDouble(double a) {
-        return a + 0.01;
-    }
-    static int staticAtoi(const char* str) {
-        return ::atoi(str);
-    }
-    static char* staticStrcpy(const char* strin) {
-        char* strout = (char*)malloc(::strlen(strin + 1));
-        ::strcpy(strout, strin);
-        return strout;
-    }
-    static void setPayload( payload* p, double d ) {
-        p->setData(d);
-    }
-
-    static int getCount() {
-        std::cout << "getcount called" << std::endl;
-        return count;
-    }
+int example01::staticAddOneToInt(int a) {
+    return a + 1;
+}
+int example01::staticAddOneToInt(int a, int b) {
+    return a + b + 1;
+}
+double example01::staticAddToDouble(double a) {
+    return a + 0.01;
+}
+int example01::staticAtoi(const char* str) {
+    return ::atoi(str);
+}
+char* example01::staticStrcpy(const char* strin) {
+    char* strout = (char*)malloc(::strlen(strin + 1));
+    ::strcpy(strout, strin);
+    return strout;
+}
+void example01::setPayload( payload* p, double d ) {
+    p->setData(d);
+}
+
+int example01::getCount() {
+    std::cout << "getcount called" << std::endl;
+    return count;
+}
 
 // instance methods
-    int addDataToInt(int a) {
-        return somedata + a;
-    }
-
-    double addDataToDouble(double a) {
-        return somedata + a;
-    }
-
-    int addDataToAtoi(const char* str) {
-        return ::atoi(str) + somedata;
-    }   
-
-    char* addToStringValue(const char* str) {
-        int out = ::atoi(str) + somedata;
-        std::ostringstream ss;
-        ss << out << std::ends;
-        std::string result = ss.str();
-        char* cresult = (char*)malloc(result.size()+1);
-        ::strcpy(cresult, result.c_str());
-        return cresult;
-    }
-
-};
+int example01::addDataToInt(int a) {
+    return somedata + a;
+}
+
+double example01::addDataToDouble(double a) {
+    return somedata + a;
+}
+
+int example01::addDataToAtoi(const char* str) {
+    return ::atoi(str) + somedata;
+}   
+
+char* example01::addToStringValue(const char* str) {
+    int out = ::atoi(str) + somedata;
+    std::ostringstream ss;
+    ss << out << std::ends;
+    std::string result = ss.str();
+    char* cresult = (char*)malloc(result.size()+1);
+    ::strcpy(cresult, result.c_str());
+    return cresult;
+}
 
 int example01::count = 0;

Added: pypy/branch/reflex-support/pypy/module/cppyy/test/example01.h
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/example01.h	Fri Jul  9 10:45:56 2010
@@ -0,0 +1,39 @@
+class payload {
+public:
+    payload(double d);
+    payload(const payload& p);
+
+    double getData();
+    void setData(double d);
+
+private:
+    double m_data;
+};
+
+
+class example01 {
+public:
+    static int count;
+    int somedata;
+
+    example01();
+    example01(int a);
+    example01(const example01& e);
+    example01& operator=(const example01& e);
+    ~example01();
+
+// class methods
+    static int staticAddOneToInt(int a);
+    static int staticAddOneToInt(int a, int b);
+    static double staticAddToDouble(double a);
+    static int staticAtoi(const char* str);
+    static char* staticStrcpy(const char* strin);
+    static void setPayload( payload* p, double d );
+    static int getCount();
+
+// instance methods
+    int addDataToInt(int a);
+    double addDataToDouble(double a);
+    int addDataToAtoi(const char* str);
+    char* addToStringValue(const char* str);
+};



More information about the Pypy-commit mailing list