neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_jar.hpp
Go to the documentation of this file.
1// i_jar.hpp
2/*
3 * Copyright (c) 2020 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 typedef uint32_t cookie;
45 typedef uint16_t small_cookie;
46 typedef uint64_t large_cookie;
47
48 template<class CookieType>
49 constexpr CookieType invalid_cookie = static_cast<CookieType>(~CookieType{});
50
51 template <typename CookieType>
53 {
54 public:
55 typedef CookieType cookie_type;
56 public:
57 struct invalid_release : std::logic_error { invalid_release() : std::logic_error("i_basic_cookie_consumer::invalid_release") {} };
58 public:
59 virtual ~i_basic_cookie_consumer() = default;
60 public:
61 virtual void add_ref(cookie_type aCookie) = 0;
62 virtual void release(cookie_type aCookie) = 0;
63 virtual long use_count(cookie_type aCookie) const = 0;
64 };
65
68
69 struct cookie_invalid : std::logic_error { cookie_invalid() : std::logic_error("neolib::cookie_invalid") {} };
70 struct cookie_already_added : std::logic_error { cookie_already_added() : std::logic_error("neolib::cookie_already_added") {} };
71 struct cookies_exhausted : std::logic_error { cookies_exhausted() : std::logic_error("neolib::cookies_exhausted") {} };
72 struct no_pointer_value_type_cookie_lookup : std::logic_error { no_pointer_value_type_cookie_lookup() : std::logic_error("neolib::no_pointer_value_type_cookie_lookup") {} };
73
74 template <typename T, typename Container = i_vector<T>, typename CookieType = cookie>
76 {
77 typedef i_basic_jar<T, CookieType> self_type;
78 public:
79 typedef self_type abstract_type;
80 typedef CookieType cookie_type;
81 public:
82 typedef T value_type;
83 typedef Container container_type;
84 typedef typename container_type::const_iterator const_iterator;
85 typedef typename container_type::iterator iterator;
86 public:
87 virtual ~i_basic_jar() = default;
88 public:
89 virtual bool empty() const = 0;
90 virtual std::size_t size() const = 0;
91 virtual bool contains(cookie_type aCookie) const = 0;
92 virtual const_iterator find(cookie_type aCookie) const = 0;
93 virtual iterator find(cookie_type aCookie) = 0;
94 virtual const value_type& operator[](cookie_type aCookie) const = 0;
95 virtual value_type& operator[](cookie_type aCookie) = 0;
96 virtual const value_type& at_index(std::size_t aIndex) const = 0;
97 virtual value_type& at_index(std::size_t aIndex) = 0;
98 virtual cookie_type insert(value_type const& aItem) = 0;
99 public:
100 virtual iterator erase(const_iterator aItem) = 0;
101 virtual iterator add(cookie_type aCookie, value_type const& aItem) = 0;
102 virtual iterator remove(value_type const& aItem) = 0;
103 virtual iterator remove(cookie_type aCookie) = 0;
104 public:
105 virtual cookie_type item_cookie(value_type const& aItem) const = 0;
107 virtual void return_cookie(cookie_type aCookie) = 0;
108 public:
109 virtual const_iterator cbegin() const = 0;
110 virtual const_iterator begin() const = 0;
111 virtual iterator begin() = 0;
112 virtual const_iterator cend() const = 0;
113 virtual const_iterator end() const = 0;
114 virtual iterator end() = 0;
115 public:
116 virtual void clear() = 0;
117 virtual const container_type& items() const = 0;
118 virtual container_type& items() = 0;
119 };
120
121 template <typename T>
123 template <typename T>
125}
virtual const_iterator find(cookie_type aCookie) const =0
container_type::const_iterator const_iterator
Definition i_jar.hpp:84
virtual const_iterator begin() const =0
virtual iterator find(cookie_type aCookie)=0
virtual const value_type & at_index(std::size_t aIndex) const =0
virtual iterator end()=0
virtual cookie_type next_cookie()=0
CookieType cookie_type
Definition i_jar.hpp:80
virtual container_type & items()=0
virtual cookie_type insert(value_type const &aItem)=0
self_type abstract_type
Definition i_jar.hpp:79
virtual iterator begin()=0
virtual const_iterator cbegin() const =0
virtual bool contains(cookie_type aCookie) const =0
virtual std::size_t size() const =0
virtual bool empty() const =0
virtual iterator remove(cookie_type aCookie)=0
virtual iterator remove(value_type const &aItem)=0
virtual iterator add(cookie_type aCookie, value_type const &aItem)=0
virtual const_iterator cend() const =0
virtual void return_cookie(cookie_type aCookie)=0
virtual cookie_type item_cookie(value_type const &aItem) const =0
virtual value_type & at_index(std::size_t aIndex)=0
virtual value_type & operator[](cookie_type aCookie)=0
virtual const value_type & operator[](cookie_type aCookie) const =0
virtual iterator erase(const_iterator aItem)=0
virtual const container_type & items() const =0
virtual const_iterator end() const =0
virtual void clear()=0
virtual ~i_basic_jar()=default
Container container_type
Definition i_jar.hpp:83
container_type::iterator iterator
Definition i_jar.hpp:85
uint64_t large_cookie
Definition i_jar.hpp:46
uint32_t cookie
Definition i_jar.hpp:44
i_basic_jar< T, i_vector< T >, small_cookie > i_small_jar
Definition i_jar.hpp:124
i_basic_cookie_consumer< small_cookie > i_small_cookie_consumer
Definition i_jar.hpp:67
uint16_t small_cookie
Definition i_jar.hpp:45
i_basic_jar< T, i_vector< T >, cookie > i_jar
Definition i_jar.hpp:122
i_basic_cookie_consumer< cookie > i_cookie_consumer
Definition i_jar.hpp:66
constexpr CookieType invalid_cookie
Definition i_jar.hpp:49