~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/python/functor/example.i

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File : example.i */
 
2
%module example
 
3
 
 
4
 
 
5
%inline %{
 
6
// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
 
7
template<class T> class Sum {
 
8
   T res;
 
9
public:
 
10
   Sum(T i = 0) : res(i) { }
 
11
   void operator() (T x) { res += x; }
 
12
   T result() const { return res; }
 
13
};
 
14
 
 
15
%}
 
16
 
 
17
// Rename the application operator to __call__ for python.
 
18
// Note: this is normally automatic, but if you had to do it yourself
 
19
// you would use this directive:
 
20
//
 
21
// %rename(__call__) *::operator();
 
22
 
 
23
// Instantiate a few versions
 
24
%template(intSum) Sum<int>;
 
25
%template(doubleSum) Sum<double>;
 
26
 
 
27
 
 
28
 
 
29