Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesscallback.h
Go to the documentation of this file.
1 
2 // File: tesscallback.h
3 // Description: classes and functions to replace pointer-to-functions
4 // Author: Samuel Charron
5 //
6 // (C) Copyright 2006, Google Inc.
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
18 
19 #ifndef _TESS_CALLBACK_SPECIALIZATIONS_H
20 #define _TESS_CALLBACK_SPECIALIZATIONS_H
21 
22 #include "host.h" // For NULL.
23 
25  static void FailIsRepeatable(const char* name);
26 };
27 
28 
29 class TessClosure {
30  public:
31  virtual ~TessClosure() { }
32  virtual void Run() = 0;
33 };
34 
35 template <class R>
37  public:
38  virtual ~TessResultCallback() { }
39  virtual R Run() = 0;
40 };
41 
42 template <bool del, class R, class T>
44  public:
46  typedef R (T::*MemberSignature)() const;
47 
48  private:
49  const T* object_;
50  MemberSignature member_;
51 
52  public:
54  const T* object, MemberSignature member)
55  : object_(object),
56  member_(member) {
57  }
58 
59  virtual R Run() {
60  if (!del) {
61  R result = (object_->*member_)();
62  return result;
63  } else {
64  R result = (object_->*member_)();
65  // zero out the pointer to ensure segfault if used again
66  member_ = NULL;
67  delete this;
68  return result;
69  }
70  }
71 };
72 
73 template <bool del, class T>
75  : public TessClosure {
76  public:
77  typedef TessClosure base;
78  typedef void (T::*MemberSignature)() const;
79 
80  private:
81  const T* object_;
82  MemberSignature member_;
83 
84  public:
86  const T* object, MemberSignature member)
87  : object_(object),
88  member_(member) {
89  }
90 
91  virtual void Run() {
92  if (!del) {
93  (object_->*member_)();
94  } else {
95  (object_->*member_)();
96  // zero out the pointer to ensure segfault if used again
97  member_ = NULL;
98  delete this;
99  }
100  }
101 };
102 
103 #ifndef SWIG
104 template <class T1, class T2, class R>
107  const T1* obj, R (T2::*member)() const) {
109  obj, member);
110 }
111 #endif
112 
113 #ifndef SWIG
114 template <class T1, class T2, class R>
117  const T1* obj, R (T2::*member)() const) {
119  obj, member);
120 }
121 #endif
122 
123 template <bool del, class R, class T>
125  public:
127  typedef R (T::*MemberSignature)() ;
128 
129  private:
130  T* object_;
131  MemberSignature member_;
132 
133  public:
135  T* object, MemberSignature member)
136  : object_(object),
137  member_(member) {
138  }
139 
140  virtual R Run() {
141  if (!del) {
142  R result = (object_->*member_)();
143  return result;
144  } else {
145  R result = (object_->*member_)();
146  // zero out the pointer to ensure segfault if used again
147  member_ = NULL;
148  delete this;
149  return result;
150  }
151  }
152 };
153 
154 template <bool del, class T>
155 class _TessMemberResultCallback_0_0<del, void, T>
156  : public TessClosure {
157  public:
158  typedef TessClosure base;
159  typedef void (T::*MemberSignature)() ;
160 
161  private:
162  T* object_;
163  MemberSignature member_;
164 
165  public:
167  T* object, MemberSignature member)
168  : object_(object),
169  member_(member) {
170  }
171 
172  virtual void Run() {
173  if (!del) {
174  (object_->*member_)();
175  } else {
176  (object_->*member_)();
177  // zero out the pointer to ensure segfault if used again
178  member_ = NULL;
179  delete this;
180  }
181  }
182 };
183 
184 #ifndef SWIG
185 template <class T1, class T2, class R>
188  T1* obj, R (T2::*member)() ) {
190  obj, member);
191 }
192 #endif
193 
194 #ifndef SWIG
195 template <class T1, class T2, class R>
198  T1* obj, R (T2::*member)() ) {
200  obj, member);
201 }
202 #endif
203 
204 template <bool del, class R>
206  public:
208  typedef R (*FunctionSignature)();
209 
210  private:
211  FunctionSignature function_;
212 
213  public:
215  FunctionSignature function)
216  : function_(function) {
217  }
218 
219  virtual R Run() {
220  if (!del) {
221  R result = (*function_)();
222  return result;
223  } else {
224  R result = (*function_)();
225  // zero out the pointer to ensure segfault if used again
226  function_ = NULL;
227  delete this;
228  return result;
229  }
230  }
231 };
232 
233 template <bool del>
235  : public TessClosure {
236  public:
237  typedef TessClosure base;
238  typedef void (*FunctionSignature)();
239 
240  private:
241  FunctionSignature function_;
242 
243  public:
245  FunctionSignature function)
246  : function_(function) {
247  }
248 
249  virtual void Run() {
250  if (!del) {
251  (*function_)();
252  } else {
253  (*function_)();
254  // zero out the pointer to ensure segfault if used again
255  function_ = NULL;
256  delete this;
257  }
258  }
259 };
260 
261 template <class R>
263 NewTessCallback(R (*function)()) {
264  return new _TessFunctionResultCallback_0_0<true,R>(function);
265 }
266 
267 template <class R>
269 NewPermanentTessCallback(R (*function)()) {
270  return new _TessFunctionResultCallback_0_0<false,R>(function);
271 }
272 
273 template <class A1>
275  public:
276  virtual ~TessCallback1() { }
277  virtual void Run(A1) = 0;
278 };
279 
280 template <class R, class A1>
282  public:
283  virtual ~TessResultCallback1() { }
284  virtual R Run(A1) = 0;
285 };
286 
287 template <bool del, class R, class T, class A1>
289  public:
291  typedef R (T::*MemberSignature)(A1) const;
292 
293  private:
294  const T* object_;
295  MemberSignature member_;
296 
297  public:
299  const T* object, MemberSignature member)
300  : object_(object),
301  member_(member) {
302  }
303 
304  virtual R Run(A1 a1) {
305  if (!del) {
306  R result = (object_->*member_)(a1);
307  return result;
308  } else {
309  R result = (object_->*member_)(a1);
310  // zero out the pointer to ensure segfault if used again
311  member_ = NULL;
312  delete this;
313  return result;
314  }
315  }
316 };
317 
318 template <bool del, class T, class A1>
319 class _ConstTessMemberResultCallback_0_1<del, void, T, A1>
320  : public TessCallback1<A1> {
321  public:
323  typedef void (T::*MemberSignature)(A1) const;
324 
325  private:
326  const T* object_;
327  MemberSignature member_;
328 
329  public:
331  const T* object, MemberSignature member)
332  : object_(object),
333  member_(member) {
334  }
335 
336  virtual void Run(A1 a1) {
337  if (!del) {
338  (object_->*member_)(a1);
339  } else {
340  (object_->*member_)(a1);
341  // zero out the pointer to ensure segfault if used again
342  member_ = NULL;
343  delete this;
344  }
345  }
346 };
347 
348 #ifndef SWIG
349 template <class T1, class T2, class R, class A1>
352  const T1* obj, R (T2::*member)(A1) const) {
354  obj, member);
355 }
356 #endif
357 
358 #ifndef SWIG
359 template <class T1, class T2, class R, class A1>
362  const T1* obj, R (T2::*member)(A1) const) {
364  obj, member);
365 }
366 #endif
367 
368 template <bool del, class R, class T, class A1>
370  public:
372  typedef R (T::*MemberSignature)(A1) ;
373 
374  private:
375  T* object_;
376  MemberSignature member_;
377 
378  public:
380  T* object, MemberSignature member)
381  : object_(object),
382  member_(member) {
383  }
384 
385  virtual R Run(A1 a1) {
386  if (!del) {
387  R result = (object_->*member_)(a1);
388  return result;
389  } else {
390  R result = (object_->*member_)(a1);
391  // zero out the pointer to ensure segfault if used again
392  member_ = NULL;
393  delete this;
394  return result;
395  }
396  }
397 };
398 
399 template <bool del, class T, class A1>
400 class _TessMemberResultCallback_0_1<del, void, T, A1>
401  : public TessCallback1<A1> {
402  public:
404  typedef void (T::*MemberSignature)(A1) ;
405 
406  private:
407  T* object_;
408  MemberSignature member_;
409 
410  public:
412  T* object, MemberSignature member)
413  : object_(object),
414  member_(member) {
415  }
416 
417  virtual void Run(A1 a1) {
418  if (!del) {
419  (object_->*member_)(a1);
420  } else {
421  (object_->*member_)(a1);
422  // zero out the pointer to ensure segfault if used again
423  member_ = NULL;
424  delete this;
425  }
426  }
427 };
428 
429 #ifndef SWIG
430 template <class T1, class T2, class R, class A1>
433  T1* obj, R (T2::*member)(A1) ) {
435  obj, member);
436 }
437 #endif
438 
439 #ifndef SWIG
440 template <class T1, class T2, class R, class A1>
443  T1* obj, R (T2::*member)(A1) ) {
445  obj, member);
446 }
447 #endif
448 
449 template <bool del, class R, class A1>
451  public:
453  typedef R (*FunctionSignature)(A1);
454 
455  private:
456  FunctionSignature function_;
457 
458  public:
460  FunctionSignature function)
461  : function_(function) {
462  }
463 
464  virtual R Run(A1 a1) {
465  if (!del) {
466  R result = (*function_)(a1);
467  return result;
468  } else {
469  R result = (*function_)(a1);
470  // zero out the pointer to ensure segfault if used again
471  function_ = NULL;
472  delete this;
473  return result;
474  }
475  }
476 };
477 
478 template <bool del, class A1>
480  : public TessCallback1<A1> {
481  public:
483  typedef void (*FunctionSignature)(A1);
484 
485  private:
486  FunctionSignature function_;
487 
488  public:
490  FunctionSignature function)
491  : function_(function) {
492  }
493 
494  virtual void Run(A1 a1) {
495  if (!del) {
496  (*function_)(a1);
497  } else {
498  (*function_)(a1);
499  // zero out the pointer to ensure segfault if used again
500  function_ = NULL;
501  delete this;
502  }
503  }
504 };
505 
506 template <class R, class A1>
508 NewTessCallback(R (*function)(A1)) {
509  return new _TessFunctionResultCallback_0_1<true,R,A1>(function);
510 }
511 
512 template <class R, class A1>
514 NewPermanentTessCallback(R (*function)(A1)) {
515  return new _TessFunctionResultCallback_0_1<false,R,A1>(function);
516 }
517 
518 template <class A1,class A2>
520  public:
521  virtual ~TessCallback2() { }
522  virtual void Run(A1,A2) = 0;
523 };
524 
525 template <class R, class A1,class A2>
527  public:
528  virtual ~TessResultCallback2() { }
529  virtual R Run(A1,A2) = 0;
530 };
531 
532 template <bool del, class R, class T, class A1, class A2>
534  public:
536  typedef R (T::*MemberSignature)(A1,A2) const;
537 
538  private:
539  const T* object_;
540  MemberSignature member_;
541 
542  public:
544  const T* object, MemberSignature member)
545  : object_(object),
546  member_(member) {
547  }
548 
549  virtual R Run(A1 a1,A2 a2) {
550  if (!del) {
551  R result = (object_->*member_)(a1,a2);
552  return result;
553  } else {
554  R result = (object_->*member_)(a1,a2);
555  // zero out the pointer to ensure segfault if used again
556  member_ = NULL;
557  delete this;
558  return result;
559  }
560  }
561 };
562 
563 template <bool del, class T, class A1, class A2>
564 class _ConstTessMemberResultCallback_0_2<del, void, T, A1, A2>
565  : public TessCallback2<A1,A2> {
566  public:
568  typedef void (T::*MemberSignature)(A1,A2) const;
569 
570  private:
571  const T* object_;
572  MemberSignature member_;
573 
574  public:
576  const T* object, MemberSignature member)
577  : object_(object),
578  member_(member) {
579  }
580 
581  virtual void Run(A1 a1,A2 a2) {
582  if (!del) {
583  (object_->*member_)(a1,a2);
584  } else {
585  (object_->*member_)(a1,a2);
586  // zero out the pointer to ensure segfault if used again
587  member_ = NULL;
588  delete this;
589  }
590  }
591 };
592 
593 #ifndef SWIG
594 template <class T1, class T2, class R, class A1, class A2>
597  const T1* obj, R (T2::*member)(A1,A2) const) {
599  obj, member);
600 }
601 #endif
602 
603 #ifndef SWIG
604 template <class T1, class T2, class R, class A1, class A2>
607  const T1* obj, R (T2::*member)(A1,A2) const) {
609  obj, member);
610 }
611 #endif
612 
613 template <bool del, class R, class T, class A1, class A2>
615  public:
617  typedef R (T::*MemberSignature)(A1,A2) ;
618 
619  private:
620  T* object_;
621  MemberSignature member_;
622 
623  public:
625  T* object, MemberSignature member)
626  : object_(object),
627  member_(member) {
628  }
629 
630  virtual R Run(A1 a1,A2 a2) {
631  if (!del) {
632  R result = (object_->*member_)(a1,a2);
633  return result;
634  } else {
635  R result = (object_->*member_)(a1,a2);
636  // zero out the pointer to ensure segfault if used again
637  member_ = NULL;
638  delete this;
639  return result;
640  }
641  }
642 };
643 
644 template <bool del, class T, class A1, class A2>
645 class _TessMemberResultCallback_0_2<del, void, T, A1, A2>
646  : public TessCallback2<A1,A2> {
647  public:
649  typedef void (T::*MemberSignature)(A1,A2) ;
650 
651  private:
652  T* object_;
653  MemberSignature member_;
654 
655  public:
657  T* object, MemberSignature member)
658  : object_(object),
659  member_(member) {
660  }
661 
662  virtual void Run(A1 a1,A2 a2) {
663  if (!del) {
664  (object_->*member_)(a1,a2);
665  } else {
666  (object_->*member_)(a1,a2);
667  // zero out the pointer to ensure segfault if used again
668  member_ = NULL;
669  delete this;
670  }
671  }
672 };
673 
674 #ifndef SWIG
675 template <class T1, class T2, class R, class A1, class A2>
678  T1* obj, R (T2::*member)(A1,A2) ) {
680  obj, member);
681 }
682 #endif
683 
684 #ifndef SWIG
685 template <class T1, class T2, class R, class A1, class A2>
688  T1* obj, R (T2::*member)(A1,A2) ) {
690  obj, member);
691 }
692 #endif
693 
694 template <bool del, class R, class A1, class A2>
696  public:
698  typedef R (*FunctionSignature)(A1,A2);
699 
700  private:
701  FunctionSignature function_;
702 
703  public:
705  FunctionSignature function)
706  : function_(function) {
707  }
708 
709  virtual R Run(A1 a1,A2 a2) {
710  if (!del) {
711  R result = (*function_)(a1,a2);
712  return result;
713  } else {
714  R result = (*function_)(a1,a2);
715  // zero out the pointer to ensure segfault if used again
716  function_ = NULL;
717  delete this;
718  return result;
719  }
720  }
721 };
722 
723 template <bool del, class A1, class A2>
724 class _TessFunctionResultCallback_0_2<del, void, A1, A2>
725  : public TessCallback2<A1,A2> {
726  public:
728  typedef void (*FunctionSignature)(A1,A2);
729 
730  private:
731  FunctionSignature function_;
732 
733  public:
735  FunctionSignature function)
736  : function_(function) {
737  }
738 
739  virtual void Run(A1 a1,A2 a2) {
740  if (!del) {
741  (*function_)(a1,a2);
742  } else {
743  (*function_)(a1,a2);
744  // zero out the pointer to ensure segfault if used again
745  function_ = NULL;
746  delete this;
747  }
748  }
749 };
750 
751 template <class R, class A1, class A2>
753 NewTessCallback(R (*function)(A1,A2)) {
755 }
756 
757 template <class R, class A1, class A2>
759 NewPermanentTessCallback(R (*function)(A1,A2)) {
761 }
762 
763 template <class A1,class A2,class A3>
765  public:
766  virtual ~TessCallback3() { }
767  virtual void Run(A1,A2,A3) = 0;
768 };
769 
770 template <class R, class A1,class A2,class A3>
772  public:
773  virtual ~TessResultCallback3() { }
774  virtual R Run(A1,A2,A3) = 0;
775 };
776 
777 template <bool del, class R, class T, class A1, class A2, class A3>
779  public:
781  typedef R (T::*MemberSignature)(A1,A2,A3) const;
782 
783  private:
784  const T* object_;
785  MemberSignature member_;
786 
787  public:
789  const T* object, MemberSignature member)
790  : object_(object),
791  member_(member) {
792  }
793 
794  virtual R Run(A1 a1,A2 a2,A3 a3) {
795  if (!del) {
796  R result = (object_->*member_)(a1,a2,a3);
797  return result;
798  } else {
799  R result = (object_->*member_)(a1,a2,a3);
800  // zero out the pointer to ensure segfault if used again
801  member_ = NULL;
802  delete this;
803  return result;
804  }
805  }
806 };
807 
808 template <bool del, class T, class A1, class A2, class A3>
809 class _ConstTessMemberResultCallback_0_3<del, void, T, A1, A2, A3>
810  : public TessCallback3<A1,A2,A3> {
811  public:
813  typedef void (T::*MemberSignature)(A1,A2,A3) const;
814 
815  private:
816  const T* object_;
817  MemberSignature member_;
818 
819  public:
821  const T* object, MemberSignature member)
822  : object_(object),
823  member_(member) {
824  }
825 
826  virtual void Run(A1 a1,A2 a2,A3 a3) {
827  if (!del) {
828  (object_->*member_)(a1,a2,a3);
829  } else {
830  (object_->*member_)(a1,a2,a3);
831  // zero out the pointer to ensure segfault if used again
832  member_ = NULL;
833  delete this;
834  }
835  }
836 };
837 
838 #ifndef SWIG
839 template <class T1, class T2, class R, class A1, class A2, class A3>
842  const T1* obj, R (T2::*member)(A1,A2,A3) const) {
844  obj, member);
845 }
846 #endif
847 
848 #ifndef SWIG
849 template <class T1, class T2, class R, class A1, class A2, class A3>
852  const T1* obj, R (T2::*member)(A1,A2,A3) const) {
854  obj, member);
855 }
856 #endif
857 
858 template <bool del, class R, class T, class A1, class A2, class A3>
860  public:
862  typedef R (T::*MemberSignature)(A1,A2,A3) ;
863 
864  private:
865  T* object_;
866  MemberSignature member_;
867 
868  public:
870  T* object, MemberSignature member)
871  : object_(object),
872  member_(member) {
873  }
874 
875  virtual R Run(A1 a1,A2 a2,A3 a3) {
876  if (!del) {
877  R result = (object_->*member_)(a1,a2,a3);
878  return result;
879  } else {
880  R result = (object_->*member_)(a1,a2,a3);
881  // zero out the pointer to ensure segfault if used again
882  member_ = NULL;
883  delete this;
884  return result;
885  }
886  }
887 };
888 
889 template <bool del, class T, class A1, class A2, class A3>
890 class _TessMemberResultCallback_0_3<del, void, T, A1, A2, A3>
891  : public TessCallback3<A1,A2,A3> {
892  public:
894  typedef void (T::*MemberSignature)(A1,A2,A3) ;
895 
896  private:
897  T* object_;
898  MemberSignature member_;
899 
900  public:
902  T* object, MemberSignature member)
903  : object_(object),
904  member_(member) {
905  }
906 
907  virtual void Run(A1 a1,A2 a2,A3 a3) {
908  if (!del) {
909  (object_->*member_)(a1,a2,a3);
910  } else {
911  (object_->*member_)(a1,a2,a3);
912  // zero out the pointer to ensure segfault if used again
913  member_ = NULL;
914  delete this;
915  }
916  }
917 };
918 
919 #ifndef SWIG
920 template <class T1, class T2, class R, class A1, class A2, class A3>
923  T1* obj, R (T2::*member)(A1,A2,A3) ) {
925  obj, member);
926 }
927 #endif
928 
929 #ifndef SWIG
930 template <class T1, class T2, class R, class A1, class A2, class A3>
933  T1* obj, R (T2::*member)(A1,A2,A3) ) {
935  obj, member);
936 }
937 #endif
938 
939 template <bool del, class R, class A1, class A2, class A3>
941  public:
943  typedef R (*FunctionSignature)(A1,A2,A3);
944 
945  private:
946  FunctionSignature function_;
947 
948  public:
950  FunctionSignature function)
951  : function_(function) {
952  }
953 
954  virtual R Run(A1 a1,A2 a2,A3 a3) {
955  if (!del) {
956  R result = (*function_)(a1,a2,a3);
957  return result;
958  } else {
959  R result = (*function_)(a1,a2,a3);
960  // zero out the pointer to ensure segfault if used again
961  function_ = NULL;
962  delete this;
963  return result;
964  }
965  }
966 };
967 
968 template <bool del, class A1, class A2, class A3>
969 class _TessFunctionResultCallback_0_3<del, void, A1, A2, A3>
970  : public TessCallback3<A1,A2,A3> {
971  public:
973  typedef void (*FunctionSignature)(A1,A2,A3);
974 
975  private:
976  FunctionSignature function_;
977 
978  public:
980  FunctionSignature function)
981  : function_(function) {
982  }
983 
984  virtual void Run(A1 a1,A2 a2,A3 a3) {
985  if (!del) {
986  (*function_)(a1,a2,a3);
987  } else {
988  (*function_)(a1,a2,a3);
989  // zero out the pointer to ensure segfault if used again
990  function_ = NULL;
991  delete this;
992  }
993  }
994 };
995 
996 template <class R, class A1, class A2, class A3>
998 NewTessCallback(R (*function)(A1,A2,A3)) {
1000 }
1001 
1002 template <class R, class A1, class A2, class A3>
1004 NewPermanentTessCallback(R (*function)(A1,A2,A3)) {
1006 }
1007 
1008 // Specified by TR1 [4.7.2] Reference modifications.
1009 template <class T> struct remove_reference;
1010 template<typename T> struct remove_reference { typedef T type; };
1011 template<typename T> struct remove_reference<T&> { typedef T type; };
1012 
1013 // Identity<T>::type is a typedef of T. Useful for preventing the
1014 // compiler from inferring the type of an argument in templates.
1015 template <typename T>
1016 struct Identity {
1017  typedef T type;
1018 };
1019 
1020 template <bool del, class R, class T, class P1, class A1, class A2, class A3>
1022  : public TessResultCallback3<R,A1,A2,A3> {
1023  public:
1025  typedef R (T::*MemberSignature)(P1,A1,A2,A3) const;
1026 
1027  private:
1028  T* object_;
1029  MemberSignature member_;
1030  typename remove_reference<P1>::type p1_;
1031 
1032  public:
1034  MemberSignature member, P1 p1)
1035  : object_(object), member_(member), p1_(p1) { }
1036 
1037  virtual R Run(A1 a1, A2 a2, A3 a3) {
1038  if (!del) {
1039  R result = (object_->*member_)(p1_,a1,a2,a3);
1040  return result;
1041  } else {
1042  R result = (object_->*member_)(p1_,a1,a2,a3);
1043  // zero out the pointer to ensure segfault if used again
1044  member_ = NULL;
1045  delete this;
1046  return result;
1047  }
1048  }
1049 };
1050 
1051 template <bool del, class T, class P1, class A1, class A2, class A3>
1052 class _ConstTessMemberResultCallback_1_3<del, void, T, P1, A1, A2, A3>
1053  : public TessCallback3<A1,A2,A3> {
1054  public:
1056  typedef void (T::*MemberSignature)(P1,A1,A2,A3) const;
1057 
1058  private:
1059  T* object_;
1060  MemberSignature member_;
1061  typename remove_reference<P1>::type p1_;
1062 
1063  public:
1065  MemberSignature member, P1 p1)
1066  : object_(object), member_(member), p1_(p1) { }
1067 
1068  virtual void Run(A1 a1, A2 a2, A3 a3) {
1069  if (!del) {
1070  (object_->*member_)(p1_,a1,a2,a3);
1071  } else {
1072  (object_->*member_)(p1_,a1,a2,a3);
1073  // zero out the pointer to ensure segfault if used again
1074  member_ = NULL;
1075  delete this;
1076  }
1077  }
1078 };
1079 
1080 #ifndef SWIG
1081 template <class T1, class T2, class R, class P1, class A1, class A2, class A3>
1083 NewTessCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3) , typename Identity<P1>::type p1) {
1085 }
1086 #endif
1087 
1088 #ifndef SWIG
1089 template <class T1, class T2, class R, class P1, class A1, class A2, class A3>
1091 NewPermanentTessCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3) , typename Identity<P1>::type p1) {
1093 }
1094 #endif
1095 
1096 template <bool del, class R, class T, class P1, class A1, class A2, class A3>
1098  public:
1100  typedef R (T::*MemberSignature)(P1,A1,A2,A3) ;
1101 
1102  private:
1103  T* object_;
1104  MemberSignature member_;
1105  typename remove_reference<P1>::type p1_;
1106 
1107  public:
1109  MemberSignature member, P1 p1)
1110  : object_(object), member_(member), p1_(p1) { }
1111 
1112  virtual R Run(A1 a1, A2 a2, A3 a3) {
1113  if (!del) {
1114  R result = (object_->*member_)(p1_,a1,a2,a3);
1115  return result;
1116  } else {
1117  R result = (object_->*member_)(p1_,a1,a2,a3);
1118  // zero out the pointer to ensure segfault if used again
1119  member_ = NULL;
1120  delete this;
1121  return result;
1122  }
1123  }
1124 };
1125 
1126 template <bool del, class T, class P1, class A1, class A2, class A3>
1127 class _TessMemberResultCallback_1_3<del, void, T, P1, A1, A2, A3>
1128  : public TessCallback3<A1,A2,A3> {
1129  public:
1131  typedef void (T::*MemberSignature)(P1,A1,A2,A3) ;
1132 
1133  private:
1134  T* object_;
1135  MemberSignature member_;
1136  typename remove_reference<P1>::type p1_;
1137 
1138  public:
1140  MemberSignature member, P1 p1)
1141  : object_(object), member_(member), p1_(p1) { }
1142 
1143  virtual void Run(A1 a1, A2 a2, A3 a3) {
1144  if (!del) {
1145  (object_->*member_)(p1_,a1,a2,a3);
1146  } else {
1147  (object_->*member_)(p1_,a1,a2,a3);
1148  // zero out the pointer to ensure segfault if used again
1149  member_ = NULL;
1150  delete this;
1151  }
1152  }
1153 };
1154 
1155 #ifndef SWIG
1156 template <class T1, class T2, class R, class P1, class A1, class A2, class A3>
1158 NewTessCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3) , typename Identity<P1>::type p1) {
1159  return new _TessMemberResultCallback_1_3<true,R,T1,P1,A1,A2,A3>(obj, member, p1);
1160 }
1161 #endif
1162 
1163 #ifndef SWIG
1164 template <class T1, class T2, class R, class P1, class A1, class A2, class A3>
1166 NewPermanentTessCallback( T1* obj, R (T2::*member)(P1,A1,A2,A3) , typename Identity<P1>::type p1) {
1167  return new _TessMemberResultCallback_1_3<false,R,T1,P1,A1,A2,A3>(obj, member, p1);
1168 }
1169 #endif
1170 
1171 template <bool del, class R, class P1, class A1, class A2, class A3>
1173  public:
1175  typedef R (*FunctionSignature)(P1,A1,A2,A3);
1176 
1177  private:
1178  FunctionSignature function_;
1179  typename remove_reference<P1>::type p1_;
1180 
1181  public:
1183  : function_(function), p1_(p1) { }
1184 
1185  virtual R Run(A1 a1, A2 a2, A3 a3) {
1186  if (!del) {
1187  R result = (*function_)(p1_,a1,a2,a3);
1188  return result;
1189  } else {
1190  R result = (*function_)(p1_,a1,a2,a3);
1191  // zero out the pointer to ensure segfault if used again
1192  function_ = NULL;
1193  delete this;
1194  return result;
1195  }
1196  }
1197 };
1198 
1199 template <bool del, class P1, class A1, class A2, class A3>
1200 class _TessFunctionResultCallback_1_3<del, void, P1, A1, A2, A3>
1201  : public TessCallback3<A1,A2,A3> {
1202  public:
1204  typedef void (*FunctionSignature)(P1,A1,A2,A3);
1205 
1206  private:
1207  FunctionSignature function_;
1208  typename remove_reference<P1>::type p1_;
1209 
1210  public:
1212  : function_(function), p1_(p1) { }
1213 
1214  virtual void Run(A1 a1, A2 a2, A3 a3) {
1215  if (!del) {
1216  (*function_)(p1_,a1,a2,a3);
1217  } else {
1218  (*function_)(p1_,a1,a2,a3);
1219  // zero out the pointer to ensure segfault if used again
1220  function_ = NULL;
1221  delete this;
1222  }
1223  }
1224 };
1225 
1226 template <class R, class P1, class A1, class A2, class A3>
1228 NewTessCallback(R (*function)(P1,A1,A2,A3), typename Identity<P1>::type p1) {
1229  return new _TessFunctionResultCallback_1_3<true,R,P1,A1,A2,A3>(function, p1);
1230 }
1231 
1232 template <class R, class P1, class A1, class A2, class A3>
1234 NewPermanentTessCallback(R (*function)(P1,A1,A2,A3), typename Identity<P1>::type p1) {
1236 }
1237 
1238 #endif /* _TESS_CALLBACK_SPECIALIZATIONS_H */