ccsoft  0.0.0
Convolutional codes library with soft decision decoding
/shared/development/google_code/rssoft/libccsoft/lib/CC_TreeNodeEdge_FA.h
Go to the documentation of this file.
00001 /*
00002  Copyright 2013 Edouard Griffiths <f4exb at free dot fr>
00003 
00004  This file is part of CCSoft. A Convolutional Codes Soft Decoding library
00005 
00006  This program is free software; you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation; either version 2 of the License, or
00009  (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
00019 
00020  Combination of a Node and its incoming Edge in the convolutional code tree
00021  (node+edge combo). In a tree structure you don't need to store nodes and
00022  edges as nodes have a single incoming edge. So a node can incorporate
00023  its incoming edge.
00024 
00025  This version uses fixed arrays for registers and forward node-edges
00026 
00027  */
00028 #ifndef __CC_TREE_NODE_EDGE_FA_H__
00029 #define __CC_TREE_NODE_EDGE_FA_H__
00030 
00031 #include "CC_TreeNodeEdge_base.h"
00032 #include "CC_EncodingRegisters_FA.h"
00033 
00034 #include <vector>
00035 #include <array>
00036 #include <algorithm>
00037 
00038 namespace ccsoft
00039 {
00040 
00051 template<typename T_IOSymbol, typename T_Register, typename T_Tag, unsigned int N_k>
00052 class CC_TreeNodeEdge_FA : public CC_TreeNodeEdge_base<T_IOSymbol, T_Tag>, public CC_EncodingRegisters_FA<T_Register, N_k>
00053 {
00054 
00055 public:
00065         CC_TreeNodeEdge_FA(unsigned int _id,
00066                         CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *_p_incoming_node_edge,
00067                         const T_IOSymbol& _in_symbol,
00068             float _incoming_edge_metric,
00069             float _path_metric,
00070             int _depth) :
00071                 CC_TreeNodeEdge_base<T_IOSymbol, T_Tag>(_id, _in_symbol, _incoming_edge_metric, _path_metric, _depth),
00072                 p_incoming_node_edge(_p_incoming_node_edge)
00073     {
00074         clear_outgoing_edges();
00075     }
00076 
00080         ~CC_TreeNodeEdge_FA()
00081         {
00082                 // deletes all outgoing edge+nodes
00083                 delete_outgoing_node_edges();
00084         }
00085 
00090     void set_outgoing_node_edge(CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *p_outgoing_node_edge, unsigned int index)
00091     {
00092         p_outgoing_node_edges[index] = p_outgoing_node_edge;
00093     }
00094 
00098     void delete_outgoing_node_edges()
00099     {
00100         typename std::array<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*, (1<<N_k)>::iterator ne_it = p_outgoing_node_edges.begin();
00101 
00102         for (; ne_it != p_outgoing_node_edges.end(); ++ne_it)
00103         {
00104             if (*ne_it)
00105             {
00106                 delete *ne_it;
00107                 *ne_it = 0;
00108             }
00109         }
00110 
00111         clear_outgoing_edges();
00112     }
00113 
00117     bool valid_outgoing_node_edges(unsigned int index_limit = (1<<N_k))
00118     {
00119         for (unsigned int i=0; i<(1<<N_k); i++)
00120         {
00121             if (i == index_limit)
00122             {
00123                 break;
00124             }
00125 
00126             if (p_outgoing_node_edges[i] == 0)
00127             {
00128                 return false;
00129             }
00130         }
00131 
00132         return true;
00133     }
00134 
00138     const std::array<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*, (1<<N_k)>& get_outgoing_node_edges() const
00139     {
00140         return p_outgoing_node_edges;
00141     }
00142 
00146     std::array<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*, (1<<N_k)>& get_outgoing_node_edges()
00147     {
00148         return p_outgoing_node_edges;
00149     }
00150 
00154     CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *get_incoming_node_edge()
00155     {
00156         return p_incoming_node_edge;
00157     }
00158     
00159 protected:
00160     void clear_outgoing_edges()
00161     {
00162         std::fill(p_outgoing_node_edges.begin(), p_outgoing_node_edges.end(), (CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*) 0);
00163         //p_outgoing_node_edges.fill(0);
00164     }
00165 
00166     std::array<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*, (1<<N_k)> p_outgoing_node_edges; 
00167     CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *p_incoming_node_edge; 
00168 };
00169 
00170 } // namespace ccsoft
00171 
00172 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines