File: foo.h

package info (click to toggle)
pybindgen 0.20.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: python: 15,981; cpp: 1,889; ansic: 617; makefile: 86; sh: 4
file content (1345 lines) | stat: -rw-r--r-- 31,232 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
// -*- Mode: C++; c-file-style: "stroustrup"; indent-tabs-mode:nil; -*-
#ifndef   	FOO_H_
# define   	FOO_H_

#include <Python.h>
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <exception>
#include <algorithm>
#include <stdexcept>

#include <stdint.h>

// Deprecation warnings look ugly and confusing; better to just
// disable them and change this macro when we want to specifically
// test them.
#define ENABLE_DEPRECATIONS 0

#ifndef DEPRECATED
# if ENABLE_DEPRECATIONS && __GNUC__ > 2
#  define DEPRECATED  __attribute__((deprecated))
# else
#  define DEPRECATED
# endif
#endif

// Yes, this code is stupid, I know; it is only meant as an example!

int print_something(const char *message) DEPRECATED;
int print_something_else(const char *message2);

/* -#- name=get_int -#- */
int get_int_from_string(const char *from_string, int multiplier=1);
// -#- name=get_int; @multiplier(default_value=1) -#-
int get_int_from_float(double from_float, int multiplier);

// In this example PointerHolder<T> automatically implies
// caller_owns_return=True when used as ReturnValue, and
// transfer_ownership=False when used as parameter.
template <typename T>
struct PointerHolder
{
    T *thePointer;
};


// -#- automatic_type_narrowing=True -#-
class Foo
{
    std::string m_datum;
    bool m_initialized;
public:
    static int instance_count;

    Foo () : m_datum (""), m_initialized (false)
        { Foo::instance_count++; }

    Foo (int xpto)  DEPRECATED : m_initialized (false) { xpto++; }

    Foo (std::string const &datum) : m_datum (datum), m_initialized (false)
        { Foo::instance_count++; }
    const std::string get_datum () const { return m_datum; }

    std::string get_datum_deprecated () const DEPRECATED { return m_datum; }

    Foo (Foo const & other) : m_datum (other.get_datum ()), m_initialized (false)
        { Foo::instance_count++; }

    void initialize () { m_initialized = true; }
    bool is_initialized () const { return m_initialized; }

    virtual ~Foo() { Foo::instance_count--; }

    static int add_sub (int a, int b=3, bool subtract=false)
        {
            return a+b;
        }
};

inline std::ostream & operator << (std::ostream &os, Foo const &foo)
{
    os << foo.get_datum ();
    return os;
}

inline bool is_unique(const Foo& foo)
{
    return foo.instance_count == 1;
}

// -#- automatic_type_narrowing=True -#-
class Zoo
{
    std::string m_datum;
public:
    Zoo () : m_datum ("")
        {}
    Zoo (std::string datum) : m_datum (datum)
        {}
    virtual ~Zoo() {}
    std::string get_datum () const { return m_datum; }

    operator Foo() const {
        return Foo(m_datum);
    }
};


class ClassThatTakesFoo
{
    Foo m_foo;
public:
    ClassThatTakesFoo(Foo foo) : m_foo(foo) {}
    Foo get_foo () const { return m_foo; }
};

extern Foo g_foo;

void function_that_takes_foo(Foo foo);
Foo function_that_returns_foo();


class Bar : public Foo
{
public:
    static std::string Hooray () {
        return std::string ("Hooray!");
    }
    virtual ~Bar() {}
};

// caller owns return
// -#- @return(caller_owns_return=true) -#-
Foo* get_hidden_subclass_pointer ();

// -#- incref_method=Ref; decref_method=Unref; peekref_method=GetReferenceCount -#-
class Zbr
{
    int m_refcount;
    std::string m_datum;
public:
    Zbr () : m_refcount (1), m_datum ("")
        { Zbr::instance_count++; }
    Zbr (std::string datum) :  m_refcount (1), m_datum (datum)
        { Zbr::instance_count++; }

    std::string get_datum () const { return m_datum; }

    Zbr (Zbr const & other) :
        m_refcount (1), m_datum (other.get_datum ())
        {Zbr::instance_count++;}

