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 | |
| 22 | #include "ccnx-charbuf.h" |
| 23 | |
| 24 | using namespace std; |
| 25 | |
| 26 | namespace Ccnx { |
| 27 | |
| 28 | void |
| 29 | CcnxCharbuf::init(ccn_charbuf *buf) |
| 30 | { |
| 31 | if (buf != NULL) |
| 32 | { |
| 33 | m_buf = ccn_charbuf_create(); |
| 34 | ccn_charbuf_reserve(m_buf, buf->length); |
| 35 | memcpy(m_buf->buf, buf->buf, buf->length); |
| 36 | m_buf->length = buf->length; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | CcnxCharbuf::CcnxCharbuf() |
| 41 | : m_buf(NULL) |
| 42 | { |
| 43 | m_buf = ccn_charbuf_create(); |
| 44 | } |
| 45 | |
| 46 | CcnxCharbuf::CcnxCharbuf(ccn_charbuf *buf) |
| 47 | : m_buf(NULL) |
| 48 | { |
| 49 | init(buf); |
| 50 | } |
| 51 | |
| 52 | CcnxCharbuf::CcnxCharbuf(const CcnxCharbuf &other) |
| 53 | : m_buf (NULL) |
| 54 | { |
| 55 | init(other.m_buf); |
| 56 | } |
| 57 | |
| 58 | CcnxCharbuf::CcnxCharbuf(const void *buf, size_t length) |
| 59 | { |
| 60 | m_buf = ccn_charbuf_create (); |
| 61 | ccn_charbuf_reserve (m_buf, length); |
| 62 | memcpy (m_buf->buf, buf, length); |
| 63 | m_buf->length = length; |
| 64 | } |
| 65 | |
| 66 | CcnxCharbuf::~CcnxCharbuf() |
| 67 | { |
| 68 | ccn_charbuf_destroy(&m_buf); |
| 69 | } |
| 70 | |
| 71 | } |