~ubuntu-branches/ubuntu/breezy/pysvn/breezy

« back to all changes in this revision

Viewing changes to Import/pycxx_5_3_4/Demo/pycxx_iter.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2005-09-08 05:13:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050908051333-qgsa2rksrb4az1h4
Tags: 1.3.0-1
Package from release tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "pycxx_iter.hxx"
 
2
#include "Python.h"
 
3
#include "CXX/Objects.hxx"
 
4
 
 
5
void IterT::init_type() {
 
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
 
 
15
class MyIterModule : public Py::ExtensionModule<MyIterModule> {
 
16
 
 
17
public:
 
18
  MyIterModule() : Py::ExtensionModule<MyIterModule>("pycxx_iter") {
 
19
    IterT::init_type();
 
20
    add_varargs_method("IterT",&MyIterModule::new_IterT,"IterT(from,last)");
 
21
    initialize("MyIterModule documentation"); // register with Python
 
22
  }
 
23
  
 
24
  virtual ~MyIterModule() {}
 
25
 
 
26
private:
 
27
  Py::Object new_IterT(const Py::Tuple& args) {
 
28
    if (args.length() != 2) {
 
29
        throw Py::RuntimeError("Incorrect # of args to IterT(from,to).");
 
30
    }
 
31
    return Py::asObject(new IterT(Py::Int(args[0]),Py::Int(args[1])));
 
32
  }
 
33
};
 
34
 
 
35
extern "C" void initpycxx_iter() {
 
36
  // the following constructor call registers our extension module
 
37
  // with the Python runtime system
 
38
  static MyIterModule* IterTest = new MyIterModule;
 
39
}