1 #include "pycxx_iter.hxx"
2 #include "CXX/Objects.hxx"
3 
init_type()4 void IterT::init_type()
5 {
6     behaviors().name("IterT");
7     behaviors().doc("IterT(ini_count)");
8     // you must have overwritten the virtual functions
9     // Py::Object iter() and Py::Object iternext()
10     behaviors().supportIter();    // set entries in the Type Table
11     behaviors().supportRepr();
12     add_varargs_method("reversed",&IterT::reversed,"reversed()");
13 
14     behaviors().readyType();
15 }
16 
17 class MyIterModule : public Py::ExtensionModule<MyIterModule>
18 {
19 
20 public:
MyIterModule()21     MyIterModule() : Py::ExtensionModule<MyIterModule>("pycxx_iter")
22     {
23         IterT::init_type();
24         add_varargs_method("IterT",&MyIterModule::new_IterT,"IterT(from,last)");
25         initialize("MyIterModule documentation"); // register with Python
26     }
27 
~MyIterModule()28     virtual ~MyIterModule() {}
29 
30 private:
new_IterT(const Py::Tuple & args)31     Py::Object new_IterT(const Py::Tuple& args)
32     {
33         if (args.length() != 2)
34         {
35             throw Py::RuntimeError("Incorrect # of args to IterT(from,to).");
36         }
37         return Py::asObject(new IterT(Py::Int(args[0]),Py::Int(args[1])));
38     }
39 };
40 
41 #if defined( _WIN32 )
42 #define EXPORT_SYMBOL __declspec( dllexport )
43 #else
44 #define EXPORT_SYMBOL
45 #endif
46 
initpycxx_iter()47 extern "C" EXPORT_SYMBOL void initpycxx_iter()
48 {
49     // the following constructor call registers our extension module
50     // with the Python runtime system
51     static MyIterModule* IterTest = new MyIterModule;
52 }
53