| Directory: | ./ |
|---|---|
| File: | include/pinocchio/serialization/static-buffer.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 14 | 14 | 100.0% |
| Branches: | 1 | 2 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2021 INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_serialization_static_buffer_hpp__ | ||
| 6 | #define __pinocchio_serialization_static_buffer_hpp__ | ||
| 7 | |||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | namespace pinocchio | ||
| 11 | { | ||
| 12 | namespace serialization | ||
| 13 | { | ||
| 14 | |||
| 15 | /// \brief Static buffer with pre-allocated memory. | ||
| 16 | struct StaticBuffer | ||
| 17 | { | ||
| 18 | |||
| 19 | /// \brief Defautl constructor from a given size | ||
| 20 | 174 | explicit StaticBuffer(const size_t n) | |
| 21 | 174 | : m_size(n) | |
| 22 | { | ||
| 23 |
1/2✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
|
174 | m_data.reserve(n); |
| 24 | 174 | } | |
| 25 | |||
| 26 | /// \brief Returns the current size of the buffer | ||
| 27 | 348 | size_t size() const | |
| 28 | { | ||
| 29 | 348 | return m_size; | |
| 30 | } | ||
| 31 | |||
| 32 | /// \brief Returns the pointer on the data | ||
| 33 | 348 | char * data() | |
| 34 | { | ||
| 35 | 348 | return m_data.data(); | |
| 36 | } | ||
| 37 | |||
| 38 | /// \brief Returns the pointer on the data (const version) | ||
| 39 | 2 | const char * data() const | |
| 40 | { | ||
| 41 | 2 | return m_data.data(); | |
| 42 | } | ||
| 43 | |||
| 44 | /// \brief Increase the capacity of the vector to a value that's greater or equal to new_size. | ||
| 45 | /// | ||
| 46 | /// \param[in] new_size New capacity of the buffer. | ||
| 47 | /// | ||
| 48 | 1 | void resize(const size_t new_size) | |
| 49 | { | ||
| 50 | 1 | m_size = new_size; | |
| 51 | 1 | m_data.reserve(new_size); | |
| 52 | 1 | } | |
| 53 | |||
| 54 | protected: | ||
| 55 | size_t m_size; | ||
| 56 | std::vector<char> m_data; | ||
| 57 | }; | ||
| 58 | |||
| 59 | } // namespace serialization | ||
| 60 | } // namespace pinocchio | ||
| 61 | |||
| 62 | #endif // ifndef __pinocchio_serialization_static_buffer_hpp__ | ||
| 63 |