31 #include "common/types.h" 32 #include "common/simdarrayfwd.h" 33 #include "common/memoryfwd.h" 36 #if defined(__GNUC__) && !defined(_WIN32) && defined(_GLIBCXX_OSTREAM) 37 #define Vc_HACK_OSTREAM_FOR_TTY 1 40 #ifdef Vc_HACK_OSTREAM_FOR_TTY 42 #include <ext/stdio_sync_filebuf.h> 45 namespace Vc_VERSIONED_NAMESPACE
49 #ifdef Vc_HACK_OSTREAM_FOR_TTY 50 class hacked_ostream :
public std::ostream
53 using std::ostream::_M_streambuf;
55 bool mayUseColor(
const std::ostream &os) __attribute__((__const__));
56 bool mayUseColor(
const std::ostream &os)
58 std::basic_streambuf<char> *hack1 =
59 const_cast<std::basic_streambuf<char> *
>(os.*(&hacked_ostream::_M_streambuf));
60 __gnu_cxx::stdio_sync_filebuf<char> *hack =
61 dynamic_cast<__gnu_cxx::stdio_sync_filebuf<char> *
>(hack1);
65 FILE *file = hack->file();
66 return 1 == isatty(fileno(file));
69 bool mayUseColor(
const std::ostream &) {
return false; }
79 static const Type green = {
"\033[1;40;32m"};
80 static const Type yellow = {
"\033[1;40;33m"};
81 static const Type blue = {
"\033[1;40;34m"};
82 static const Type normal = {
"\033[0m"};
84 inline std::ostream &
operator<<(std::ostream &out,
const Type &c)
86 if (mayUseColor(out)) {
116 template <
typename T,
typename Abi>
117 inline std::ostream &operator<<(std::ostream &out, const Vc::Vector<T, Abi> &v)
119 using TT =
typename std::conditional<std::is_same<T, char>::value ||
120 std::is_same<T, unsigned char>::value ||
121 std::is_same<T, signed char>::value,
124 out << AnsiColor::green <<
'[';
126 for (
size_t i = 1; i < v.Size; ++i) {
127 out <<
", " << TT(v[i]);
129 out <<
']' << AnsiColor::normal;
156 template <
typename T,
typename Abi>
157 inline std::ostream &operator<<(std::ostream &out, const Vc::Mask<T, Abi> &m)
159 out << AnsiColor::blue <<
"m[";
160 for (
unsigned int i = 0; i < m.Size; ++i) {
161 if (i > 0 && (i % 4) == 0) {
165 out << AnsiColor::yellow <<
'1';
167 out << AnsiColor::blue <<
'0';
170 out << AnsiColor::blue <<
']' << AnsiColor::normal;
204 template<
typename V,
typename Parent,
typename Dimension,
typename RM>
205 inline std::ostream &operator<<(std::ostream &s, const Vc::MemoryBase<V, Parent, Dimension, RM> &m);
208 template<
typename V,
typename Parent,
typename RM>
209 inline std::ostream &operator<<(std::ostream &out, const MemoryBase<V, Parent, 1, RM> &m )
211 out << AnsiColor::blue <<
'{' << AnsiColor::normal;
212 for (
unsigned int i = 0; i < m.vectorsCount(); ++i) {
213 out << V(m.vector(i));
215 out << AnsiColor::blue <<
'}' << AnsiColor::normal;
219 template<
typename V,
typename Parent,
typename RM>
220 inline std::ostream &operator<<(std::ostream &out, const MemoryBase<V, Parent, 2, RM> &m )
222 out << AnsiColor::blue <<
'{' << AnsiColor::normal;
223 for (
size_t i = 0; i < m.rowsCount(); ++i) {
227 const size_t vcount = m[i].vectorsCount();
228 for (
size_t j = 0; j < vcount; ++j) {
232 out << AnsiColor::blue <<
'}' << AnsiColor::normal;
237 template<
typename T, std::
size_t N>
238 inline std::ostream &operator<<(std::ostream &out, const SimdArray<T, N> &v)
240 out << AnsiColor::green <<
'<' << v[0];
241 for (
size_t i = 1; i < N; ++i) {
242 if (i % 4 == 0) out <<
" |";
245 return out << '>
' << AnsiColor::normal; 248 template<typename T, std::size_t N> 249 inline std::ostream &operator<<(std::ostream &out, const SimdMaskArray<T, N> &m) 251 out << AnsiColor::blue << "«"; 252 for (size_t i = 0; i < N; ++i) { 253 if (i > 0 && (i % 4) == 0) { 257 out << AnsiColor::yellow << '1
'; 259 out << AnsiColor::blue << '0
'; 262 return out << AnsiColor::blue << "»" << AnsiColor::normal; 268 // 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.