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