blob: 4b17e63a9829927e9a0af42cd16791ec98c57199 [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#include "dynamic-uchar-vector.hpp"
8
9using namespace std;
10
11namespace ndn {
12
13DynamicUCharVector::DynamicUCharVector(unsigned int initialLength)
14: vector_(new vector<unsigned char>(initialLength))
15{
Jeff Thompsond1427fb2013-08-29 17:20:32 -070016 ndn_DynamicUCharArray_initialize(this, &vector_->front(), initialLength, DynamicUCharVector::realloc);
Jeff Thompson529779a2013-08-12 13:15:55 -070017}
18
Jeff Thompson0050abe2013-09-17 12:50:25 -070019unsigned char*
20DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length)
Jeff Thompson529779a2013-08-12 13:15:55 -070021{
22 // Because this method is private, assume there is not a problem with upcasting.
23 DynamicUCharVector *thisObject = (DynamicUCharVector *)self;
24
25 if (array != &thisObject->vector_->front())
26 // We don't expect this to ever happen. The caller didn't pass the array from this object.
27 return 0;
28
Jeff Thompson1e2180f2013-08-12 13:32:50 -070029 thisObject->vector_->resize(length);
Jeff Thompson529779a2013-08-12 13:15:55 -070030 return &thisObject->vector_->front();
31}
32
33}