sources/list.h

Wed, 27 Jan 2021 19:28:18 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 27 Jan 2021 19:28:18 +0200
changeset 190
90bf9049e5eb
parent 185
e83ec58cc458
child 191
2e6cbacafdc7
permissions
-rw-r--r--

updated copyright year

1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
190
90bf9049e5eb updated copyright year
Teemu Piippo <teemu@hecknology.net>
parents: 185
diff changeset
2 Copyright 2014 - 2021 Teemu Piippo
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #pragma once
181
e254398fcc7c removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
32 #include <vector>
182
20ca0a6be175 removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
33 #include <string>
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "basics.h"
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 87
diff changeset
35 BEGIN_ZFC_NAMESPACE
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
181
e254398fcc7c removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
37 template<typename T>
e254398fcc7c removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
38 using Vector = std::vector<T>;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 template<typename T>
181
e254398fcc7c removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
41 auto& last(T& container)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 {
181
e254398fcc7c removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
43 return *(container.begin() + container.size() - 1);
e254398fcc7c removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
44 }
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 87
diff changeset
45
180
2e7225dbd9b2 continue cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
46 using ByteArray = std::vector<unsigned char>;
182
20ca0a6be175 removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
47 std::string quote(const ByteArray& bytes);
158
de7574d292ad Added the ByteArray typedef for Vector<unsigned char>
Teemu Piippo <teemu@compsta2.com>
parents: 157
diff changeset
48
179
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
49 template<typename T>
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
50 T splice(const T& container, int start, int end, int step = 1)
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
51 {
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
52 start = clamp(start, 0, static_cast<int>(container.size()));
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
53 end = clamp(end, 0, static_cast<int>(container.size()));
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
54 T result;
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
55 result.reserve((end - start) / step);
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
56 for (int i = start; i < end; i += step)
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
57 {
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
58 result.push_back(container[i]);
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
59 }
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
60 return result;
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
61 }
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 164
diff changeset
62
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 87
diff changeset
63 END_ZFC_NAMESPACE

mercurial