Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * [ Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer) ]
17 : : *
18 : : * All Rights Reserved.
19 : : *
20 : : * For minor contributions see the git repository.
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
29 : : /**
30 : : * Print nicely formatted sheet content to stdout. Indispensable when
31 : : * debugging the unit test code involving testing of sheet contents.
32 : : */
33 : :
34 : : #include <rtl/strbuf.hxx>
35 : : #include <rtl/ustring.hxx>
36 : : #include "document.hxx"
37 : :
38 : : #ifdef WNT
39 : : #if !defined NOMINMAX
40 : : #define NOMINMAX
41 : : #endif
42 : : #include <prewin.h>
43 : : #include <postwin.h>
44 : : #undef NOMINMAX
45 : : #endif
46 : :
47 : : #define MDDS_HASH_CONTAINER_BOOST 1
48 : : #include <mdds/mixed_type_matrix.hpp>
49 : :
50 : : #include <iostream>
51 : :
52 : : using namespace ::com::sun::star;
53 : : using ::rtl::OUString;
54 : : using ::rtl::OUStringBuffer;
55 : : using ::std::cout;
56 : : using ::std::cerr;
57 : : using ::std::endl;
58 : : using ::std::vector;
59 : :
60 : :
61 : 129 : class SheetPrinter
62 : : {
63 : : typedef ::mdds::mixed_type_matrix<OUString, bool> MatrixType;
64 : : public:
65 : 129 : SheetPrinter(size_t rows, size_t cols) :
66 : 129 : maMatrix(rows, cols, ::mdds::matrix_density_sparse_empty) {}
67 : :
68 : 3090 : void set(size_t row, size_t col, const OUString& aStr)
69 : : {
70 : 3090 : maMatrix.set_string(row, col, new OUString(aStr));
71 : 3090 : }
72 : :
73 : : #if CALC_DEBUG_OUTPUT
74 : : void print(const char* header) const
75 : : {
76 : : if (header)
77 : : cout << header << endl;
78 : :
79 : : MatrixType::size_pair_type ns = maMatrix.size();
80 : : vector<sal_Int32> aColWidths(ns.second, 0);
81 : :
82 : : // Calculate column widths first.
83 : : for (size_t row = 0; row < ns.first; ++row)
84 : : {
85 : : for (size_t col = 0; col < ns.second; ++col)
86 : : {
87 : : const OUString* p = maMatrix.get_string(row, col);
88 : : if (aColWidths[col] < p->getLength())
89 : : aColWidths[col] = p->getLength();
90 : : }
91 : : }
92 : :
93 : : // Make the row separator string.
94 : : OUStringBuffer aBuf;
95 : : aBuf.appendAscii("+");
96 : : for (size_t col = 0; col < ns.second; ++col)
97 : : {
98 : : aBuf.appendAscii("-");
99 : : for (sal_Int32 i = 0; i < aColWidths[col]; ++i)
100 : : aBuf.append(sal_Unicode('-'));
101 : : aBuf.appendAscii("-+");
102 : : }
103 : :
104 : : OUString aSep = aBuf.makeStringAndClear();
105 : :
106 : : // Now print to stdout.
107 : : cout << aSep << endl;
108 : : for (size_t row = 0; row < ns.first; ++row)
109 : : {
110 : : cout << "| ";
111 : : for (size_t col = 0; col < ns.second; ++col)
112 : : {
113 : : const OUString* p = maMatrix.get_string(row, col);
114 : : size_t nPadding = aColWidths[col] - p->getLength();
115 : : aBuf.append(*p);
116 : : for (size_t i = 0; i < nPadding; ++i)
117 : : aBuf.append(sal_Unicode(' '));
118 : : cout << aBuf.makeStringAndClear() << " | ";
119 : : }
120 : : cout << endl;
121 : : cout << aSep << endl;
122 : : }
123 : : }
124 : : #else
125 : 129 : void print(const char*) const {}
126 : : #endif
127 : :
128 : : /**
129 : : * Print nested string array which can be copy-n-pasted into the test code
130 : : * for content verification.
131 : : */
132 : : void printArray() const
133 : : {
134 : : #if CALC_DEBUG_OUTPUT
135 : : MatrixType::size_pair_type ns = maMatrix.size();
136 : : for (size_t row = 0; row < ns.first; ++row)
137 : : {
138 : : cout << " { ";
139 : : for (size_t col = 0; col < ns.second; ++col)
140 : : {
141 : : const OUString* p = maMatrix.get_string(row, col);
142 : : if (p->getLength())
143 : : cout << "\"" << *p << "\"";
144 : : else
145 : : cout << "0";
146 : : if (col < ns.second - 1)
147 : : cout << ", ";
148 : : }
149 : : cout << " }";
150 : : if (row < ns.first - 1)
151 : : cout << ",";
152 : : cout << endl;
153 : : }
154 : : #endif
155 : : }
156 : :
157 : : void clear() { maMatrix.clear(); }
158 : : void resize(size_t rows, size_t cols) { maMatrix.resize(rows, cols); }
159 : :
160 : : private:
161 : : MatrixType maMatrix;
162 : : };
163 : :
164 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|