~ubuntu-branches/ubuntu/natty/pysvn/natty

« back to all changes in this revision

Viewing changes to Import/pycxx-5.5.0/Demo/pycxx_iter.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-23 20:08:08 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223200808-t946skprxzf6vjqx
Tags: 1.6.3-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

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