Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 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-uchar-array.h" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | /** |
| 17 | * A DynamicUCharVector extends ndn_DynamicUCharArray to hold a shared_ptr<vector<unsigned char> > for use with |
| 18 | * C functions which need an ndn_DynamicUCharArray. |
| 19 | */ |
Jeff Thompson | 1e2180f | 2013-08-12 13:32:50 -0700 | [diff] [blame] | 20 | class DynamicUCharVector : public ndn_DynamicUCharArray { |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 21 | public: |
| 22 | /** |
| 23 | * Create a new DynamicUCharVector with an initial length. |
| 24 | * @param initialLength The initial size of the allocated vector. |
| 25 | */ |
| 26 | DynamicUCharVector(unsigned int initialLength); |
| 27 | |
| 28 | /** |
| 29 | * Get the shared_ptr to the allocated vector. |
| 30 | * @return The shared_ptr to the allocated vector. |
| 31 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 32 | const ptr_lib::shared_ptr<std::vector<unsigned char> >& |
| 33 | get() { return vector_; } |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 34 | |
| 35 | private: |
| 36 | /** |
Jeff Thompson | 1e2180f | 2013-08-12 13:32:50 -0700 | [diff] [blame] | 37 | * Implement the static realloc function using vector resize. |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 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 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 43 | static unsigned char* |
| 44 | realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length); |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 45 | |
Jeff Thompson | 5dbf543 | 2013-08-16 16:59:32 -0700 | [diff] [blame] | 46 | ptr_lib::shared_ptr<std::vector<unsigned char> > vector_; |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | #endif |