blob: 7313cc92ada3b84dbf9074c6255feda8f10fa344 [file] [log] [blame]
Jeff Thompson529779a2013-08-12 13:15:55 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson529779a2013-08-12 13:15:55 -07004 * 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
14namespace 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 Thompson1e2180f2013-08-12 13:32:50 -070020class DynamicUCharVector : public ndn_DynamicUCharArray {
Jeff Thompson529779a2013-08-12 13:15:55 -070021public:
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 Thompson1656e6a2013-08-29 18:01:48 -070032 const ptr_lib::shared_ptr<std::vector<unsigned char> >& get() { return vector_; }
Jeff Thompson529779a2013-08-12 13:15:55 -070033
34private:
35 /**
Jeff Thompson1e2180f2013-08-12 13:32:50 -070036 * Implement the static realloc function using vector resize.
Jeff Thompson529779a2013-08-12 13:15:55 -070037 * @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 Thompson5dbf5432013-08-16 16:59:32 -070044 ptr_lib::shared_ptr<std::vector<unsigned char> > vector_;
Jeff Thompson529779a2013-08-12 13:15:55 -070045};
46
47}
48
49#endif