Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
nf_buffer.h
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#ifndef nf_buffer_h_included
11#define nf_buffer_h_included
12
13
14#if defined __cplusplus
15
16#include <iterator>
17
18
19template<typename T>
20class nf_Buffer {
21 private:
22 T *m_data;
23 size_t m_length;
24
25 public:
26
27 using iterator = T*;
28 using const_iterator = T const *;
29
30 inline
31 constexpr
32 nf_Buffer() noexcept : m_data(nullptr), m_length(0) {}
33
34 inline
35 nf_Buffer(nf_Buffer const &c) :
36 m_data(new T[c.m_length]),
37 m_length(c.m_length)
38 {
39 for(size_t i = 0;i < m_length;++ i){
40 m_data[i] = c.m_data[i];
41 }
42 }
43
44 inline
45 ~nf_Buffer() noexcept {
46 deallocate();
47 }
48
49 inline
50 constexpr
51 size_t size() const noexcept { return m_length; }
52
53 inline
54 void clear(T value){
55 for(size_t i = 0;i < m_length;++ i){
56 m_data[i] = value;
57 }
58 }
59
60 inline
61 void allocate(size_t length){
62 deallocate();
63 m_length = length;
64 m_data = new T[length];
65 }
66
67 inline
68 void deallocate() noexcept {
69 delete[] m_data;
70 m_length = 0;
71 }
72
73 inline
74 void resize(size_t length){
75 allocate(length);
76 }
77
78 inline
79 std::vector<T> vector() const {
80 return std::vector<T>(cbegin(), cend());
81 }
82
83 inline
84 T* data() noexcept {return m_data;}
85
86 inline
87 constexpr
88 T const * data() const noexcept {return m_data;}
89
90 template<typename I>
91 inline
92 T& operator[](I idx) noexcept {return m_data[idx];}
93
94 template<typename I>
95 inline
96 constexpr
97 T const & operator[](I idx) const noexcept {return m_data[idx];}
98
99
100 inline
101 iterator begin() noexcept { return m_data; }
102
103 inline
104 constexpr
105 const_iterator begin() const noexcept { return m_data; }
106
107 inline
108 iterator end() noexcept { return m_data + m_length; }
109
110 inline
111 constexpr
112 const_iterator end() const noexcept { return m_data + m_length; }
113
114 inline
115 constexpr
116 const_iterator cbegin() const noexcept { return m_data; }
117
118 inline
119 constexpr
120 const_iterator cend() const noexcept { return m_data + m_length; }
121};
122
123
124
125
126#endif
127
128#endif /* End of nf_buffer_h_included. */
allocation_function xml_memory_management_function_storage< T >::allocate
Definition pugixml.cc:205
deallocation_function xml_memory_management_function_storage< T >::deallocate
Definition pugixml.cc:206