annotate lib/swig/swigwin-2.0.11/Lib/lua/_std_common.i @ 2353:bb9f180d50f6

Removing a few unsorted_subs includes
author Grumpy7
date Wed, 09 Apr 2014 21:58:09 +0200
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 * _std_common.i
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 * std::helpers for LUA
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 %include <std_except.i> // the general exceptions
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 The basic idea here, is instead of trying to feed SWIG all the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 horribly templated STL code, to give it a neatened version.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 These %defines cover some of the more common methods
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 so the class declarations become just a set of %defines
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 /* #define for basic container features
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 note: I allow front(), back() & pop_back() to throw exceptions
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 upon empty containers, rather than coredump
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 (as we haven't defined the methods, we can use %extend to add with
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 new features)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 %define %STD_CONTAINER_METHODS(CLASS,T)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 public:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 CLASS();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 CLASS(const CLASS&);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 unsigned int size() const;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 unsigned int max_size() const;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 bool empty() const;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 void clear();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 %extend { // the extra stuff which must be checked
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 T front()const throw (std::out_of_range){ // only read front & back
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 if (self->empty())
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 throw std::out_of_range("in "#CLASS"::front()");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 return self->front();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 T back()const throw (std::out_of_range){ // not write to them
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 if (self->empty())
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 throw std::out_of_range("in "#CLASS"::back()");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 return self->back();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 /* push/pop for front/back
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 also note: front & back are read only methods, not used for writing
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 %define %STD_FRONT_ACCESS_METHODS(CLASS,T)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 public:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 void push_front(const T& val);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 %extend { // must check this
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 void pop_front() throw (std::out_of_range){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 if (self->empty())
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 throw std::out_of_range("in "#CLASS"::pop_front()");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 self->pop_back();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 %define %STD_BACK_ACCESS_METHODS(CLASS,T)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 public:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 void push_back(const T& val);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 %extend { // must check this
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 void pop_back() throw (std::out_of_range){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 if (self->empty())
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 throw std::out_of_range("in "#CLASS"::pop_back()");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 self->pop_back();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 Random access methods
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 %define %STD_RANDOM_ACCESS_METHODS(CLASS,T)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 %extend // this is a extra bit of SWIG code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 // [] is replaced by __getitem__ & __setitem__
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 // simply throws a string, which causes a lua error
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 T __getitem__(unsigned int idx) throw (std::out_of_range){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 if (idx>=self->size())
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 throw std::out_of_range("in "#CLASS"::__getitem__()");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 return (*self)[idx];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 void __setitem__(unsigned int idx,const T& val) throw (std::out_of_range){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 if (idx>=self->size())
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 throw std::out_of_range("in "#CLASS"::__setitem__()");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 (*self)[idx]=val;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 %enddef