- Revision
- 132169
- Author
- ander...@apple.com
- Date
- 2012-10-22 17:58:14 -0700 (Mon, 22 Oct 2012)
Log Message
Handle ArgumentCoder template specializations that take the ArgumentEncoder as a reference
https://bugs.webkit.org/show_bug.cgi?id=100056
Reviewed by Andreas Kling.
Use template magic to make it possible to have ArgumentCoder specializations where the encode
function takes the ArgumentEncoder object as a reference instead of as a pointer. Also, add an
operator<< to ArgumentEncoder and change the string related ArgumentCoder specializations over to taking
the encoder as a reference and using stream operators.
* Platform/CoreIPC/ArgumentCoders.cpp:
(CoreIPC::::encode):
* Platform/CoreIPC/ArgumentCoders.h:
* Platform/CoreIPC/ArgumentEncoder.h:
(ArgumentEncoder):
(UsesDeprecatedEncodeFunction):
(NoType):
(CoreIPC::ArgumentEncoder::encode):
(CoreIPC::ArgumentEncoder::operator<<):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (132168 => 132169)
--- trunk/Source/WebKit2/ChangeLog 2012-10-23 00:55:19 UTC (rev 132168)
+++ trunk/Source/WebKit2/ChangeLog 2012-10-23 00:58:14 UTC (rev 132169)
@@ -1,5 +1,27 @@
2012-10-22 Anders Carlsson <ander...@apple.com>
+ Handle ArgumentCoder template specializations that take the ArgumentEncoder as a reference
+ https://bugs.webkit.org/show_bug.cgi?id=100056
+
+ Reviewed by Andreas Kling.
+
+ Use template magic to make it possible to have ArgumentCoder specializations where the encode
+ function takes the ArgumentEncoder object as a reference instead of as a pointer. Also, add an
+ operator<< to ArgumentEncoder and change the string related ArgumentCoder specializations over to taking
+ the encoder as a reference and using stream operators.
+
+ * Platform/CoreIPC/ArgumentCoders.cpp:
+ (CoreIPC::::encode):
+ * Platform/CoreIPC/ArgumentCoders.h:
+ * Platform/CoreIPC/ArgumentEncoder.h:
+ (ArgumentEncoder):
+ (UsesDeprecatedEncodeFunction):
+ (NoType):
+ (CoreIPC::ArgumentEncoder::encode):
+ (CoreIPC::ArgumentEncoder::operator<<):
+
+2012-10-22 Anders Carlsson <ander...@apple.com>
+
More Argument coder cleanup
https://bugs.webkit.org/show_bug.cgi?id=100022
Modified: trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.cpp (132168 => 132169)
--- trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.cpp 2012-10-23 00:55:19 UTC (rev 132168)
+++ trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.cpp 2012-10-23 00:58:14 UTC (rev 132169)
@@ -26,14 +26,15 @@
#include "config.h"
#include "ArgumentCoders.h"
+#include "DataReference.h"
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
namespace CoreIPC {
-void ArgumentCoder<AtomicString>::encode(ArgumentEncoder* encoder, const AtomicString& atomicString)
+void ArgumentCoder<AtomicString>::encode(ArgumentEncoder& encoder, const AtomicString& atomicString)
{
- encoder->encode(atomicString.string());
+ encoder << atomicString.string();
}
bool ArgumentCoder<AtomicString>::decode(ArgumentDecoder* decoder, AtomicString& atomicString)
@@ -46,17 +47,16 @@
return true;
}
-void ArgumentCoder<CString>::encode(ArgumentEncoder* encoder, const CString& string)
+void ArgumentCoder<CString>::encode(ArgumentEncoder& encoder, const CString& string)
{
// Special case the null string.
if (string.isNull()) {
- encoder->encode(std::numeric_limits<uint32_t>::max());
+ encoder << std::numeric_limits<uint32_t>::max();
return;
}
uint32_t length = string.length();
- encoder->encode(length);
- encoder->encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length, 1);
+ encoder << length << CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(string.data()), length);
}
bool ArgumentCoder<CString>::decode(ArgumentDecoder* decoder, CString& result)
@@ -87,22 +87,23 @@
}
-void ArgumentCoder<String>::encode(ArgumentEncoder* encoder, const String& string)
+void ArgumentCoder<String>::encode(ArgumentEncoder& encoder, const String& string)
{
// Special case the null string.
if (string.isNull()) {
- encoder->encode(std::numeric_limits<uint32_t>::max());
+ encoder << std::numeric_limits<uint32_t>::max();
return;
}
uint32_t length = string.length();
- encoder->encode(length);
bool is8Bit = string.is8Bit();
- encoder->encode(is8Bit);
+
+ encoder << length << is8Bit;
+
if (is8Bit)
- encoder->encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar), __alignof(LChar));
+ encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar), __alignof(LChar));
else
- encoder->encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), __alignof(UChar));
+ encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), __alignof(UChar));
}
template <typename CharacterType>
Modified: trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.h (132168 => 132169)
--- trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.h 2012-10-23 00:55:19 UTC (rev 132168)
+++ trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.h 2012-10-23 00:58:14 UTC (rev 132169)
@@ -197,17 +197,17 @@
};
template<> struct ArgumentCoder<AtomicString> {
- static void encode(ArgumentEncoder*, const AtomicString&);
+ static void encode(ArgumentEncoder&, const AtomicString&);
static bool decode(ArgumentDecoder*, AtomicString&);
};
template<> struct ArgumentCoder<CString> {
- static void encode(ArgumentEncoder*, const CString&);
+ static void encode(ArgumentEncoder&, const CString&);
static bool decode(ArgumentDecoder*, CString&);
};
template<> struct ArgumentCoder<String> {
- static void encode(ArgumentEncoder*, const String&);
+ static void encode(ArgumentEncoder&, const String&);
static bool decode(ArgumentDecoder*, String&);
};
Modified: trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h (132168 => 132169)
--- trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h 2012-10-23 00:55:19 UTC (rev 132168)
+++ trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h 2012-10-23 00:58:14 UTC (rev 132169)
@@ -60,13 +60,44 @@
encode(static_cast<uint64_t>(t));
}
+
+ template<bool B, typename T = void>
+ struct EnableIf { };
+
+ template<typename T>
+ struct EnableIf<true, T> { typedef T Type; };
- // Generic type encode function.
- template<typename T> void encode(const T& t)
+ template<typename T> class UsesDeprecatedEncodeFunction {
+ typedef char YesType;
+ struct NoType {
+ char padding[8];
+ };
+
+ static YesType checkEncode(void (*)(ArgumentEncoder*, const T&));
+ static NoType checkEncode(...);
+
+ public:
+ static const bool value = sizeof(checkEncode(ArgumentCoder<T>::encode)) == sizeof(YesType);
+ };
+
+ // FIXME: This is the function that gets chosen if the argument coder takes the ArgumentEncoder as a pointer.
+ // This is the deprecated form - get rid of it.
+ template<typename T> void encode(const T& t, typename EnableIf<UsesDeprecatedEncodeFunction<T>::value>::Type* = 0)
{
ArgumentCoder<T>::encode(this, t);
}
+ template<typename T> void encode(const T& t, typename EnableIf<!UsesDeprecatedEncodeFunction<T>::value>::Type* = 0)
+ {
+ ArgumentCoder<T>::encode(*this, t);
+ }
+
+ template<typename T> ArgumentEncoder& operator<<(const T& t)
+ {
+ encode(t);
+ return *this;
+ }
+
uint8_t* buffer() const { return m_buffer; }
size_t bufferSize() const { return m_bufferSize; }