Warning, file /include/Geant4/nf_buffer.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef nf_buffer_h_included
0011 #define nf_buffer_h_included
0012
0013
0014 #if defined __cplusplus
0015
0016 #include <iterator>
0017
0018
0019 template<typename T>
0020 class nf_Buffer {
0021 private:
0022 T *m_data;
0023 size_t m_length;
0024
0025 public:
0026
0027 using iterator = T*;
0028 using const_iterator = T const *;
0029
0030 inline
0031 constexpr
0032 nf_Buffer() noexcept : m_data(nullptr), m_length(0) {}
0033
0034 inline
0035 nf_Buffer(nf_Buffer const &c) :
0036 m_data(new T[c.m_length]),
0037 m_length(c.m_length)
0038 {
0039 for(size_t i = 0;i < m_length;++ i){
0040 m_data[i] = c.m_data[i];
0041 }
0042 }
0043
0044 inline
0045 ~nf_Buffer() noexcept {
0046 deallocate();
0047 }
0048
0049 inline
0050 constexpr
0051 size_t size() const noexcept { return m_length; }
0052
0053 inline
0054 void clear(T value){
0055 for(size_t i = 0;i < m_length;++ i){
0056 m_data[i] = value;
0057 }
0058 }
0059
0060 inline
0061 void allocate(size_t length){
0062 deallocate();
0063 m_length = length;
0064 m_data = new T[length];
0065 }
0066
0067 inline
0068 void deallocate() noexcept {
0069 delete[] m_data;
0070 m_length = 0;
0071 }
0072
0073 inline
0074 void resize(size_t length){
0075 allocate(length);
0076 }
0077
0078 inline
0079 std::vector<T> vector() const {
0080 return std::vector<T>(cbegin(), cend());
0081 }
0082
0083 inline
0084 T* data() noexcept {return m_data;}
0085
0086 inline
0087 constexpr
0088 T const * data() const noexcept {return m_data;}
0089
0090 template<typename I>
0091 inline
0092 T& operator[](I idx) noexcept {return m_data[idx];}
0093
0094 template<typename I>
0095 inline
0096 constexpr
0097 T const & operator[](I idx) const noexcept {return m_data[idx];}
0098
0099
0100 inline
0101 iterator begin() noexcept { return m_data; }
0102
0103 inline
0104 constexpr
0105 const_iterator begin() const noexcept { return m_data; }
0106
0107 inline
0108 iterator end() noexcept { return m_data + m_length; }
0109
0110 inline
0111 constexpr
0112 const_iterator end() const noexcept { return m_data + m_length; }
0113
0114 inline
0115 constexpr
0116 const_iterator cbegin() const noexcept { return m_data; }
0117
0118 inline
0119 constexpr
0120 const_iterator cend() const noexcept { return m_data + m_length; }
0121 };
0122
0123
0124
0125
0126 #endif
0127
0128 #endif