32 #include "common/types.h"
33 #include "common/simdarrayfwd.h"
34 #include "common/memoryfwd.h"
37 #if defined(__GNUC__) && !defined(_WIN32) && defined(_GLIBCXX_OSTREAM)
38 #define Vc_HACK_OSTREAM_FOR_TTY 1
41 #ifdef Vc_HACK_OSTREAM_FOR_TTY
43 #include <ext/stdio_sync_filebuf.h>
46 namespace Vc_VERSIONED_NAMESPACE
50 #ifdef Vc_HACK_OSTREAM_FOR_TTY
51 class hacked_ostream :
public std::ostream
54 using std::ostream::_M_streambuf;
56 bool mayUseColor(
const std::ostream &os) __attribute__((__const__));
57 bool mayUseColor(
const std::ostream &os)
59 std::basic_streambuf<char> *hack1 =
60 const_cast<std::basic_streambuf<char> *
>(os.*(&hacked_ostream::_M_streambuf));
61 __gnu_cxx::stdio_sync_filebuf<char> *hack =
62 dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char> *
>(hack1);
66 FILE *file = hack->file();
67 return 1 == isatty(fileno(file));
70 bool mayUseColor(
const std::ostream &) {
return false; }
80 static const Type green = {
"\033[1;40;32m"};
81 static const Type yellow = {
"\033[1;40;33m"};
82 static const Type blue = {
"\033[1;40;34m"};
83 static const Type normal = {
"\033[0m"};
85 inline std::ostream &
operator<<(std::ostream &out,
const Type &c)
87 if (mayUseColor(out)) {
117 template <
typename T,
typename Abi>
118 inline std::ostream &operator<<(std::ostream &out, const Vc::Vector<T, Abi> &v)
120 using TT =
typename std::conditional<std::is_same<T, char>::value ||
121 std::is_same<T, unsigned char>::value ||
122 std::is_same<T, signed char>::value,
125 out << AnsiColor::green <<
'[';
127 for (
size_t i = 1; i < v.Size; ++i) {
128 out <<
", " << TT(v[i]);
130 out <<
']' << AnsiColor::normal;
157 template <
typename T,
typename Abi>
158 inline std::ostream &operator<<(std::ostream &out, const Vc::Mask<T, Abi> &m)
160 out << AnsiColor::blue <<
"m[";
161 for (
unsigned int i = 0; i < m.Size; ++i) {
162 if (i > 0 && (i % 4) == 0) {
166 out << AnsiColor::yellow <<
'1';
168 out << AnsiColor::blue <<
'0';
171 out << AnsiColor::blue <<
']' << AnsiColor::normal;
205 template<
typename V,
typename Parent,
typename Dimension,
typename RM>
206 inline std::ostream &operator<<(std::ostream &s, const Vc::MemoryBase<V, Parent, Dimension, RM> &m);
209 template<
typename V,
typename Parent,
typename RM>
210 inline std::ostream &operator<<(std::ostream &out, const MemoryBase<V, Parent, 1, RM> &m )
212 out << AnsiColor::blue <<
'{' << AnsiColor::normal;
213 for (
unsigned int i = 0; i < m.vectorsCount(); ++i) {
214 out << V(m.vector(i));
216 out << AnsiColor::blue <<
'}' << AnsiColor::normal;
220 template<
typename V,
typename Parent,
typename RM>
221 inline std::ostream &operator<<(std::ostream &out, const MemoryBase<V, Parent, 2, RM> &m )
223 out << AnsiColor::blue <<
'{' << AnsiColor::normal;
224 for (
size_t i = 0; i < m.rowsCount(); ++i) {
228 const size_t vcount = m[i].vectorsCount();
229 for (
size_t j = 0; j < vcount; ++j) {
233 out << AnsiColor::blue <<
'}' << AnsiColor::normal;
238 template<
typename T, std::
size_t N>
239 inline std::ostream &operator<<(std::ostream &out, const SimdArray<T, N> &v)
241 out << AnsiColor::green <<
'<' << v[0];
242 for (
size_t i = 1; i < N; ++i) {
243 if (i % 4 == 0) out <<
" |";
246 return out << '>
' << AnsiColor::normal;
249 template<typename T, std::size_t N>
250 inline std::ostream &operator<<(std::ostream &out, const SimdMaskArray<T, N> &m)
252 out << AnsiColor::blue << "«";
253 for (size_t i = 0; i < N; ++i) {
254 if (i > 0 && (i % 4) == 0) {
258 out << AnsiColor::yellow << '1
';
260 out << AnsiColor::blue << '0
';
263 return out << AnsiColor::blue << "»" << AnsiColor::normal;
269 // vim: ft=cpp foldmethod=marker
Common::AdaptSubscriptOperator< std::vector< T, Allocator >> vector
An adapted std::vector container with an additional subscript operator which implements gather and sc...
std::ostream & operator<<(std::ostream &s, const Vc::MemoryBase< V, Parent, Dimension, RM > &m)
Prints the contents of a Memory object into a stream object.