    void Ref () {
        // std::cerr << "Ref Zbr " << this << " from " << m_refcount << std::endl;
        ++m_refcount;
    }
    void Unref () {
        // std::cerr << "Unref Zbr " << this << " from " << m_refcount << std::endl;
        if (--m_refcount == 0)
            delete this;
    }
    int GetReferenceCount () const { return m_refcount; }

    virtual int get_int (int x) {
        return x;
    }

    static int instance_count;

    virtual ~Zbr () {
        --Zbr::instance_count;
    }

    // -#- @foobaz(transfer_ownership=true, direction=out) -#-
    int get_value (int* foobaz) { *foobaz = 123; return -1; }
};

// -#- @zbr(transfer_ownership=true) -#-
void store_zbr (Zbr *zbr);
int invoke_zbr (int x);
void delete_stored_zbr (void);


// -#- allow_subclassing=true -#-
class Foobar
{
    Foobar (const Foobar &);
    Foobar& operator= (const Foobar &);

public:
    static int instance_count;

    Foobar ()
        { Foobar::instance_count++; }

    virtual ~Foobar() { Foobar::instance_count--; }
};


class SomeObject
{
public:
    std::string m_prefix;

    enum {
        TYPE_FOO,
        TYPE_BAR,
    } type;

    static int instance_count;


    // A nested class
    // -#- automatic_type_narrowing=True -#-
    class NestedClass
    {
        std::string m_datum;
    public:
        static int instance_count;

        NestedClass () : m_datum ("")
            { Foo::instance_count++; }
        NestedClass (std::string datum) : m_datum (datum)
            { Foo::instance_count++; }
        std::string get_datum () const { return m_datum; }

        NestedClass (NestedClass const & other) : m_datum (other.get_datum ())
            { Foo::instance_count++; }

        virtual ~NestedClass() { NestedClass::instance_count--; }
    };

    // A nested enum
    enum NestedEnum {
        FOO_TYPE_AAA,
        FOO_TYPE_BBB,
        FOO_TYPE_CCC,
    };


    // An anonymous nested enum
    enum  {
        CONSTANT_A,
        CONSTANT_B,
        CONSTANT_C
    };


private:
    Foo m_foo_value;
    Foo *m_foo_ptr;
    Foo *m_foo_shared_ptr;
    Zbr *m_zbr;
    Zbr *m_internal_zbr;

    PyObject *m_pyobject;
    Foobar *m_foobar;

    SomeObject ();

public:

    static std::string staticData;

    virtual ~SomeObject ();
    SomeObject (const SomeObject &other);
    SomeObject (std::string const prefix);
    SomeObject (int prefix_len);

    // -#- @message(direction=inout) -#-
    int add_prefix (std::string& message) {
        message = m_prefix + message;
        return message.size ();
    }

    // -#- @message(direction=inout) -#-
    int operator() (std::string& message) {
        message = m_prefix + message;
        return message.size ();
    }

    // --------  Virtual methods ----------
    virtual std::string get_prefix () const {
        return m_prefix;
    }

    std::string call_get_prefix () const {
        return get_prefix();
    }

    virtual std::string get_prefix_with_foo_value (Foo foo) const {
        return m_prefix + foo.get_datum();
    }

    // -#- @foo(direction=inout) -#-
    virtual std::string get_prefix_with_foo_ref (const Foo &foo) const {
        return m_prefix + foo.get_datum ();
    }

    virtual std::string get_prefix_with_foo_ptr (const Foo *foo) const {
        return m_prefix + foo->get_datum ();
    }


    // A couple of overloaded virtual methods
    virtual std::string get_something () const {
        return "something";
    }
    virtual std::string get_something (int x) const {
        std::stringstream out;
        out << x;
        return out.str ();
    }

    // -#- @pyobject(transfer_ownership=false) -#-
    virtual void set_pyobject (PyObject *pyobject) {
        if (m_pyobject) {
            Py_DECREF(m_pyobject);
        }
        Py_INCREF(pyobject);
        m_pyobject = pyobject;
    }

