neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_map.hpp
Go to the documentation of this file.
1// i_map.hpp
2/*
3 * Copyright (c) 2007 Leigh Johnston.
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * * Neither the name of Leigh Johnston nor the names of any
19 * other contributors to this software may be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#pragma once
37
38#include <neolib/neolib.hpp>
41
42namespace neolib
43{
44 template <typename Key, typename T>
45 class i_map : public i_container<i_pair<const Key, T>, i_const_iterator<i_pair<const Key, T>>, i_iterator<i_pair<const Key, T>>>
46 {
47 typedef i_map<Key, T> self_type;
49 public:
50 typedef self_type abstract_type;
51 typedef Key abstract_key_type;
54 protected:
57 public:
59 typedef typename base_type::iterator iterator;
60 public:
62 virtual const abstract_mapped_type& at(const abstract_key_type& aKey) const = 0;
63 virtual abstract_mapped_type& at(const abstract_key_type& aKey) = 0;
64 public:
65 iterator insert(const abstract_value_type& aValue) { iterator result; return do_insert(result.storage(), aValue.first(), aValue.second()); }
66 iterator insert(const abstract_key_type& aKey, const abstract_mapped_type& aMapped) { iterator result; return do_insert(result.storage(), aKey, aMapped); }
67 const_iterator find(const abstract_key_type& aKey) const { const_iterator result; return do_find(result.storage(), aKey); }
68 iterator find(const abstract_key_type& aKey) { iterator result; return do_find(result.storage(), aKey); }
69 const_iterator lower_bound(const abstract_key_type& aKey) const { const_iterator result; return do_lower_bound(result.storage(), aKey); }
70 iterator lower_bound(const abstract_key_type& aKey) { iterator result; return do_lower_bound(result.storage(), aKey); }
71 const_iterator upper_bound(const abstract_key_type& aKey) const { const_iterator result; return do_upper_bound(result.storage(), aKey); }
72 iterator upper_bound(const abstract_key_type& aKey) { iterator result; return do_upper_bound(result.storage(), aKey); }
73 private:
74 virtual abstract_iterator* do_insert(void* memory, const abstract_key_type& aKey, const abstract_mapped_type& aMapped) = 0;
75 virtual abstract_const_iterator* do_find(void* memory, const abstract_key_type& aKey) const = 0;
76 virtual abstract_iterator* do_find(void* memory, const abstract_key_type& aKey) = 0;
77 virtual abstract_const_iterator* do_lower_bound(void* memory, const abstract_key_type& aKey) const = 0;
78 virtual abstract_iterator* do_lower_bound(void* memory, const abstract_key_type& aKey) = 0;
79 virtual abstract_const_iterator* do_upper_bound(void* memory, const abstract_key_type& aKey) const = 0;
80 virtual abstract_iterator* do_upper_bound(void* memory, const abstract_key_type& aKey) = 0;
81 };
82
83 template <typename Key, typename T>
84 class i_multimap : public i_container<i_pair<const Key, T>, i_const_iterator<i_pair<const Key, T>>, i_iterator<i_pair<const Key, T>>>
85 {
86 typedef i_multimap<Key, T> self_type;
88 public:
89 typedef self_type abstract_type;
90 typedef Key abstract_key_type;
93 protected:
96 public:
98 typedef typename base_type::iterator iterator;
99 public:
100 iterator insert(const abstract_value_type& aValue) { iterator result; return do_insert(result.storage(), aValue.first(), aValue.second()); }
101 iterator insert(const abstract_key_type& aKey, const abstract_mapped_type& aMapped) { iterator result; return do_insert(result.storage(), aKey, aMapped); }
102 const_iterator find(const abstract_key_type& aKey) const { const_iterator result; return do_find(result.storage(), aKey); }
103 iterator find(const abstract_key_type& aKey) { iterator result; return do_find(result.storage(), aKey); }
104 const_iterator lower_bound(const abstract_key_type& aKey) const { const_iterator result; return do_lower_bound(result.storage(), aKey); }
105 iterator lower_bound(const abstract_key_type& aKey) { iterator result; return do_lower_bound(result.storage(), aKey); }
106 const_iterator upper_bound(const abstract_key_type& aKey) const { const_iterator result; return do_upper_bound(result.storage(), aKey); }
107 iterator upper_bound(const abstract_key_type& aKey) { iterator result; return do_upper_bound(result.storage(), aKey); }
108 private:
109 virtual abstract_iterator* do_insert(void* memory, const abstract_key_type& aKey, const abstract_mapped_type& aMapped) = 0;
110 virtual abstract_const_iterator* do_find(void* memory, const abstract_key_type& aKey) const = 0;
111 virtual abstract_iterator* do_find(void* memory, const abstract_key_type& aKey) = 0;
112 virtual abstract_const_iterator* do_lower_bound(void* memory, const abstract_key_type& aKey) const = 0;
113 virtual abstract_iterator* do_lower_bound(void* memory, const abstract_key_type& aKey) = 0;
114 virtual abstract_const_iterator* do_upper_bound(void* memory, const abstract_key_type& aKey) const = 0;
115 virtual abstract_iterator* do_upper_bound(void* memory, const abstract_key_type& aKey) = 0;
116 };
117}
iterator insert(const abstract_value_type &aValue)
Definition i_map.hpp:65
base_type::const_iterator const_iterator
Definition i_map.hpp:58
Key abstract_key_type
Definition i_map.hpp:51
virtual const abstract_mapped_type & at(const abstract_key_type &aKey) const =0
const_iterator find(const abstract_key_type &aKey) const
Definition i_map.hpp:67
i_pair< const abstract_key_type, abstract_mapped_type > abstract_value_type
Definition i_map.hpp:53
const_iterator lower_bound(const abstract_key_type &aKey) const
Definition i_map.hpp:69
iterator insert(const abstract_key_type &aKey, const abstract_mapped_type &aMapped)
Definition i_map.hpp:66
base_type::abstract_iterator abstract_iterator
Definition i_map.hpp:56
iterator lower_bound(const abstract_key_type &aKey)
Definition i_map.hpp:70
self_type abstract_type
Definition i_map.hpp:50
base_type::abstract_const_iterator abstract_const_iterator
Definition i_map.hpp:55
iterator upper_bound(const abstract_key_type &aKey)
Definition i_map.hpp:72
base_type::iterator iterator
Definition i_map.hpp:59
T abstract_mapped_type
Definition i_map.hpp:52
const_iterator upper_bound(const abstract_key_type &aKey) const
Definition i_map.hpp:71
virtual abstract_mapped_type & operator[](const abstract_key_type &aKey)=0
virtual abstract_mapped_type & at(const abstract_key_type &aKey)=0
iterator find(const abstract_key_type &aKey)
Definition i_map.hpp:68
i_pair< const abstract_key_type, abstract_mapped_type > abstract_value_type
Definition i_map.hpp:92
iterator insert(const abstract_value_type &aValue)
Definition i_map.hpp:100
const_iterator upper_bound(const abstract_key_type &aKey) const
Definition i_map.hpp:106
base_type::abstract_iterator abstract_iterator
Definition i_map.hpp:95
const_iterator lower_bound(const abstract_key_type &aKey) const
Definition i_map.hpp:104
base_type::const_iterator const_iterator
Definition i_map.hpp:97
const_iterator find(const abstract_key_type &aKey) const
Definition i_map.hpp:102
iterator upper_bound(const abstract_key_type &aKey)
Definition i_map.hpp:107
self_type abstract_type
Definition i_map.hpp:89
iterator insert(const abstract_key_type &aKey, const abstract_mapped_type &aMapped)
Definition i_map.hpp:101
iterator find(const abstract_key_type &aKey)
Definition i_map.hpp:103
iterator lower_bound(const abstract_key_type &aKey)
Definition i_map.hpp:105
base_type::abstract_const_iterator abstract_const_iterator
Definition i_map.hpp:94
base_type::iterator iterator
Definition i_map.hpp:98