blob: 842c8403dbbce60c993711758326297afedc7055 [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
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070022#include "ndnx-charbuf.h"
Alexander Afanasyev452645b2013-02-24 15:41:29 -080023
24using namespace std;
25
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070026namespace Ndnx {
Alexander Afanasyev452645b2013-02-24 15:41:29 -080027
28void
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070029NdnxCharbuf::init(ndn_charbuf *buf)
Alexander Afanasyev452645b2013-02-24 15:41:29 -080030{
31 if (buf != NULL)
32 {
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070033 m_buf = ndn_charbuf_create();
34 ndn_charbuf_reserve(m_buf, buf->length);
Alexander Afanasyev452645b2013-02-24 15:41:29 -080035 memcpy(m_buf->buf, buf->buf, buf->length);
36 m_buf->length = buf->length;
37 }
38}
39
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070040NdnxCharbuf::NdnxCharbuf()
Alexander Afanasyev452645b2013-02-24 15:41:29 -080041 : m_buf(NULL)
42{
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070043 m_buf = ndn_charbuf_create();
Alexander Afanasyev452645b2013-02-24 15:41:29 -080044}
45
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070046NdnxCharbuf::NdnxCharbuf(ndn_charbuf *buf)
Alexander Afanasyev452645b2013-02-24 15:41:29 -080047 : m_buf(NULL)
48{
49 init(buf);
50}
51
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070052NdnxCharbuf::NdnxCharbuf(const NdnxCharbuf &other)
Alexander Afanasyev452645b2013-02-24 15:41:29 -080053 : m_buf (NULL)
54{
55 init(other.m_buf);
56}
57
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070058NdnxCharbuf::NdnxCharbuf(const void *buf, size_t length)
Alexander Afanasyev452645b2013-02-24 15:41:29 -080059{
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070060 m_buf = ndn_charbuf_create ();
61 ndn_charbuf_reserve (m_buf, length);
Alexander Afanasyev452645b2013-02-24 15:41:29 -080062 memcpy (m_buf->buf, buf, length);
63 m_buf->length = length;
64}
65
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070066NdnxCharbuf::~NdnxCharbuf()
Alexander Afanasyev452645b2013-02-24 15:41:29 -080067{
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070068 ndn_charbuf_destroy(&m_buf);
Alexander Afanasyev452645b2013-02-24 15:41:29 -080069}
70
71}