27 void PrintAsTable(
const T<VaultRecordRef>& container,
bool isPrintId =
false,
const std::size_t& amountOfRecords = -1,
const std::vector<std::string> keys = {})
noexcept
29 if (container.empty())
31 std::cout <<
"The keys could not be retrieved because the container is empty" << std::endl;
32 std::cout <<
" (0 records)" << std::endl;
36 std::vector<std::string>* realKeys;
38 realKeys =
new std::vector<std::string>(container.front().GetKeys());
40 realKeys =
const_cast<std::vector<std::string>*
>(&keys);
42 std::vector<std::size_t> maxLengths(realKeys->size());
45 for (std::size_t i = 0; i < realKeys->size(); ++i)
46 maxLengths[i] = (*realKeys)[i].length();
49 std::string dataString;
50 for (std::size_t i = 0; i < realKeys->size(); ++i)
52 for (
const auto& record : container)
54 record.GetDataAsString((*realKeys)[i], dataString);
55 if (dataString.length() > maxLengths[i]) maxLengths[i] = dataString.length();
61 for (std::size_t i = 0; i < realKeys->size(); ++i)
64 for (std::size_t j = 0; j < maxLengths[i]; ++j) std::cout <<
"-";
67 std::cout << std::endl;
71 for (std::size_t i = 0; i < realKeys->size(); ++i)
73 std::cout <<
" " << (*realKeys)[i];
74 for (std::size_t j = (*realKeys)[i].length(); j < maxLengths[i]; ++j) std::cout <<
" ";
77 std::cout << std::endl;
81 for (std::size_t i = 0; i < realKeys->size(); ++i)
84 for (std::size_t j = 0; j < maxLengths[i]; ++j) std::cout <<
"-";
87 std::cout << std::endl;
90 std::size_t counter = 0;
91 for (
const auto& record : container)
94 for (std::size_t i = 0; i < realKeys->size(); ++i)
96 record.GetDataAsString((*realKeys)[i], dataString);
97 std::cout <<
" " << dataString;
98 for (std::size_t j = dataString.length(); j < maxLengths[i]; ++j) std::cout <<
" ";
102 std::cout <<
" " << record.GetRecordUniqueId() << std::endl;
104 std::cout << std::endl;
107 if (counter == amountOfRecords)
break;
111 if (amountOfRecords >= container.size())
114 for (std::size_t i = 0; i < realKeys->size(); ++i)
117 for (std::size_t j = 0; j < maxLengths[i]; ++j) std::cout <<
"-";
120 std::cout << std::endl;
125 for (std::size_t i = 0; i < realKeys->size(); ++i)
128 for (std::size_t j = 0; j < maxLengths[i]; ++j) std::cout <<
"~";
131 std::cout << std::endl;
134 std::cout <<
" (" << container.size() <<
" records)" << std::endl;
void PrintAsTable(const T< VaultRecordRef > &container, bool isPrintId=false, const std::size_t &amountOfRecords=-1, const std::vector< std::string > keys={}) noexcept
A method for printing data as tables.
Definition PrintAsTable.h:27