Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #include "dynamic-uint8-vector.hpp" |
| 9 | |
| 10 | using namespace std; |
| 11 | |
| 12 | namespace ndn { |
| 13 | |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 14 | DynamicUInt8Vector::DynamicUInt8Vector(size_t initialLength) |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 15 | : vector_(new vector<uint8_t>(initialLength)) |
| 16 | { |
| 17 | ndn_DynamicUInt8Array_initialize(this, &vector_->front(), initialLength, DynamicUInt8Vector::realloc); |
| 18 | } |
| 19 | |
| 20 | uint8_t* |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 21 | DynamicUInt8Vector::realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length) |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 22 | { |
| 23 | // Because this method is private, assume there is not a problem with upcasting. |
| 24 | DynamicUInt8Vector *thisObject = (DynamicUInt8Vector *)self; |
| 25 | |
| 26 | if (array != &thisObject->vector_->front()) |
| 27 | // We don't expect this to ever happen. The caller didn't pass the array from this object. |
| 28 | return 0; |
| 29 | |
| 30 | thisObject->vector_->resize(length); |
| 31 | return &thisObject->vector_->front(); |
| 32 | } |
| 33 | |
| 34 | } |