blob: d3464946583cc919e751763bb276db75d64c3c9d [file] [log] [blame]
Jeff Thompson529779a2013-08-12 13:15:55 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#include "dynamic-uchar-vector.hpp"
7
8using namespace std;
9
10namespace ndn {
11
12DynamicUCharVector::DynamicUCharVector(unsigned int initialLength)
13: vector_(new vector<unsigned char>(initialLength))
14{
15 ndn_DynamicUCharArray_init(this, &vector_->front(), initialLength, DynamicUCharVector::realloc);
16}
17
18unsigned char *DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length)
19{
20 // Because this method is private, assume there is not a problem with upcasting.
21 DynamicUCharVector *thisObject = (DynamicUCharVector *)self;
22
23 if (array != &thisObject->vector_->front())
24 // We don't expect this to ever happen. The caller didn't pass the array from this object.
25 return 0;
26
27 thisObject->vector_->reserve(length);
28 return &thisObject->vector_->front();
29}
30
31}