    // -#- @return(caller_owns_return=true) -#-
    virtual PyObject* get_pyobject (void) {
        if (m_pyobject) {
            Py_INCREF(m_pyobject);
            return m_pyobject;
        } else {
            return NULL;
        }
    }

    // pass by value, direction=in
    void set_foo_value (Foo foo) {
        m_foo_value = foo;
    }

    // pass by reference, direction=in
    void set_foo_by_ref (const Foo& foo) {
        m_foo_value = foo;
    }

    // pass by reference, direction=out
    // -#- @foo(direction=out) -#-
    void get_foo_by_ref (Foo& foo) {
        foo = m_foo_value;
    }

    // -#- @foo(transfer_ownership=true) -#-
    void set_foo_ptr (Foo *foo) {
        if (m_foo_ptr)
            delete m_foo_ptr;
        m_foo_ptr = foo;
    }

    // -#- @foo(transfer_ownership=false) -#-
    void set_foo_shared_ptr (Foo *foo) {
        m_foo_shared_ptr = foo;
    }

    // return value
    Foo get_foo_value () {
        return m_foo_value;
    }

    // -#- @return(caller_owns_return=false) -#-
    const Foo * get_foo_shared_ptr () {
        return m_foo_shared_ptr;
    }

    // -#- @return(caller_owns_return=true) -#-
    Foo * get_foo_ptr () {
        Foo *foo = m_foo_ptr;
        m_foo_ptr = NULL;
        return foo;
    }

    // -#- @return(caller_owns_return=true) -#-
    Zbr* get_zbr () {
        if (m_zbr)
        {
            m_zbr->Ref ();
            return m_zbr;
        } else
            return NULL;
    }

    // -#- @return(caller_owns_return=true) -#-
    Zbr* get_internal_zbr () {
        m_internal_zbr->Ref ();
        return m_internal_zbr;
    }

    // return reference counted object, caller does not own return
    // -#- @return(caller_owns_return=false) -#-
    Zbr* peek_zbr () { return m_zbr; }

    // pass reference counted object, transfer ownership
    // -#- @zbr(transfer_ownership=true) -#-
    void set_zbr_transfer (Zbr *zbr) {
        if (m_zbr)
            m_zbr->Unref ();
        m_zbr = zbr;
    }

    // pass reference counted object, does not transfer ownership
    // -#- @zbr(transfer_ownership=false) -#-
    void set_zbr_shared (Zbr *zbr) {
        if (m_zbr)
            m_zbr->Unref ();
        zbr->Ref ();
        m_zbr = zbr;
    }


    // return reference counted object, caller does not own return
    PointerHolder<Zbr> get_zbr_pholder () {
        PointerHolder<Zbr> foo = { m_zbr };
        m_zbr->Ref ();
        return foo;
    }

    // pass reference counted object, transfer ownership
    void set_zbr_pholder (PointerHolder<Zbr> zbr) {
        if (m_zbr)
            m_zbr->Unref ();
        m_zbr = zbr.thePointer;
        m_zbr->Ref ();
    }

    int get_int (const char *from_string);
    int get_int (double from_float);

    // custodian/ward tests

    // -#- @return(custodian=0, reference_existing_object=true) -#-
    Foobar* get_foobar_with_self_as_custodian () {
        if (m_foobar == NULL) {
            m_foobar = new Foobar;
        }
        return m_foobar;
    }
    // -#- @return(custodian=1, reference_existing_object=true); @other(transfer_ownership=false) -#-
    Foobar* get_foobar_with_other_as_custodian (SomeObject *other) {
        return other->get_foobar_with_self_as_custodian ();
    }
    // -#- @foobar(custodian=0, transfer_ownership=True) -#-
    void set_foobar_with_self_as_custodian (Foobar *foobar) {
        delete m_foobar;
        m_foobar = foobar;
    }

    virtual const char* method_returning_cstring() const { return "foobar"; }

protected:
    std::string protected_method_that_is_not_virtual (std::string arg) const;
};


// A function that will appear as a method of SomeObject
// -#- as_method=get_something_prefixed; of_class=SomeObject -#-
// -#- @obj(transfer_ownership=false) -#-
std::string some_object_get_something_prefixed(const SomeObject *obj, const std::string something);

