IBR-DTNSuite  0.8
ibrdtn/ibrdtn/data/ScopeControlHopLimitBlock.cpp
Go to the documentation of this file.
00001 /*
00002  * ScopeControlHopLimitBlock.cpp
00003  *
00004  *  Created on: 05.08.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #include "ibrdtn/data/ScopeControlHopLimitBlock.h"
00009 
00010 namespace dtn
00011 {
00012         namespace data
00013         {
00014                 dtn::data::Block* ScopeControlHopLimitBlock::Factory::create()
00015                 {
00016                         return new ScopeControlHopLimitBlock();
00017                 }
00018 
00019                 ScopeControlHopLimitBlock::ScopeControlHopLimitBlock()
00020                  : dtn::data::Block(ScopeControlHopLimitBlock::BLOCK_TYPE)
00021                 {
00022                         // set the replicate in every fragment bit
00023                         set(REPLICATE_IN_EVERY_FRAGMENT, true);
00024                 }
00025 
00026                 ScopeControlHopLimitBlock::~ScopeControlHopLimitBlock()
00027                 {
00028                 }
00029 
00030                 size_t ScopeControlHopLimitBlock::getHopsToLive() const
00031                 {
00032                         if (_limit.getValue() < _count.getValue()) return 0;
00033                         return _limit.getValue() - _count.getValue();
00034                 }
00035 
00036                 void ScopeControlHopLimitBlock::increment(size_t hops)
00037                 {
00038                         _count += dtn::data::SDNV(hops);
00039                 }
00040 
00041                 void ScopeControlHopLimitBlock::setLimit(size_t hops)
00042                 {
00043                         _count = 0;
00044                         _limit = hops;
00045                 }
00046 
00047                 size_t ScopeControlHopLimitBlock::getLength() const
00048                 {
00049                         return _count.getLength() + _limit.getLength();
00050                 }
00051 
00052                 std::ostream& ScopeControlHopLimitBlock::serialize(std::ostream &stream, size_t &length) const
00053                 {
00054                         stream << _count;
00055                         stream << _limit;
00056                         length += getLength();
00057                         return stream;
00058                 }
00059 
00060                 std::istream& ScopeControlHopLimitBlock::deserialize(std::istream &stream, const size_t)
00061                 {
00062                         stream >> _count;
00063                         stream >> _limit;
00064                         return stream;
00065                 }
00066         } /* namespace data */
00067 } /* namespace dtn */