Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 22 | #include "ndnx-charbuf.h" |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 23 | |
| 24 | using namespace std; |
| 25 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 26 | namespace Ndnx { |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 27 | |
| 28 | void |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 29 | NdnxCharbuf::init(ndn_charbuf *buf) |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 30 | { |
| 31 | if (buf != NULL) |
| 32 | { |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 33 | m_buf = ndn_charbuf_create(); |
| 34 | ndn_charbuf_reserve(m_buf, buf->length); |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 35 | memcpy(m_buf->buf, buf->buf, buf->length); |
| 36 | m_buf->length = buf->length; |
| 37 | } |
| 38 | } |
| 39 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 40 | NdnxCharbuf::NdnxCharbuf() |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 41 | : m_buf(NULL) |
| 42 | { |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 43 | m_buf = ndn_charbuf_create(); |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 46 | NdnxCharbuf::NdnxCharbuf(ndn_charbuf *buf) |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 47 | : m_buf(NULL) |
| 48 | { |
| 49 | init(buf); |
| 50 | } |
| 51 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 52 | NdnxCharbuf::NdnxCharbuf(const NdnxCharbuf &other) |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 53 | : m_buf (NULL) |
| 54 | { |
| 55 | init(other.m_buf); |
| 56 | } |
| 57 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 58 | NdnxCharbuf::NdnxCharbuf(const void *buf, size_t length) |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 59 | { |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 60 | m_buf = ndn_charbuf_create (); |
| 61 | ndn_charbuf_reserve (m_buf, length); |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 62 | memcpy (m_buf->buf, buf, length); |
| 63 | m_buf->length = length; |
| 64 | } |
| 65 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 66 | NdnxCharbuf::~NdnxCharbuf() |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 67 | { |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame^] | 68 | ndn_charbuf_destroy(&m_buf); |
Alexander Afanasyev | 452645b | 2013-02-24 15:41:29 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } |