iostream: use consistent ostream format

This commit is contained in:
Danny Robson 2016-03-11 13:01:57 +11:00
parent 7f4cf49931
commit 809e7b0421
12 changed files with 23 additions and 56 deletions

View File

@ -382,12 +382,12 @@ namespace util {
template <size_t S, typename T>
std::ostream&
util::operator<< (std::ostream &os, util::colour<S,T> c) {
os << "colour(";
os << "[";
std::transform (std::cbegin (c),
std::cend (c),
infix_iterator<stream::numeric<T>> (os, ", "),
stream::to_numeric<T>);
os << ")";
os << "]";
return os;
}

View File

@ -21,6 +21,7 @@
#include "../stream.hpp"
#include <ostream>
#include <algorithm>
namespace util {
template <

View File

@ -232,25 +232,9 @@ template bool util::debug::valid (const extent<2,uint32_t>&);
template bool util::debug::valid (const extent<2,uint64_t>&);
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
std::ostream&
util::operator<< (std::ostream &os, extent<S,T> e)
{
os << "[";
std::transform (std::cbegin (e.data),
std::cend (e.data),
infix_iterator<stream::numeric<T>> (os, ", "),
stream::to_numeric<T>);
os << "]";
return os;
}
//-----------------------------------------------------------------------------
#define INSTANTIATE_S_T(S,T) \
template struct util::extent<S,T>; \
template std::ostream& util::operator<< (std::ostream&, extent<S,T>);
#define INSTANTIATE_S_T(S,T) \
template struct util::extent<S,T>;
#define INSTANTIATE(T) \
INSTANTIATE_S_T(1,T) \

View File

@ -21,8 +21,6 @@
#include "vector.hpp"
#include "point.hpp"
#include <iostream>
namespace util {
/**
@ -107,9 +105,6 @@ namespace util {
using extent_range2i = extent_range2<typename extent2i::value_type>;
using extent_range3u = extent_range2<typename extent3u::value_type>;
template <size_t S, typename T>
std::ostream& operator<< (std::ostream&, util::extent<S,T>);
}

View File

@ -17,12 +17,11 @@
#include "fourcc.hpp"
using util::fourcc;
using std::ostream;
static_assert (sizeof(fourcc) == 4, "fourcc must be a 4 byte POD");
///////////////////////////////////////////////////////////////////////////////
fourcc
fourcc::from_chars (uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
fourcc lhs;
@ -36,6 +35,7 @@ fourcc::from_chars (uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
}
//-----------------------------------------------------------------------------
fourcc
fourcc::from_string (const char data[4]) {
fourcc lhs;
@ -49,6 +49,7 @@ fourcc::from_string (const char data[4]) {
}
///////////////////////////////////////////////////////////////////////////////
bool
fourcc::operator== (const char rhs[4]) const {
return data[0] == rhs[0] &&
@ -58,6 +59,7 @@ fourcc::operator== (const char rhs[4]) const {
}
///////////////////////////////////////////////////////////////////////////////
fourcc::operator uint32_t (void) const {
return static_cast<uint32_t> (data[0] << 24U |
data[1] << 16U |
@ -66,9 +68,9 @@ fourcc::operator uint32_t (void) const {
}
ostream&
operator<< (ostream &os, fourcc f) {
///////////////////////////////////////////////////////////////////////////////
std::ostream&
util::operator<< (std::ostream &os, fourcc f) {
os << f.data[0] << f.data[1] << f.data[2] << f.data[3];
return os;
}

View File

@ -17,7 +17,7 @@
#ifndef __UTIL_FOURCC_HPP
#define __UTIL_FOURCC_HPP
#include <iostream>
#include <ostream>
#include <cstdint>
namespace util {
@ -30,8 +30,9 @@ namespace util {
bool operator== (const char[4]) const;
operator uint32_t (void) const;
};
std::ostream& operator<< (std::ostream&, util::fourcc);
}
std::ostream& operator<< (std::ostream&, util::fourcc);
#endif

View File

@ -18,7 +18,8 @@
#define __UTIL_GUID_HPP
#include <cstdint>
#include <iostream>
#include <ostream>
#include <istream>
class guid {
public:

View File

@ -20,7 +20,7 @@
#include "vector.hpp"
#include "matrix.hpp"
#include <iostream>
#include <ostream>
namespace util {
@ -82,7 +82,8 @@ namespace util {
typedef quaternion<float> quaternionf;
template <typename T>
std::ostream& operator<< (std::ostream&, quaternion<T>);
std::ostream&
operator<< (std::ostream&, quaternion<T>);
}

View File

@ -365,8 +365,7 @@ util::region<S,T>::UNIT (util::point<S,T>{0}, util::extent<S,T>{1});
template <size_t S, typename T>
std::ostream&
util::operator<< (std::ostream &os, const util::region<S,T> &rhs) {
os << "region(" << rhs.p << ", " << rhs.e << ")";
return os;
return os << "{position: " << rhs.p << ", extent: " << rhs.e << "}";
}

View File

@ -23,6 +23,8 @@
#include "vector.hpp"
#include "types/traits.hpp"
#include <ostream>
namespace util {
/**
* A two-dimensional rectangle, with size and position.

View File

@ -248,21 +248,6 @@ util::vector<S,T>::sanity (void) const
///////////////////////////////////////////////////////////////////////////////
// ostream
template <size_t S, typename T>
std::ostream&
util::operator<< (std::ostream &os, util::vector<S,T> v)
{
os << "vec" << S << "(" << v.data[0];
for (size_t i = 1; i < S; ++i)
os << ", " << v.data[i];
os << ")";
return os;
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
const json::tree::node&
util::operator>> (const json::tree::node &node, util::vector<S,T> &v)
@ -284,7 +269,6 @@ util::operator>> (const json::tree::node &node, util::vector<S,T> &v)
//-----------------------------------------------------------------------------
#define INSTANTIATE_S_T(S,T) \
template struct util::vector<S,T>; \
template std::ostream& util::operator<< (std::ostream&, util::vector<S,T> v); \
template const json::tree::node& util::operator>> (const json::tree::node&, util::vector<S,T>&);

View File

@ -21,7 +21,6 @@
#include "coord.hpp"
#include <array>
#include <iostream>
#include <initializer_list>
namespace util {
@ -67,8 +66,6 @@ namespace util {
template <typename T> vector<3,T> from_euler (vector<2,T>);
// output and serialisation operators
template <size_t S, typename T> std::ostream& operator<< (std::ostream&, vector<S,T>);
template <size_t S, typename T>
const json::tree::node& operator>> (const json::tree::node&, vector<S,T>&);