00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2010 Nicola Baldo 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Nicola Baldo <nicola@baldo.biz> 00019 */ 00020 00021 00022 00023 #ifndef ENCODER_H 00024 #define ENCODER_H 00025 00026 #include<ptr.h> 00027 #include<packet-combination.h> 00028 00029 00030 00031 namespace Binc { 00032 00033 00046 class PacketCombinationSender 00047 { 00048 public: 00049 00055 virtual void Send (Ptr<const PacketCombination> codedPacket) = 0; 00056 }; 00057 00058 00059 00065 class Encoder 00066 { 00067 public: 00068 Encoder (); 00069 virtual ~Encoder (); 00070 00077 void SetPacketCombinationSender (PacketCombinationSender* s); 00078 00085 void Encode (unsigned int id, Ptr<const BitVector> payload); 00086 00087 protected: 00088 00089 virtual void DoEncode (Ptr<const PacketCombination> p) = 0; 00090 00091 PacketCombinationSender* m_packetCombinationSender; 00092 }; 00093 00094 00095 00104 class SumEncoder : public Encoder 00105 { 00106 public: 00114 SumEncoder (unsigned int k); 00115 00116 protected: 00117 00118 virtual void DoEncode (Ptr<const PacketCombination> p); 00119 00120 unsigned int m_k; 00121 unsigned int m_i; 00122 Ptr<PacketCombination> m_sum; 00123 }; 00124 00125 00132 class BlockCodeEncoder : public Encoder 00133 { 00134 public: 00135 BlockCodeEncoder (std::vector<std::vector<bool> > generatorMatrix); 00136 00137 protected: 00138 BlockCodeEncoder (); 00139 00140 std::vector<std::vector<bool> > m_generatorMatrix; 00141 std::vector<Ptr<PacketCombination> > m_informationPackets; 00142 unsigned int m_numInformationPackets; 00143 unsigned int m_codeLength; 00144 }; 00145 00152 class SystematicBlockCodeEncoder : public BlockCodeEncoder 00153 { 00154 public: 00155 00156 //inherited from Encoder 00157 virtual void Encode (Ptr<const BitVector> payload); 00158 00159 protected: 00160 00161 unsigned int m_nextInformationPacket; 00162 }; 00163 00164 00165 00166 00167 } // namespace Binc 00168 00169 00170 #endif // ENCODER_H