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