blob: 0ba328f40be9fe04b66166cb8035d66a299fe332 [file] [log] [blame]
Alexander Afanasyev452645b2013-02-24 15:41:29 -08001/* -*- 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
24using namespace std;
25
26namespace Ccnx {
27
28void
29CcnxCharbuf::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
40CcnxCharbuf::CcnxCharbuf()
41 : m_buf(NULL)
42{
43 m_buf = ccn_charbuf_create();
44}
45
46CcnxCharbuf::CcnxCharbuf(ccn_charbuf *buf)
47 : m_buf(NULL)
48{
49 init(buf);
50}
51
52CcnxCharbuf::CcnxCharbuf(const CcnxCharbuf &other)
53 : m_buf (NULL)
54{
55 init(other.m_buf);
56}
57
58CcnxCharbuf::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
66CcnxCharbuf::~CcnxCharbuf()
67{
68 ccn_charbuf_destroy(&m_buf);
69}
70
71}