Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "dynamic-uchar-vector.hpp" |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
| 13 | DynamicUCharVector::DynamicUCharVector(unsigned int initialLength) |
| 14 | : vector_(new vector<unsigned char>(initialLength)) |
| 15 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 16 | ndn_DynamicUCharArray_initialize(this, &vector_->front(), initialLength, DynamicUCharVector::realloc); |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | unsigned 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 Thompson | 1e2180f | 2013-08-12 13:32:50 -0700 | [diff] [blame] | 28 | thisObject->vector_->resize(length); |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 29 | return &thisObject->vector_->front(); |
| 30 | } |
| 31 | |
| 32 | } |