Commit b0e9ddb5 by Geoff Lang Committed by Commit Bot

Refactor a hex streaming into a generic FmtHex function.

The length of the printed value can be determined from size of the type. BUG=angleproject:2546 Change-Id: I39a4f9550f381dd82183f50019b3f7d117c52472 Reviewed-on: https://chromium-review.googlesource.com/1070220Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 58675016
......@@ -216,18 +216,15 @@ std::string LogMessage::getMessage() const
}
#if defined(ANGLE_PLATFORM_WINDOWS)
std::ostream &operator<<(std::ostream &os, const FmtHR &fmt)
priv::FmtHexHelper<HRESULT> FmtHR(HRESULT value)
{
os << "HRESULT: ";
return FmtHexInt(os, fmt.mHR);
return priv::FmtHexHelper<HRESULT>("HRESULT: ", value);
}
std::ostream &operator<<(std::ostream &os, const FmtErr &fmt)
priv::FmtHexHelper<DWORD> FmtErr(DWORD value)
{
os << "error: ";
return FmtHexInt(os, fmt.mErr);
return priv::FmtHexHelper<DWORD>("error: ", value);
}
#endif // defined(ANGLE_PLATFORM_WINDOWS)
} // namespace gl
......@@ -127,39 +127,52 @@ std::ostream &FmtHex(std::ostream &os, T value)
return os;
}
} // namespace priv
#if defined(ANGLE_PLATFORM_WINDOWS)
class FmtHR
template <typename T>
std::ostream &FmtHexAutoSized(std::ostream &os, T value)
{
public:
explicit FmtHR(HRESULT hresult) : mHR(hresult) {}
private:
HRESULT mHR;
friend std::ostream &operator<<(std::ostream &os, const FmtHR &fmt);
};
constexpr int N = sizeof(T) * 2;
return priv::FmtHex<N>(os, value);
}
class FmtErr
template <typename T>
class FmtHexHelper
{
public:
explicit FmtErr(DWORD err) : mErr(err) {}
FmtHexHelper(const char *prefix, T value) : mPrefix(prefix), mValue(value) {}
explicit FmtHexHelper(T value) : mPrefix(nullptr), mValue(value) {}
private:
DWORD mErr;
friend std::ostream &operator<<(std::ostream &os, const FmtErr &fmt);
const char *mPrefix;
T mValue;
friend std::ostream &operator<<(std::ostream &os, const FmtHexHelper &fmt)
{
if (fmt.mPrefix)
{
os << fmt.mPrefix;
}
return FmtHexAutoSized(os, fmt.mValue);
}
};
#endif // defined(ANGLE_PLATFORM_WINDOWS)
} // namespace priv
template <typename T>
std::ostream &FmtHexShort(std::ostream &os, T value)
priv::FmtHexHelper<T> FmtHex(T value)
{
return priv::FmtHex<4>(os, value);
return priv::FmtHexHelper<T>(value);
}
#if defined(ANGLE_PLATFORM_WINDOWS)
priv::FmtHexHelper<HRESULT> FmtHR(HRESULT value);
priv::FmtHexHelper<DWORD> FmtErr(DWORD value);
#endif // defined(ANGLE_PLATFORM_WINDOWS)
template <typename T>
std::ostream &FmtHexInt(std::ostream &os, T value)
std::ostream &FmtHex(std::ostream &os, T value)
{
return priv::FmtHex<8>(os, value);
return priv::FmtHexAutoSized(os, value);
}
// A few definitions of macros that don't generate much code. These are used
......
......@@ -70,7 +70,7 @@ bool Error::operator!=(const Error &other) const
std::ostream &operator<<(std::ostream &os, const Error &err)
{
return gl::FmtHexShort(os, err.getCode());
return gl::FmtHex(os, err.getCode());
}
} // namespace gl
......@@ -104,7 +104,7 @@ const std::string &Error::getMessage() const
std::ostream &operator<<(std::ostream &os, const Error &err)
{
return gl::FmtHexShort(os, err.getCode());
return gl::FmtHex(os, err.getCode());
}
} // namespace egl
......@@ -499,7 +499,7 @@ Format Format::Invalid()
std::ostream &operator<<(std::ostream &os, const Format &fmt)
{
// TODO(ynovikov): return string representation when available
return FmtHexShort(os, fmt.info->sizedInternalFormat);
return FmtHex(os, fmt.info->sizedInternalFormat);
}
bool InternalFormat::operator==(const InternalFormat &other) const
......
......@@ -105,8 +105,7 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
const LPSTR idcArrow = MAKEINTRESOURCEA(32512);
std::ostringstream stream;
stream << "ANGLE DisplayWGL " << std::internal << std::setw(10) << std::setfill('0') << mDisplay
<< " Intermediate Window Class";
stream << "ANGLE DisplayWGL " << gl::FmtHex(mDisplay) << " Intermediate Window Class";
std::string className = stream.str();
WNDCLASSA intermediateClassDesc = { 0 };
......
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