// -#- as_method=val_get_something_prefixed; of_class=SomeObject -#-
std::string some_object_val_get_something_prefixed(SomeObject obj, const std::string something);
// -#- as_method=ref_get_something_prefixed; of_class=SomeObject -#-
std::string some_object_ref_get_something_prefixed(const SomeObject &obj, const std::string something);


// Transfer ownership of 'obj' to the library
// -#- @obj(transfer_ownership=true) -#-
void store_some_object(SomeObject *obj);

// Invokes the virtual method in the stored SomeObject
std::string invoke_some_object_get_prefix();

// Transfer ownership of 'obj' away from the library
// -#- @return(caller_owns_return=true) -#-
SomeObject* take_some_object();

// Deletes the contained object, if any
void delete_some_object();


namespace xpto
{
    typedef uint32_t FlowId;
    FlowId get_flow_id (FlowId flowId);

    std::string some_function();

    class SomeClass
    {
    public:
        SomeClass() {}
    };

    enum FooType {
        FOO_TYPE_AAA,
        FOO_TYPE_BBB,
        FOO_TYPE_CCC,
    };

    FooType get_foo_type ();
    void set_foo_type (FooType type);

    // -#- @type(direction=inout) -#-
    void set_foo_type_ptr (FooType *type);

    // -#- @type(direction=inout) -#-
    void set_foo_type_inout (FooType &type);

    typedef Foo FooXpto;

    std::string get_foo_datum(FooXpto const &foo);

    struct XptoClass
    {
        // -#- @return(caller_owns_return=true) -#-
        SomeClass* GetSomeClass()
            {
                return NULL;
            }
    };
}

// -#- @return(custodian=1, reference_existing_object=true); @other(transfer_ownership=false) -#-
Foobar* get_foobar_with_other_as_custodian(SomeObject *other);

// -#- @return(caller_owns_return=true) -#-
Foobar* create_new_foobar();
// -#- @foobar(custodian=2, transfer_ownership=true); @other(transfer_ownership=false) -#-
void set_foobar_with_other_as_custodian(Foobar *foobar, SomeObject *other);
// -#- @foobar(custodian=-1, transfer_ownership=true); @return(caller_owns_return=true) -#-
SomeObject * set_foobar_with_return_as_custodian(Foobar *foobar);

// -#- is_singleton=true -#-
class SingletonClass
{
private:
    static SingletonClass *m_instance;

    SingletonClass () {}
    ~SingletonClass () {}

public:
    // -#- @return(caller_owns_return=true) -#-
    static SingletonClass *GetInstance () {
            if (!m_instance)
                m_instance = new SingletonClass;
            return m_instance;
        }
};


class InterfaceId
{
public:
    ~InterfaceId () {}
private:
    InterfaceId () {}
    friend InterfaceId make_interface_id ();
    // -#- ignore -#-
    friend InterfaceId make_object_interface_id ();
};

InterfaceId make_interface_id ();

template <typename T> std::string TypeNameGet (void)
{
  return "unknown";
}


// -#- template_instance_names=int=>IntegerTypeNameGet -#-
template <> std::string TypeNameGet<int> (void);


// just to force a template instantiation
struct __foo__
{
     std::string get ()
        {
            return TypeNameGet<int> ();
        }
};


// Test code generation errors and error handling

class CannotBeConstructed
{
public:
    ~CannotBeConstructed () {}

    // This static method cannot be generated
    static CannotBeConstructed get_value () {
        return CannotBeConstructed ();
    }

    // This static method can be generated because caller-owns-return=true
    // -#- @return(caller_owns_return=true) -#-
    static CannotBeConstructed* get_ptr () {
        return new CannotBeConstructed ();
    }
private:
    CannotBeConstructed () {}
};

// This function cannot be generated
inline CannotBeConstructed get_cannot_be_constructed_value () {
    return CannotBeConstructed::get_value ();
}

// This static method can be generated because caller-owns-return=true
// -#- @return(caller_owns_return=true) -#-
inline CannotBeConstructed* get_cannot_be_constructed_ptr () {
    return CannotBeConstructed::get_ptr ();
}

