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) 2012-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 | #ifndef CCNX_CCNX_CHARBUF_H |
| 23 | #define CCNX_CCNX_CHARBUF_H |
| 24 | |
| 25 | #include "ccnx-common.h" |
| 26 | #include <boost/shared_ptr.hpp> |
| 27 | |
| 28 | namespace Ccnx { |
| 29 | |
| 30 | class CcnxCharbuf; |
| 31 | typedef boost::shared_ptr<CcnxCharbuf> CcnxCharbufPtr; |
| 32 | |
| 33 | // This class is mostly used in CcnxWrapper; users should not be directly using this class |
| 34 | // The main purpose of this class to is avoid manually create and destroy charbuf everytime |
| 35 | class CcnxCharbuf |
| 36 | { |
| 37 | public: |
| 38 | CcnxCharbuf(); |
| 39 | CcnxCharbuf(ccn_charbuf *buf); |
| 40 | CcnxCharbuf(const CcnxCharbuf &other); |
| 41 | CcnxCharbuf(const void *buf, size_t length); |
| 42 | ~CcnxCharbuf(); |
| 43 | |
| 44 | // expose internal data structure, use with caution!! |
| 45 | ccn_charbuf * |
| 46 | getBuf() { return m_buf; } |
| 47 | |
| 48 | const ccn_charbuf * |
| 49 | getBuf() const { return m_buf; } |
| 50 | |
| 51 | const unsigned char * |
| 52 | buf () const |
| 53 | { return m_buf->buf; } |
| 54 | |
| 55 | size_t |
| 56 | length () const |
| 57 | { return m_buf->length; } |
| 58 | |
| 59 | private: |
| 60 | void init(ccn_charbuf *buf); |
| 61 | |
| 62 | protected: |
| 63 | ccn_charbuf *m_buf; |
| 64 | }; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | #endif // CCNX_CCNX_CHARBUF_H |