/**
 * @file print_floyd_matrices.hpp
 *
 * CopyRight F. J. Madrid-Cuevas <fjmadrid@uco.es>
 *
 * Sólo se permite el uso de este código en la docencia de las asignaturas sobre
 * Estructuras de Datos de la Universidad de Córdoba.
 *
 * Está prohibido su uso para cualquier otro objetivo.
 */

#include <iomanip>
#include <limits>
#include "print_floyd_matrices.hpp"

std::ostream &
print_floyd_I(std::ostream &out,
              IMatrix const &I)
{
    std::string blanks = "          ";
    std::string unders = "__________";
    size_t field_width = 4;
    out << blanks.substr(0, field_width + 1);
    for (size_t i = 0; i < I.cols(); ++i)
        out << std::setw(field_width) << i;
    out << std::endl;
    out << blanks.substr(0, field_width + 1);
    for (size_t i = 0; i < I.cols(); ++i)
        out << std::setw(field_width) << unders.substr(0, field_width);
    out << std::endl;
    for (size_t r = 0; r < I.rows(); ++r)
    {
        out << std::setw(field_width) << r << '|';
        for (size_t c = 0; c < I.cols(); ++c)
        {
            if (I[r][c] == -1)
                out << std::setw(field_width) << '-';
            else
                out << std::setw(field_width) << I[r][c];
        }
        out << std::endl;
    }
    return out;
}

std::ostream &
print_floyd_D(std::ostream &out,
              FMatrix const &D)
{
    std::string blanks = "          ";
    std::string unders = "__________";
    size_t field_width = 4;
    out << blanks.substr(0, field_width + 1);
    for (size_t i = 0; i < D.cols(); ++i)
        out << std::setw(field_width) << i;
    out << std::endl;
    out << blanks.substr(0, field_width + 1);
    for (size_t i = 0; i < D.cols(); ++i)
        out << std::setw(field_width) << unders.substr(0, field_width);
    out << std::endl;
    for (size_t r = 0; r < D.rows(); ++r)
    {
        out << std::setw(field_width) << r << '|';
        for (size_t c = 0; c < D.cols(); ++c)
        {
            if (D[r][c] == std::numeric_limits<float>::infinity())
                out << std::setw(field_width) << '-';
            else
                out << std::setw(field_width) << D[r][c];
        }
        out << std::endl;
    }
    return out;
}