annotate lib/swig/swigwin-2.0.11/Lib/std/std_carray.swg @ 2346:37bb43874e59

Слияние
author Ritor1
date Mon, 07 Apr 2014 19:15:31 +0600
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 #include <algorithm>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 //
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 // std::carray - is really an extension to the 'std' namespace.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 //
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8 // A simple fix C array wrapper, more or less as presented in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 //
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 // "The C++ Standarf Library", by Nicolai M. Josuttis
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 //
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 // which is also derived from the example in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 //
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 // "The C++ Programming Language", by Bjarne Stroustup.
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 %inline %{
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 namespace std {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 template <class _Type, size_t _Size>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 class carray
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 public:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 typedef _Type value_type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 typedef size_t size_type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 typedef _Type * iterator;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 typedef const _Type * const_iterator;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 carray() { }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 carray(const carray& c) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 std::copy(c.v, c.v + size(), v);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 template <class _Iterator>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 carray(_Iterator first, _Iterator last) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 assign(first, last);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 iterator begin() { return v; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 iterator end() { return v + _Size; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 const_iterator begin() const { return v; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 const_iterator end() const { return v + _Size; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 _Type& operator[](size_t i) { return v[i]; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 const _Type& operator[](size_t i) const { return v[i]; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 static size_t size() { return _Size; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 template <class _Iterator>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 void assign(_Iterator first, _Iterator last) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 if (std::distance(first,last) == size()) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 std::copy(first, last, v);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 throw std::length_error("bad range length");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 }
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 private:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 _Type v[_Size];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 %}