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 ...@@ -216,18 +216,15 @@ std::string LogMessage::getMessage() const
} }
#if defined(ANGLE_PLATFORM_WINDOWS) #if defined(ANGLE_PLATFORM_WINDOWS)
std::ostream &operator<<(std::ostream &os, const FmtHR &fmt) priv::FmtHexHelper<HRESULT> FmtHR(HRESULT value)
{ {
os << "HRESULT: "; return priv::FmtHexHelper<HRESULT>("HRESULT: ", value);
return FmtHexInt(os, fmt.mHR);
} }
std::ostream &operator<<(std::ostream &os, const FmtErr &fmt) priv::FmtHexHelper<DWORD> FmtErr(DWORD value)
{ {
os << "error: "; return priv::FmtHexHelper<DWORD>("error: ", value);
return FmtHexInt(os, fmt.mErr);
} }
#endif // defined(ANGLE_PLATFORM_WINDOWS) #endif // defined(ANGLE_PLATFORM_WINDOWS)
} // namespace gl } // namespace gl
...@@ -127,39 +127,52 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -127,39 +127,52 @@ std::ostream &FmtHex(std::ostream &os, T value)
return os; return os;
} }
} // namespace priv
#if defined(ANGLE_PLATFORM_WINDOWS) template <typename T>
class FmtHR std::ostream &FmtHexAutoSized(std::ostream &os, T value)
{ {
public: constexpr int N = sizeof(T) * 2;
explicit FmtHR(HRESULT hresult) : mHR(hresult) {} return priv::FmtHex<N>(os, value);
private: }
HRESULT mHR;
friend std::ostream &operator<<(std::ostream &os, const FmtHR &fmt);
};
class FmtErr template <typename T>
class FmtHexHelper
{ {
public: 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: private:
DWORD mErr; const char *mPrefix;
friend std::ostream &operator<<(std::ostream &os, const FmtErr &fmt); 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> 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> 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 // 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 ...@@ -70,7 +70,7 @@ bool Error::operator!=(const Error &other) const
std::ostream &operator<<(std::ostream &os, const Error &err) std::ostream &operator<<(std::ostream &os, const Error &err)
{ {
return gl::FmtHexShort(os, err.getCode()); return gl::FmtHex(os, err.getCode());
} }
} // namespace gl } // namespace gl
...@@ -104,7 +104,7 @@ const std::string &Error::getMessage() const ...@@ -104,7 +104,7 @@ const std::string &Error::getMessage() const
std::ostream &operator<<(std::ostream &os, const Error &err) std::ostream &operator<<(std::ostream &os, const Error &err)
{ {
return gl::FmtHexShort(os, err.getCode()); return gl::FmtHex(os, err.getCode());
} }
} // namespace egl } // namespace egl
...@@ -499,7 +499,7 @@ Format Format::Invalid() ...@@ -499,7 +499,7 @@ Format Format::Invalid()
std::ostream &operator<<(std::ostream &os, const Format &fmt) std::ostream &operator<<(std::ostream &os, const Format &fmt)
{ {
// TODO(ynovikov): return string representation when available // 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 bool InternalFormat::operator==(const InternalFormat &other) const
......
...@@ -105,8 +105,7 @@ egl::Error DisplayWGL::initialize(egl::Display *display) ...@@ -105,8 +105,7 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
const LPSTR idcArrow = MAKEINTRESOURCEA(32512); const LPSTR idcArrow = MAKEINTRESOURCEA(32512);
std::ostringstream stream; std::ostringstream stream;
stream << "ANGLE DisplayWGL " << std::internal << std::setw(10) << std::setfill('0') << mDisplay stream << "ANGLE DisplayWGL " << gl::FmtHex(mDisplay) << " Intermediate Window Class";
<< " Intermediate Window Class";
std::string className = stream.str(); std::string className = stream.str();
WNDCLASSA intermediateClassDesc = { 0 }; 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