Loading...
Searching...
No Matches
index_generator.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_INDEX_GENERATOR_HPP__
26#define __BITPIT_INDEX_GENERATOR_HPP__
27
28#include <cassert>
29#include <iostream>
30#include <limits>
31#include <set>
32
33#include "bitpit_common.hpp"
34#include "bitpit_containers.hpp"
35
36namespace bitpit {
37
38template<typename id_t = long>
40
41static_assert(std::is_integral<id_t>::value, "Index has to be an integer!");
42static_assert(std::numeric_limits<id_t>::is_signed, "Index has to be signed!");
43
44public:
45 typedef id_t id_type;
46
47 BITPIT_PUBLIC_API static const id_type NULL_ID;
48
50
51 id_type generate();
52 bool isAssigned(id_type id);
53 void setAssigned(id_type id);
54 void trash(id_type id);
55
56 id_type getLatest();
57 id_type getHighest();
58
59 void reset();
60
61 void dump(std::ostream &stream) const;
62 void restore(std::istream &stream);
63
64private:
65 id_type m_latest;
66 id_type m_lowest;
67 id_type m_highest;
68 std::set<id_type> m_trash;
69
70 void eraseFromTrash(id_type id);
71
72 int getBinaryArchiveVersion() const;
73
74};
75
76#ifndef __BITPIT_COMMON_UTILS_SRC__
77extern template class IndexGenerator<int>;
78extern template class IndexGenerator<long>;
79#endif
80
81}
82
83// Include the implementation
84#include "index_generator.tpp"
85
86#endif
The IndexGenerator class allows to generate unique ids.
bool isAssigned(id_type id)
void setAssigned(id_type id)
void restore(std::istream &stream)
void dump(std::ostream &stream) const
--- layout: doxygen_footer ---