class AbstractBaseClass
{
public:
    virtual ~AbstractBaseClass () {}

protected:
    // A pure virtual method with a parameter type so strange that it
    // cannot be possibly be automatically wrapped by pybindgen; this
    // will cause the cannot_be_constructed flag on the class to be
    // set to true, and allow us to test code generation error
    // handling (see below).
    virtual void do_something (char ****) = 0;

    AbstractBaseClass () {}
};

class AbstractBaseClassImpl : public AbstractBaseClass
{
public:
    virtual ~AbstractBaseClassImpl () {}

    // -#- @return(caller_owns_return=true) -#-
    static AbstractBaseClass* get_abstract_base_class_ptr1 ()
        {
            return new AbstractBaseClassImpl;
        }

    // This method will be scanned by gccxmlparser and generate an error
    // that is only detected in code generation time.
    // -#- @return(caller_owns_return=false) -#-
    static AbstractBaseClass* get_abstract_base_class_ptr2 ()
        {
            static AbstractBaseClassImpl *singleton = NULL;
            if (!singleton)
                singleton = new AbstractBaseClassImpl;
            return singleton;
        }

protected:
    virtual void do_something (char ****) {}

    AbstractBaseClassImpl () {}
};


// -#- @return(caller_owns_return=true) -#-
inline AbstractBaseClass* get_abstract_base_class_ptr1 ()
{
    return AbstractBaseClassImpl::get_abstract_base_class_ptr1 ();
}

// This function will be scanned by gccxmlparser and generate an error
// that is only detected in code generation time.
// -#- @return(caller_owns_return=false) -#-
inline AbstractBaseClass* get_abstract_base_class_ptr2 ()
{
    static AbstractBaseClass *singleton = NULL;
    if (!singleton)
        singleton = AbstractBaseClassImpl::get_abstract_base_class_ptr1 ();
    return singleton;
}


// Class to test private/protected virtual methods
class AbstractBaseClass2
{
protected:
    AbstractBaseClass2 () {}

public:
    virtual ~AbstractBaseClass2 () {}

    int invoke_private_virtual (int x) const {
        return private_virtual (x);
    }

    int invoke_protected_virtual (int x) const {
        return protected_virtual (x);
    }

    int invoke_protected_pure_virtual (int x) const {
        return protected_pure_virtual (x);
    }

protected:
    virtual int protected_virtual (int x) const { return x+1; }

    virtual int protected_pure_virtual (int x) const = 0;

private:
    virtual int private_virtual (int x) const = 0;

    AbstractBaseClass2 (const AbstractBaseClass2 &other) { other.invoke_protected_virtual(0); }
};

// -#- allow_subclassing=true -#-
class AbstractXpto
{
public:
    AbstractXpto () {}
    virtual ~AbstractXpto () {}

    virtual void something (int x) const = 0;
};

class AbstractXptoImpl : public AbstractXpto
{
public:
    AbstractXptoImpl () {}

    virtual void something (int x) const { x++; }
};


// Test anonymous structures
union Word
{
    uint16_t word;
    struct
    {
        uint8_t low, high;
    };
};

// Test float array
// -#- @matrix(direction=in, array_length=6) -#-
float matrix_sum_of_elements (float *matrix);

// -#- @matrix(direction=out, array_length=6) -#-
void matrix_identity_new (float *matrix);

namespace TopNs
{

    class OuterBase
    {
    public:
    };

    namespace PrefixBottomNs {
        class PrefixInner : public OuterBase
        {
        public:
            PrefixInner () {}
            void Do (void) {}
        };
    }

}


// Bug #245097
typedef void (*Callback) (void);
void function_that_takes_callback (Callback cb);


// <Bug #246069>
struct Socket
{
    virtual int Bind () { return -1; }
    virtual int Bind (int address) { return address; }

    virtual ~Socket () {}
};

struct UdpSocket : public Socket
{
    virtual int Bind () { return 0; }
};
// </Bug #246069>


struct simple_struct_t
{
    int xpto;
};

// -- Containers:

typedef std::vector<simple_struct_t> SimpleStructList;
typedef std::vector<simple_struct_t> SimpleStructVec;
typedef std::map<std::string, simple_struct_t> SimpleStructMap;


