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 | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 32 | const ptr_lib::shared_ptr<std::vector<unsigned char> >& get() { return vector_; } |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | /** |
Jeff Thompson | 1e2180f | 2013-08-12 13:32:50 -0700 | [diff] [blame] | 36 | * Implement the static realloc function using vector resize. |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 37 | * @param self A pointer to this object. |
| 38 | * @param array Should be the front of the vector. |
| 39 | * @param length The new length for the vector. |
| 40 | * @return The front of the allocated vector. |
| 41 | */ |
| 42 | static unsigned char *realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length); |
| 43 | |
Jeff Thompson | 5dbf543 | 2013-08-16 16:59:32 -0700 | [diff] [blame] | 44 | ptr_lib::shared_ptr<std::vector<unsigned char> > vector_; |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | } |
| 48 | |
| 49 | #endif |