blob: 68950a971d5190ea9218b12651ccfdf6b16955a2 [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 Thompson0050abe2013-09-17 12:50:25 -070032 const ptr_lib::shared_ptr<std::vector<unsigned char> >&
33 get() { return vector_; }
Jeff Thompson529779a2013-08-12 13:15:55 -070034
35private:
36 /**
Jeff Thompson1e2180f2013-08-12 13:32:50 -070037 * Implement the static realloc function using vector resize.
Jeff Thompson529779a2013-08-12 13:15:55 -070038 * @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 Thompson0050abe2013-09-17 12:50:25 -070043 static unsigned char*
44 realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length);
Jeff Thompson529779a2013-08-12 13:15:55 -070045
Jeff Thompson5dbf5432013-08-16 16:59:32 -070046 ptr_lib::shared_ptr<std::vector<unsigned char> > vector_;
Jeff Thompson529779a2013-08-12 13:15:55 -070047};
48
49}
50
51#endif