blob: 454ce8cfb6287f99e0edf573acf378190777ecf0 [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
19unsigned char *DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length)
20{
21 // Because this method is private, assume there is not a problem with upcasting.
22 DynamicUCharVector *thisObject = (DynamicUCharVector *)self;
23
24 if (array != &thisObject->vector_->front())
25 // We don't expect this to ever happen. The caller didn't pass the array from this object.
26 return 0;
27
Jeff Thompson1e2180f2013-08-12 13:32:50 -070028 thisObject->vector_->resize(length);
Jeff Thompson529779a2013-08-12 13:15:55 -070029 return &thisObject->vector_->front();
30}
31
32}