SimpleStructList get_simple_list ();
int set_simple_list (SimpleStructList list);

class TestContainer
{
public:

    std::set<float> m_floatSet;

    TestContainer () : m_vec (NULL) {
        m_floatSet.insert (1.0);
        m_floatSet.insert (2.0);
        m_floatSet.insert (3.0);
    }
    virtual ~TestContainer () {
        delete m_vec;
    }

    virtual SimpleStructList get_simple_list ();
    virtual int set_simple_list (SimpleStructList list);

    // -#- @inout_list(direction=inout) -#-
    virtual int set_simple_list_by_ref (SimpleStructList &inout_list);

    virtual SimpleStructVec get_simple_vec ();
    virtual int set_simple_vec (SimpleStructVec vec);

    virtual SimpleStructMap get_simple_map ();
    virtual int set_simple_map (SimpleStructMap map);

    // -#- @outVec(direction=out) -#-
    void get_vec (std::vector<std::string> &outVec);

    // -#- @inVec(direction=in, transfer_ownership=true) -#-
    void set_vec_ptr (std::vector<std::string> *inVec);

    // -#- @outVec(direction=out) -#-
    void get_vec_ptr (std::vector<std::string> *outVec);

private:
    SimpleStructList m_simpleList;
    SimpleStructMap m_simpleMap;

    std::vector<std::string> *m_vec;

};

std::map<std::string, int> get_map ();

std::set<uint32_t> get_set ();


// test binary operators

struct Tupl
{
    int x, y;

    inline Tupl operator * (Tupl const &b)
        {
            Tupl retval;
            retval.x = x * b.x;
            retval.y = y * b.y;
            return retval;
        }

    inline Tupl operator / (Tupl const &b)
        {
            Tupl retval;
            retval.x = x / b.x;
            retval.y = y / b.y;
            return retval;
        }

    inline bool operator == (Tupl const &b)
        {
            return (x == b.x && y == b.y);
        }

    inline bool operator != (Tupl const &b)
        {
            return (x != b.x || y != b.y);
        }


    inline Tupl operator - ()
        {
            Tupl retval;
            retval.x = -x;
            retval.y = -y;
            return retval;
        }

};

inline bool operator < (Tupl const &a, Tupl const &b)
{
    return (a.x < b.x || (a.x == b.x && a.y < b.y));
}

inline bool operator <= (Tupl const &a, Tupl const &b)
{
    return (a.x <= b.x || (a.x == b.x && a.y <= b.y));
}

inline bool operator > (Tupl const &a, Tupl const &b)
{
    return (a.x > b.x || (a.x == b.x && a.y > b.y));
}

inline bool operator >= (Tupl const &a, Tupl const &b)
{
    return (a.x >= b.x || (a.x == b.x && a.y >= b.y));
}

inline Tupl operator + (Tupl const &a, Tupl const &b)
{
    Tupl retval;
    retval.x = a.x + b.x;
    retval.y = a.y + b.y;
    return retval;
}

inline Tupl operator - (Tupl const &a, Tupl const &b)
{
    Tupl retval;
    retval.x = a.x - b.x;
    retval.y = a.y - b.y;
    return retval;
}

inline Tupl & operator += (Tupl &a, Tupl const &b)
{
    a.x += b.x;
    a.y += b.y;
    return a;
}

inline Tupl & operator += (Tupl &a, int b)
{
    a.x += b;
    a.y += b;
    return a;
}

inline Tupl & operator -= (Tupl &a, Tupl const &b)
{
    a.x -= b.x;
    a.y -= b.y;
    return a;
}

inline Tupl & operator *= (Tupl &a, Tupl const &b)
{
    a.x *= b.x;
    a.y *= b.y;
    return a;
}

inline Tupl & operator /= (Tupl &a, Tupl const &b)
{
    a.x /= b.x;
    a.y /= b.y;
    return a;
}

class ManipulatedObject
{
private:
    int m_value;

    // disable the copy constructor
    ManipulatedObject (const ManipulatedObject &ctor_arg);

public:
    ManipulatedObject () : m_value (0) {}
    void SetValue (int value) { m_value = value; }
    int GetValue () const { return m_value; }
};


