#ifndef NLSR_RTC_HPP
#define NLSR_RTC_HPP

#include <list>
#include <iostream>

namespace nlsr
{

  class Map;
  class RoutingTable;
  class Nlsr;


  using namespace std;

  class RoutingTableCalculator
  {
  public:
    RoutingTableCalculator()
    {
    }
    RoutingTableCalculator(int rn)
    {
      numOfRouter=rn;
    }
  protected:
    void allocateAdjMatrix();
    void initMatrix();
    void makeAdjMatrix(Nlsr& pnlsr,Map pMap);
    void printAdjMatrix();
    int getNumOfLinkfromAdjMatrix(int sRouter);
    void freeAdjMatrix();
    void adjustAdMatrix(int source, int link, double linkCost);
    void getLinksFromAdjMatrix(int *links, double *linkCosts, int source);

    void allocateLinks();
    void allocateLinkCosts();
    void freeLinks();
    void freeLinksCosts();

    void setNoLink(int nl)
    {
      vNoLink=nl;
    }

  protected:
    double** adjMatrix;
    int numOfRouter;

    int vNoLink;
    int* links;
    double* linkCosts;
  };

  class LinkStateRoutingTableCalculator: public RoutingTableCalculator
  {
  public:
    LinkStateRoutingTableCalculator(int rn)
      : EMPTY_PARENT(-12345)
      , INF_DISTANCE(2147483647)
      , NO_MAPPING_NUM(-1)
      , NO_NEXT_HOP(-12345)
    {
      numOfRouter=rn;
    }


    void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);


  private:
    void doDijkstraPathCalculation(int sourceRouter);
    void sortQueueByDistance(int* Q, double* dist,int start,int element);
    int isNotExplored(int* Q, int u,int start, int element);
    void printAllLsPath(int sourceRouter);
    void printLsPath(int destRouter);
    void addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
                                        Map& pMap,int sourceRouter);
    int getLsNextHop(int dest, int source);

    void allocateParent();
    void allocateDistance();
    void freeParent();
    void freeDistance();




  private:
    int* m_parent;
    double* m_distance;


    const int EMPTY_PARENT;
    const double INF_DISTANCE;
    const int NO_MAPPING_NUM;
    const int NO_NEXT_HOP;

  };

  class HypRoutingTableCalculator: public RoutingTableCalculator
  {
  public:
    HypRoutingTableCalculator(int rn)
      :  MATH_PI(3.141592654)
    {
      numOfRouter=rn;
      m_isDryRun=0;
    }
    HypRoutingTableCalculator(int rn, int idr)
      :  MATH_PI(3.141592654)
    {
      numOfRouter=rn;
      m_isDryRun=idr;
    }

    void calculatePath(Map& pMap, RoutingTable& rt, Nlsr& pnlsr);

  private:
    void allocateLinkFaces();
    void allocateDistanceToNeighbor();
    void allocateDistFromNbrToDest();
    void freeLinkFaces();
    void freeDistanceToNeighbor();
    void freeDistFromNbrToDest();

    double getHyperbolicDistance(Nlsr& pnlsr,Map& pMap, int src, int dest);
    void addHypNextHopsToRoutingTable(Nlsr& pnlsr,Map& pMap,
                                      RoutingTable& rt, int noFaces,int dest);

  private:
    bool m_isDryRun;

    int* m_linkFaces;
    double* m_distanceToNeighbor;
    double* m_distFromNbrToDest;

    const double MATH_PI;

  };

}//namespace nlsr

#endif
