mCRL2
Loading...
Searching...
No Matches
stack_array.h
Go to the documentation of this file.
1// Author(s): Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
10#ifndef MCRL2_UTILITIES_STACK_VECTOR_H
11#define MCRL2_UTILITIES_STACK_VECTOR_H
12
15
16#include <cstddef>
17#include <iterator>
18
19namespace mcrl2
20{
21namespace utilities
22{
23
28template<typename T>
30{
31public:
32 using iterator = T*;
33 using const_iterator = const T*;
34 using reverse_iterator = std::reverse_iterator<iterator>;
35 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
36
38 stack_array(T* reserved_memory, std::size_t N)
39 : m_reserved_memory(reserved_memory),
40 m_size(N)
41 {
42 for (T& element : *this)
43 {
44 new (&element) T();
45 }
46 }
47
49 {
50 for (T& element : *this)
51 {
52 element.~T();
53 }
54 }
55
56 // The remaining interface of std::array
57
58 iterator begin() { return data(); }
59 const_iterator begin() const { return data(); }
60
61 iterator end() { return data() + size(); }
62 const_iterator end() const { return data() + size(); }
63
64 T* data() { return m_reserved_memory; }
65 const T* data() const { return m_reserved_memory; }
66
67 bool empty() const { return size() != 0; }
68
71
74
75 std::size_t size() const { return m_size; }
76
77 std::size_t max_size() const { return m_size; }
78
79 T& operator[](std::size_t index)
80 {
81 assert(index < size());
82 return m_reserved_memory[index];
83 }
84
85private:
87 std::size_t m_size;
88};
89
90} // namespace utilities
91} // namespace mcrl2
92
94#define MCRL2_STACK_ARRAY_NAME(NAME) \
95 NAME ## _reserved_stack_memory
96
98#define MCRL2_DECLARE_STACK_ARRAY(NAME, TYPE, SIZE) \
99 TYPE* MCRL2_STACK_ARRAY_NAME(NAME) = MCRL2_SPECIFIC_STACK_ALLOCATOR(TYPE, SIZE); \
100 mcrl2::utilities::stack_array<TYPE> NAME (MCRL2_STACK_ARRAY_NAME(NAME), SIZE)
101
102#endif // MCRL2_UTILITIES_STACK_VECTOR_H
Inherit from this class to prevent it from being copyable.
Definition noncopyable.h:21
Provides (a subset of) the interface of std::array<T> for a portion of preallocated memory....
Definition stack_array.h:30
const_iterator begin() const
Definition stack_array.h:59
std::size_t size() const
Definition stack_array.h:75
reverse_iterator rend()
Definition stack_array.h:72
std::size_t max_size() const
Definition stack_array.h:77
stack_array(T *reserved_memory, std::size_t N)
The given pointer should be able to hold N element of sizeof(T) bytes.
Definition stack_array.h:38
std::reverse_iterator< iterator > reverse_iterator
Definition stack_array.h:34
T & operator[](std::size_t index)
Definition stack_array.h:79
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition stack_array.h:35
reverse_iterator rbegin()
Definition stack_array.h:69
const_iterator end() const
Definition stack_array.h:62
const_reverse_iterator rend() const
Definition stack_array.h:73
const_reverse_iterator rbegin() const
Definition stack_array.h:70
This file contains a workaround that allows to assign a small array of elements on the stack....
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72