class ReferenceManipulator
{
    ManipulatedObject m_obj;

public:
    ReferenceManipulator () {}
    virtual ~ReferenceManipulator () {}

    int manipulate_object () {
        do_manipulate_object (m_obj);
        return m_obj.GetValue ();
    }

    // -#- @obj(direction=inout) -#-
    virtual void do_manipulate_object (ManipulatedObject &obj) = 0;

};


class VectorLike
{
    std::vector<double> m_vec;

public:
    VectorLike ()
        {
        }
    // -#- name=__len__ -#-
    std::vector<double>::size_type get_len () const
        {
            return m_vec.size ();
        }
    // -#- name=__add__-#-
    VectorLike add_VectorLike(const VectorLike& rhs)
        {
            VectorLike result(*this);
            std::copy(rhs.m_vec.begin(), rhs.m_vec.end(), std::back_inserter(result.m_vec));
            return result;
        }
    // -#- name=__iadd__-#-
    VectorLike& iadd_VectorLike(const VectorLike& rhs)
        {
            std::copy(rhs.m_vec.begin(), rhs.m_vec.end(), std::back_inserter(m_vec));
            return *this;
        }
    // -#- name=__mul__-#-
    VectorLike mul_VectorLike(const unsigned n)
        {
            VectorLike result;
            if (n > 0)
            {
                result.m_vec.reserve(n * m_vec.size());
                for (unsigned i = 0; i != n; ++i)
                {
                    std::copy(m_vec.begin(), m_vec.end(), std::back_inserter(result.m_vec));
                }
            }
            return result;
        }
    // -#- name=__imul__-#-
    VectorLike& imul_VectorLike(const unsigned n)
        {
            if (n > 0)
            {
                const unsigned n0 = m_vec.size();
                m_vec.reserve(n * n0);
                for (unsigned i = 0; i < n - 1; ++i)
                {
                    std::copy(m_vec.begin(), m_vec.begin() + n0, std::back_inserter(m_vec));
                }
            }
            else
            {
                *this = VectorLike();
            }
            return *this;
        }
    // -#- name=__setitem__ -#-
    int set_item (int index, double value)
        {
            const int n = this->get_len();
            index = (index < 0 ? (n + 1 + index) : index);
            if (index >= n) return -1;
            m_vec[index] = value;
            return 0;
        }
    // -#- name=__getitem__ -#-
    double get_item (int index) const
        {
            const int n = this->get_len();
            index = (index < 0 ? (n + 1 + index) : index);
            try
            {
                return m_vec.at(index);
            }
            catch (std::out_of_range)
            {
                PyErr_SetString(PyExc_IndexError, "Container index out of range");
                return 0.0;
            }
        }
    // -#- name=__setslice__ -#-
    int set_slice (int index1, int index2, const VectorLike& values)
        {
            const int n = this->get_len();
            index1 = (index1 < 0 ? (n + 1 + index1) : index1);
            index2 = (index2 < 0 ? (n + 1 + index2) : index2);
            if (index1 >= n or index2 > n) return -1;
            for (int i = index1; i < index2; ++i)
            {
                if (this->set_item(i, values.get_item(i - index1)) != 0) return -1;
            }
            return 0;
        }
    // -#- name=__getslice__ -#-
    VectorLike get_slice (int index1, int index2) const
        {
            VectorLike result;
            const int n = this->get_len();
            index1 = (index1 < 0 ? (n + 1 + index1) : index1);
            index2 = (index2 < 0 ? (n + 1 + index2) : index2);
            for (int i = index1; i < index2; ++i)
            {
                result.m_vec.push_back(this->get_item(i));
            }
            return result;
        }
    // -#- name=__contains__ -#-
    int contains_value (double value) const
        {
            return ((std::find(m_vec.begin(), m_vec.end(), value) == m_vec.end()) ?
                    0 :
                    1);
        }

    void append (double value)
        {
            m_vec.push_back (value);
        }

    typedef std::vector<double>::iterator Iterator;
    Iterator Begin () { return m_vec.begin (); }
    Iterator End () { return m_vec.end (); }
};



