File: pycxx_iter.cxx

package info (click to toggle)
pycxx 6.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,156 kB
  • sloc: cpp: 6,093; python: 756; sh: 47; ansic: 43; makefile: 38
file content (50 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "pycxx_iter.hxx"
#include "CXX/Objects.hxx"

void IterT::init_type()
{
    behaviors().name("IterT");
    behaviors().doc("IterT(ini_count)");
    // you must have overwritten the virtual functions
    // Py::Object iter() and Py::Object iternext()
    behaviors().supportIter();    // set entries in the Type Table
    behaviors().supportRepr();
    add_varargs_method("reversed",&IterT::reversed,"reversed()");
}

class MyIterModule : public Py::ExtensionModule<MyIterModule>
{

public:
    MyIterModule() : Py::ExtensionModule<MyIterModule>("pycxx_iter")
    {
        IterT::init_type();
        add_varargs_method("IterT",&MyIterModule::new_IterT,"IterT(from,last)");
        initialize("MyIterModule documentation"); // register with Python
    }
    
    virtual ~MyIterModule() {}

private:
    Py::Object new_IterT(const Py::Tuple& args)
    {
        if (args.length() != 2)
        {
            throw Py::RuntimeError("Incorrect # of args to IterT(from,to).");
        }
        return Py::asObject(new IterT(Py::Int(args[0]),Py::Int(args[1])));
    }
};

#if defined( _WIN32 )
#define EXPORT_SYMBOL __declspec( dllexport )
#else
#define EXPORT_SYMBOL
#endif

extern "C" EXPORT_SYMBOL void initpycxx_iter()
{
    // the following constructor call registers our extension module
    // with the Python runtime system
    static MyIterModule* IterTest = new MyIterModule;
}