1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef SC_DEBUG_HELPER_HXX
11 #define SC_DEBUG_HELPER_HXX
14 * Print nicely formatted sheet content to stdout. Indispensable when
15 * debugging the unit test code involving testing of sheet contents.
18 #include <rtl/strbuf.hxx>
19 #include <rtl/ustring.hxx>
30 #define MDDS_HASH_CONTAINER_BOOST 1
31 #include <mdds/mixed_type_matrix.hpp>
35 using namespace ::com::sun::star
;
44 typedef ::mdds::mixed_type_matrix
<OUString
, bool> MatrixType
;
46 SheetPrinter(size_t rows
, size_t cols
) :
47 maMatrix(rows
, cols
, ::mdds::matrix_density_sparse_empty
) {}
49 void set(size_t row
, size_t col
, const OUString
& aStr
)
51 maMatrix
.set_string(row
, col
, new OUString(aStr
));
55 void print(const char* header
) const
58 cout
<< header
<< endl
;
60 MatrixType::size_pair_type ns
= maMatrix
.size();
61 vector
<sal_Int32
> aColWidths(ns
.second
, 0);
63 // Calculate column widths first.
64 for (size_t row
= 0; row
< ns
.first
; ++row
)
66 for (size_t col
= 0; col
< ns
.second
; ++col
)
68 const OUString
* p
= maMatrix
.get_string(row
, col
);
69 if (aColWidths
[col
] < p
->getLength())
70 aColWidths
[col
] = p
->getLength();
74 // Make the row separator string.
76 aBuf
.appendAscii("+");
77 for (size_t col
= 0; col
< ns
.second
; ++col
)
79 aBuf
.appendAscii("-");
80 for (sal_Int32 i
= 0; i
< aColWidths
[col
]; ++i
)
81 aBuf
.append(sal_Unicode('-'));
82 aBuf
.appendAscii("-+");
85 OUString aSep
= aBuf
.makeStringAndClear();
87 // Now print to stdout.
89 for (size_t row
= 0; row
< ns
.first
; ++row
)
92 for (size_t col
= 0; col
< ns
.second
; ++col
)
94 const OUString
* p
= maMatrix
.get_string(row
, col
);
95 size_t nPadding
= aColWidths
[col
] - p
->getLength();
97 for (size_t i
= 0; i
< nPadding
; ++i
)
98 aBuf
.append(sal_Unicode(' '));
99 cout
<< aBuf
.makeStringAndClear() << " | ";
102 cout
<< aSep
<< endl
;
106 void print(const char*) const {}
110 * Print nested string array which can be copy-n-pasted into the test code
111 * for content verification.
113 void printArray() const
115 #if CALC_DEBUG_OUTPUT
116 MatrixType::size_pair_type ns
= maMatrix
.size();
117 for (size_t row
= 0; row
< ns
.first
; ++row
)
120 for (size_t col
= 0; col
< ns
.second
; ++col
)
122 const OUString
* p
= maMatrix
.get_string(row
, col
);
124 cout
<< "\"" << *p
<< "\"";
127 if (col
< ns
.second
- 1)
131 if (row
< ns
.first
- 1)
138 void clear() { maMatrix
.clear(); }
139 void resize(size_t rows
, size_t cols
) { maMatrix
.resize(rows
, cols
); }
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */