Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_DYNAMIC_UCHAR_VECTOR_HPP |
| 8 | #define NDN_DYNAMIC_UCHAR_VECTOR_HPP |
| 9 | |
| 10 | #include <vector> |
| 11 | #include "../common.hpp" |
| 12 | #include "../c/util/dynamic-uint8-array.h" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | /** |
| 17 | * A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr<vector<uint8_t> > for use with |
| 18 | * C functions which need an ndn_DynamicUInt8Array. |
| 19 | */ |
| 20 | class DynamicUInt8Vector : public ndn_DynamicUInt8Array { |
| 21 | public: |
| 22 | /** |
| 23 | * Create a new DynamicUInt8Vector with an initial length. |
| 24 | * @param initialLength The initial size of the allocated vector. |
| 25 | */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame^] | 26 | DynamicUInt8Vector(size_t initialLength); |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Get the shared_ptr to the allocated vector. |
| 30 | * @return The shared_ptr to the allocated vector. |
| 31 | */ |
| 32 | const ptr_lib::shared_ptr<std::vector<uint8_t> >& |
| 33 | get() { return vector_; } |
| 34 | |
| 35 | private: |
| 36 | /** |
| 37 | * Implement the static realloc function using vector resize. |
| 38 | * @param self A pointer to this object. |
| 39 | * @param array Should be the front of the vector. |
| 40 | * @param length The new length for the vector. |
| 41 | * @return The front of the allocated vector. |
| 42 | */ |
| 43 | static uint8_t* |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame^] | 44 | realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length); |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 45 | |
| 46 | ptr_lib::shared_ptr<std::vector<uint8_t> > vector_; |
| 47 | }; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | #endif |