tools.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libfbasics - library of some basic tools
  4. * See file License for license information.
  5. */
  6. #include <core/basics/tools.h>
  7. namespace NICE {
  8. void writeLatexTabular(std::ostream& out,
  9. std::vector<std::vector<std::string> >& data,
  10. bool heading,
  11. bool hlines,
  12. bool vlines) {
  13. const uint lines = data.size();
  14. if (lines == 0) {
  15. return;
  16. }
  17. const uint columns = data[0].size();
  18. // latex tabular
  19. out << "\\begin{tabular}{";
  20. for (unsigned int j = 0; j < columns; j++) {
  21. if (vlines) {
  22. out << "|";
  23. }
  24. out << "l";
  25. }
  26. if (vlines) {
  27. out << "|";
  28. }
  29. out << "}" << std::endl;
  30. if (hlines) {
  31. out << "\\hline" << std::endl;
  32. }
  33. // data
  34. for (unsigned int i = 0; i < lines; i++) {
  35. if (i == 1 && heading) {
  36. out << "\\hline" << std::endl;
  37. }
  38. if (i > 0 && hlines) {
  39. out << "\\hline" << std::endl;
  40. }
  41. for (unsigned int j = 0; j < columns; j++) {
  42. if (j > 0) {
  43. out << "&";
  44. }
  45. out << data[i][j];
  46. }
  47. out << "\\\\" << std::endl;
  48. }
  49. // finish
  50. if (hlines) {
  51. out << "\\hline" << std::endl;
  52. }
  53. out << "\\end{tabular}" << std::endl;
  54. }
  55. } // namespace