~laney/ubuntu/quantal/swig2.0/guile-2.0

« back to all changes in this revision

Viewing changes to Lib/go/std_map.i

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2010-12-19 18:25:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101219182559-8lh77o66bo890jwo
Tags: 2.0.1-1
* Merge new upstream release 2.0.1.
* Remove dependency on quilt and usage in debian/rules, the new source
  format will take care of that.
* Remove patch fix-cleaning.diff (applied upstream).
* Remove patch keep_docs.diff (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -----------------------------------------------------------------------------
 
2
 * std_map.i
 
3
 *
 
4
 * SWIG typemaps for std::map
 
5
 * ----------------------------------------------------------------------------- */
 
6
 
 
7
%include <std_common.i>
 
8
 
 
9
// ------------------------------------------------------------------------
 
10
// std::map
 
11
// ------------------------------------------------------------------------
 
12
 
 
13
%{
 
14
#include <map>
 
15
#include <algorithm>
 
16
#include <stdexcept>
 
17
%}
 
18
 
 
19
// exported class
 
20
 
 
21
namespace std {
 
22
 
 
23
    template<class K, class T> class map {
 
24
        // add typemaps here
 
25
      public:
 
26
        typedef size_t size_type;
 
27
        typedef ptrdiff_t difference_type;
 
28
        typedef K key_type;
 
29
        typedef T mapped_type;
 
30
        map();
 
31
        map(const map<K,T> &);
 
32
        
 
33
        unsigned int size() const;
 
34
        bool empty() const;
 
35
        void clear();
 
36
        %extend {
 
37
            const T& get(const K& key) throw (std::out_of_range) {
 
38
                std::map<K,T >::iterator i = self->find(key);
 
39
                if (i != self->end())
 
40
                    return i->second;
 
41
                else
 
42
                    throw std::out_of_range("key not found");
 
43
            }
 
44
            void set(const K& key, const T& x) {
 
45
                (*self)[key] = x;
 
46
            }
 
47
            void del(const K& key) throw (std::out_of_range) {
 
48
                std::map<K,T >::iterator i = self->find(key);
 
49
                if (i != self->end())
 
50
                    self->erase(i);
 
51
                else
 
52
                    throw std::out_of_range("key not found");
 
53
            }
 
54
            bool has_key(const K& key) {
 
55
                std::map<K,T >::iterator i = self->find(key);
 
56
                return i != self->end();
 
57
            }
 
58
        }
 
59
    };
 
60
}