Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef _CCNB_PARSER_BLOCK_H_ |
| 22 | #define _CCNB_PARSER_BLOCK_H_ |
| 23 | |
| 24 | #include "ns3/simple-ref-count.h" |
| 25 | #include "ns3/buffer.h" |
| 26 | #include "ns3/ptr.h" |
| 27 | |
| 28 | // visitors |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 29 | #include "../visitors/void-no-argu-visitor.h" |
| 30 | #include "../visitors/void-visitor.h" |
| 31 | #include "../visitors/no-argu-visitor.h" |
| 32 | #include "../visitors/visitor.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 33 | |
| 34 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 35 | namespace ndn { |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 36 | namespace CcnbParser { |
| 37 | |
| 38 | /** |
| 39 | * \ingroup ccnx-ccnb |
| 40 | * \brief Base class for ccnb-encoded node |
| 41 | * |
| 42 | * This class provides a static method to create a new block |
| 43 | * (recursively) from the stream |
| 44 | * |
| 45 | * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html |
| 46 | */ |
| 47 | class Block : public SimpleRefCount<Block> |
| 48 | { |
| 49 | public: |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 50 | // static int counter; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 51 | /** |
| 52 | * \brief Parsing stream (recursively) and creating a parsed BLOCK |
| 53 | * object |
| 54 | * |
| 55 | * \param start buffer iterator pointing to the start position for parsing |
| 56 | * \returns parsed ccnb-encoded block, that could contain more block inside |
| 57 | */ |
| 58 | static Ptr<Block> |
| 59 | ParseBlock (Buffer::Iterator &start); |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 60 | |
| 61 | virtual ~Block (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 63 | virtual void accept( VoidNoArguVisitor &v ) = 0; ///< @brief Accept visitor void(*)() |
| 64 | virtual void accept( VoidVisitor &v, boost::any param ) = 0; ///< @brief Accept visitor void(*)(boost::any) |
| 65 | virtual boost::any accept( NoArguVisitor &v ) = 0; ///< @brief Accept visitor boost::any(*)() |
| 66 | virtual boost::any accept( Visitor &v, boost::any param ) = 0; ///< @brief Accept visitor boost::any(*)(boost::any) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 69 | /** |
| 70 | * @brief Necessary until Buffer::Iterator gets PeekU8 call |
| 71 | * @param i buffer iterator |
| 72 | * @return peeked uint8_t value |
| 73 | */ |
Alexander Afanasyev | c1e33eb | 2012-05-31 12:13:17 -0700 | [diff] [blame] | 74 | inline |
| 75 | uint8_t |
| 76 | BufferIteratorPeekU8 (Buffer::Iterator &i) |
| 77 | { |
| 78 | uint8_t ret = i.ReadU8 (); |
| 79 | i.Prev (); |
| 80 | return ret; |
| 81 | } |
| 82 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 85 | } |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 86 | |
| 87 | #endif // _CCNB_PARSER_BLOCK_H_ |