Commit 3b1cbcab authored by Martin Marinov's avatar Martin Marinov
Browse files

Added Base::IOutputStream::print() function for arrays and redirected existing...

Added Base::IOutputStream::print() function for arrays and redirected existing array-stream functions to it due to some reported issues with array streaming,
parent d9e10c4f
......@@ -49,76 +49,72 @@ public:
virtual IOutputStream& print(const double) = 0;
virtual IOutputStream& print(const char* const) = 0;
virtual IOutputStream& print(const Command&) = 0;
/*! Print an array of ElementT */
template <typename ElementT>
inline IOutputStream& print(const size_t _nmbr, const ElementT* _elems)
{
*this << "[ ";
for (size_t i = 0; i < _nmbr; ++i)
*this << _elems[i] << " ";
*this << "]";
return *this;
}
};
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const int _i);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const int _i);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const double _d);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const double _d);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const char* const _s);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const char* const _s);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const char _c);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const char _c);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const size_t _i);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const size_t _i);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const unsigned int _i);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const unsigned int _i);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const float _f);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const float _f);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const std::string& _s);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const std::string& _s);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const Command& _co);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const Command& _co);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds, const Command::Type _cmd_type);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const Command::Type _cmd_type);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _ds,
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os,
const boost::filesystem::path& _path);
// IStream operator for std::vector<>
template< typename ElementT>
IOutputStream& operator<<(IOutputStream& _ds, const std::vector<ElementT>& _vec)
template <typename ElementT>
IOutputStream& operator<<(IOutputStream& _os, const std::vector<ElementT>& _vec)
{
_ds << "[ ";
for (typename std::vector<ElementT>::const_iterator el_it = _vec.begin(); el_it != _vec.end(); ++el_it)
{
const ElementT el = *el_it;
_ds << el << " ";
}
_ds << "]";
return _ds;
return _os.print(_vec.size(), &_vec[0]);
}
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
// IStream operator for std::array<>
template< typename ElementT, size_t _el_nmbr>
IOutputStream& operator<<(IOutputStream& _ds,
const std::array<ElementT, _el_nmbr>& _vec)
template <typename ElementT, size_t _nmbr>
IOutputStream& operator<<(IOutputStream& _os,
const std::array<ElementT, _nmbr>& _vec)
{
_ds << "[ ";
for (const auto el : _vec)
_ds << el << " ";
_ds << "]";
return _ds;
return _os.print(_nmbr, &_vec[0]);
}
#endif
// IStream operator for fixed size arrays
template <typename ElementT, size_t _el_nmbr>
IOutputStream& operator<<(IOutputStream& _ds, const ElementT(&_arr)[_el_nmbr])
template <typename ElementT, size_t _nmbr>
IOutputStream& operator<<(IOutputStream& _os, const ElementT(&_vec)[_nmbr])
{
_ds << "[ ";
for (size_t i = 0; i < _el_nmbr; ++i)
_ds << _arr[i] << " ";
_ds << "]";
return _ds;
return _os.print(_nmbr, &_vec[0]);
}
// IStream std::pair<>
template <typename T0, typename T1>
IOutputStream& operator<<(IOutputStream& _ds, const std::pair<T0, T1>& _pair)
IOutputStream& operator<<(IOutputStream& _os, const std::pair<T0, T1>& _pair)
{
_ds << "(" << _pair.first << ", " << _pair.second << ")";
return _ds;
_os << "(" << _pair.first << ", " << _pair.second << ")";
return _os;
}
template <class StreamT>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment