ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/include/adt/map_vector.h
Revision: 1.1
Committed: Sun Oct 17 08:14:45 2010 UTC (13 years, 8 months ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import

File Contents

# User Rev Content
1 sf-pippijn 1.1 #pragma once
2    
3     #include <deque>
4     #include <cstddef>
5    
6     template<typename T>
7     struct map_vector
8     {
9     typedef std::deque<T> container_type;
10    
11     typedef typename container_type:: iterator iterator;
12     typedef typename container_type::const_iterator const_iterator;
13    
14     T &front () { return data.front (); }
15     T const &front () const { return data.front (); }
16    
17     T &at (int n) { return data.at (offset + n); }
18     T const &at (int n) const { return data.at (offset + n); }
19    
20     bool has (int n) const { return offset + n >= 0 && offset + n < size (); }
21    
22     void clear () { return data.clear (); }
23    
24     int size () const
25     {
26     return data.size ();
27     }
28    
29     void ensure (int x)
30     {
31     while (offset + x < 0)
32     {
33     data.emplace_front ();
34     ++offset;
35     }
36     while (offset + x >= size ())
37     {
38     data.emplace_back ();
39     }
40     }
41    
42     int low () const { return -offset; }
43     int high () const { return data.size () + low (); }
44    
45     iterator begin () { return data.begin (); }
46     iterator end () { return data.end (); }
47     const_iterator begin () const { return data.begin (); }
48     const_iterator end () const { return data.end (); }
49    
50     map_vector ()
51     : offset (0)
52     {
53     }
54    
55     private:
56     long offset;
57     container_type data;
58     };