blob: b7957c5484a5251bcfa6c1a7da0a901293c14222 [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
Jeff Thompson1e2180f2013-08-12 13:32:50 -070027 thisObject->vector_->resize(length);
Jeff Thompson529779a2013-08-12 13:15:55 -070028 return &thisObject->vector_->front();
29}
30
31}