tools.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. typedef unsigned int uint;
  8. namespace NICE {
  9. void writeLatexTabular(std::ostream& out,
  10. std::vector<std::vector<std::string> >& data,
  11. bool heading,
  12. bool hlines,
  13. bool vlines) {
  14. const uint lines = data.size();
  15. if (lines == 0) {
  16. return;
  17. }
  18. const uint columns = data[0].size();
  19. // latex tabular
  20. out << "\\begin{tabular}{";
  21. for (unsigned int j = 0; j < columns; j++) {
  22. if (vlines) {
  23. out << "|";
  24. }
  25. out << "l";
  26. }
  27. if (vlines) {
  28. out << "|";
  29. }
  30. out << "}" << std::endl;
  31. if (hlines) {
  32. out << "\\hline" << std::endl;
  33. }
  34. // data
  35. for (unsigned int i = 0; i < lines; i++) {
  36. if (i == 1 && heading) {
  37. out << "\\hline" << std::endl;
  38. }
  39. if (i > 0 && hlines) {
  40. out << "\\hline" << std::endl;
  41. }
  42. for (unsigned int j = 0; j < columns; j++) {
  43. if (j > 0) {
  44. out << "&";
  45. }
  46. out << data[i][j];
  47. }
  48. out << "\\\\" << std::endl;
  49. }
  50. // finish
  51. if (hlines) {
  52. out << "\\hline" << std::endl;
  53. }
  54. out << "\\end{tabular}" << std::endl;
  55. }
  56. } // namespace