class VectorLike2
{
    std::vector<double> m_vec;

public:
    VectorLike2 ()
        {
        }

    void append (double value)
        {
            m_vec.push_back (value);
        }

    typedef std::vector<double>::iterator Iterator;
    Iterator Begin () { return m_vec.begin (); }
    Iterator End () { return m_vec.end (); }
};


class MapLike
{
    std::map<int, double> m_map;

public:
    MapLike () {}

    void set (int key, double value) { m_map[key] = value; }

    typedef std::map<int, double>::iterator Iterator;
    Iterator Begin () { return m_map.begin (); }
    Iterator End () { return m_map.end (); }
};


// -#- exception -#-
struct Error
{
    std::string message;
};

// -#- exception -#-
struct DomainError : public Error
{
};


// returns 1/x, raises DomainError if x == 0
double my_inverse_func (double x) throw (DomainError);
double my_inverse_func2 (double x) throw (std::exception);

// the following function throws an exception but forgets to declare it
// -#- throw=std::exception -#-
double my_inverse_func3 (double x);

class ClassThatThrows
{
public:
    ClassThatThrows (double x) throw (DomainError);

    // returns 1/x, raises DomainError if x == 0
    double my_inverse_method (double x) throw (DomainError);
    double my_inverse_method2 (double x) throw (std::exception);

    // the following method throws an exception but forgets to declare it
    // -#- throw=std::exception -#-
    double my_inverse_method3 (double x);

    // -#- throw=std::out_of_range -#-
    int throw_out_of_range() throw (std::out_of_range);

    virtual int throw_error () const throw (std::exception);

    virtual ~ClassThatThrows () {}
};


// https://bugs.launchpad.net/pybindgen/+bug/450255
class ProtectedConstructor
{
public:
    ProtectedConstructor() {}
protected:
    // Not to be implemented
    ProtectedConstructor(ProtectedConstructor&);
    void operator=(ProtectedConstructor&);
};



template<typename ValueType>
class property
{
private:
    ValueType m_value;

public:
    property<ValueType> ()
    {
    }

    operator ValueType()

    {
        return m_value;
    }

    const ValueType &operator =(const ValueType &value)
    {
        m_value = value;
        return value;
    }
};

static inline std::string __property_inst()
{
    property<std::string> prop;
    prop = std::string("foo");
    return (std::string) prop;
}



class Box
{
    Foobar m_foobar;

public:
    static int instance_count;

    // -#- return_internal_reference=true -#-
    Foobar *m_internalFoobar;

    Box () { ++instance_count; m_internalFoobar = &m_foobar; }
    virtual ~Box () { --instance_count;}

    // -#- @return(reference_existing_object=true) -#-
    const Foobar* getFoobarInternalPtr () { return &m_foobar; }

    // -#- @return(reference_existing_object=true) -#-
    Foobar& getFoobarInternalRef () { return m_foobar; }

    // -#- @return(return_internal_reference=true) -#-
    Foobar* getFoobarInternalPtr2 () { return &m_foobar; }

    // -#- @return(return_internal_reference=true) -#-
    Foobar& getFoobarInternalRef2 () { return m_foobar; }

};


// multiple inheritance
class MIRoot
{
public:
    MIRoot () {}
    int root_method () const { return -1; }
};


class MIBase1 : public virtual MIRoot
{
    int m_value;
public:
    MIBase1 () : m_value (1) {}
    int base1_method () const { return m_value; }
};

class MIBase2 : public virtual MIRoot
{
    int m_value;
public:
    MIBase2 ()  : m_value (2) {}
    int base2_method () const { return m_value; }
};

class MIMixed : public MIBase1, public MIBase2
{
public:
    MIMixed () {}
    int mixed_method () const { return 3; }
};


Tupl my_throwing_func () throw (std::exception);


class IFoo
{
public:
    virtual void DoSomething() = 0;
protected:
    virtual ~IFoo() {}
};


class IFooImpl : public IFoo
{
public:
    virtual void DoSomething() {}
    ~IFooImpl() {}
};


int test_args_kwargs(const char *args, const char *kwargs);

#endif 	    /* !FOO_H_ */