Commit e876c815 authored by Martin Marinov's avatar Martin Marinov

Improved portability inc. support for x32 platforms. Various minor fixes.

parent 3e56d034
......@@ -32,3 +32,9 @@
#endif
// configure some defines based on the platform
#if (_MSC_VER >= 1700 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#define STD_ARRAY_AVAILABLE
#endif
......@@ -95,10 +95,9 @@ public:
return priority_;
}
const char* filename() const
{
if (this && (!flnm_.empty())) return flnm_.c_str();
return NULL;
const char* filename() const
{
return flnm_.empty() ? NULL : flnm_.c_str();
}
void clear()
......
......@@ -31,9 +31,10 @@
#include <sstream>
#include <vector>
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#include <array>
#endif
// ERROR is occasionally defined in system headers, e.g., windows.h
#ifdef ERROR
#undef ERROR
#endif//ERROR
namespace Debug {
......@@ -115,6 +116,15 @@ private:
BASEDLLEXPORT extern void warning(const std::string& _wrng, const ::Base::CodeLink& _lnk);
BASEDLLEXPORT extern void error(const std::string& _err, const ::Base::CodeLink& _lnk);
// TODO: Move this upstream to namespace Base?!
template <typename T>
std::string to_string(const T& _t)
{
std::ostringstream ss;
ss << _t;
return ss.str();
}
}//namespace Debug
// Obsolete, use gradually removed
......@@ -147,27 +157,12 @@ BASEDLLEXPORT extern void error(const std::string& _err, const ::Base::CodeLink&
::Debug::error(strm.str, BASE_CODELINK); }
#define DEB_error_if(CC, AA) { if (CC) DEB_error(AA); }
// Stream does not fulfill ostream. If you want to exploit an existing
// Debug::Stream does not fulfill ostream. If you want to exploit an existing
// ostream streamer to DEB_out a class as text without exploiting any
// numeric processing or custom Stream streamers then use this macro thus
// DEB_out(1, "my_class is " << DEB_os_str(my_c) )
#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#define DEB_os_str(AA) \
dynamic_cast<std::ostringstream &&>((std::ostringstream() << AA )).str()
#else
namespace Debug
{
template <typename T>
std::string toString(const T& t)
{
std::ostringstream ss;
ss << t;
return ss.str();
}
}// namespace Debug
#define DEB_os_str(AA) \
Debug::toString(AA)
#endif
#define DEB_os_str(AA) Debug::to_string(AA)
#endif // DEB_ON
......
......@@ -35,10 +35,12 @@ IOutputStream& operator<<(IOutputStream& _os, const size_t _i)
return _os.print(_i);
}
#ifdef UINT_SIZET_DIFFER
IOutputStream& operator<<(IOutputStream& _os, const unsigned int _i)
{
return _os.print(size_t(_i));
}
#endif//UINT_SIZET_DIFFER
IOutputStream& operator<<(IOutputStream& _os, const float _f)
{
......
......@@ -5,14 +5,20 @@
#include <string>
#include <vector>
#include <stdint.h>
#if (_MSC_VER >= 1700 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#define STD_ARRAY_AVAILABLE
#include <array>
#include <limits.h>
// Find out if we need separate streaming operators for uint and size_t
#if ((UINT_MAX) != (SIZE_MAX))
#define UINT_SIZET_DIFFER
#endif
#include <Base/Config/BaseDefines.hh>
#ifdef STD_ARRAY_AVAILABLE
#include <array>
#endif//STD_ARRAY_AVAILABLE
namespace boost {
namespace filesystem {
class path;
......@@ -77,7 +83,9 @@ BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const char _c);
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const size_t _i);
#ifdef UINT_SIZET_DIFFER
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const unsigned int _i);
#endif//UINT_SIZET_DIFFER
BASEDLLEXPORT IOutputStream& operator<<(IOutputStream& _os, const float _f);
......@@ -183,16 +191,18 @@ private:
Old Style secure print function, should be used directly only in exceptional
cases. Note: Defined in OStringStream.cc.
*/
extern int print(char* _bffr, const size_t _bffr_size, const char* _frmt, ...);
extern int print(char* _bffr, const size_t _bffr_size, const char* const _frmt,
...);
//! Format a variable for streaming
template <typename T, const size_t _bffr_size = 128>
template <const size_t _bffr_size = 128>
struct FormatT
{
public:
typedef FormatT<T, _bffr_size> Self;
typedef FormatT<_bffr_size> Self;
FormatT(const char* _frmt, const T& _vrbl)
template <typename T>
FormatT(const char* const _frmt, const T& _vrbl)
{
print(bffr_, _bffr_size, _frmt, _vrbl);
}
......@@ -208,21 +218,21 @@ private:
//! Convenient access to format a variable for streaming
template <typename T>
inline FormatT<T> format(const char* _frmt, const T& _vrbl)
inline FormatT<> format(const char* const _frmt, const T& _vrbl)
{
return FormatT<T>(_frmt, _vrbl);
return FormatT<>(_frmt, _vrbl);
}
//! Format a 64bit size_t variable for streaming in hex (e.g. for hash)
inline FormatT<size_t> format_hex(const size_t _vrbl)
{
return FormatT<size_t>("%I64x", _vrbl);
//! Format a 32bit uint variable for streaming in hex (e.g. for hash)
inline FormatT<> format_hex(const uint32_t _vrbl)
{
return FormatT<>("%x", _vrbl);
}
//! Format a 32bit uint variable for streaming in hex (e.g. for hash)
inline FormatT<uint> format_hex(const uint _vrbl)
//! Format a 64bit size_t variable for streaming in hex (e.g. for hash)
inline FormatT<> format_hex(const uint64_t _vrbl)
{
return FormatT<uint>("%x", _vrbl);
return FormatT<>("%I64x", _vrbl);
}
}//namespace Base
......
Markdown is supported
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