Changeset 61635 in webkit


Ignore:
Timestamp:
Jun 22, 2010 4:35:44 PM (14 years ago)
Author:
andersca@apple.com
Message:

2010-06-22 Anders Carlsson <andersca@apple.com>

Reviewed by Sam Weinig.

Use the ArgumentCoder class template for decoding
https://bugs.webkit.org/show_bug.cgi?id=41021

  • Platform/CoreIPC/ArgumentCoder.h: (CoreIPC::ArgumentCoder::decode):
  • Platform/CoreIPC/ArgumentDecoder.h: (CoreIPC::ArgumentDecoder::decode):
  • Shared/WebCoreTypeArgumentMarshalling.h: (CoreIPC::):
Location:
trunk/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r61634 r61635  
     12010-06-22  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Use the ArgumentCoder class template for decoding
     6        https://bugs.webkit.org/show_bug.cgi?id=41021
     7
     8        * Platform/CoreIPC/ArgumentCoder.h:
     9        (CoreIPC::ArgumentCoder::decode):
     10        * Platform/CoreIPC/ArgumentDecoder.h:
     11        (CoreIPC::ArgumentDecoder::decode):
     12        * Shared/WebCoreTypeArgumentMarshalling.h:
     13        (CoreIPC::):
     14
    1152010-06-22  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/WebKit2/Platform/CoreIPC/ArgumentCoder.h

    r61634 r61635  
    3939        t.encode(*encoder);
    4040    }
     41
     42    static bool decode(ArgumentDecoder* decoder, T& t)
     43    {
     44        return T::decode(*decoder, t);
     45    }
    4146};
    4247
  • trunk/WebKit2/Platform/CoreIPC/ArgumentDecoder.h

    r57454 r61635  
    2727#define ArgumentDecoder_h
    2828
     29#include "ArgumentCoder.h"
    2930#include "Attachment.h"
    3031#include <wtf/Deque.h>
    31 #include <wtf/TypeTraits.h>
    3232#include <wtf/Vector.h>
    3333
    3434namespace CoreIPC {
    35 
    36 class ArgumentDecoder;
    37 class Attachment;
    38 
    39 namespace ArgumentCoders {
    40 
    41 template<typename T> bool decode(ArgumentDecoder& decoder, T& t)
    42 {
    43     return WTF::RemovePointer<T>::Type::decode(decoder, t);
    44 }
    45 
    46 }
    4735
    4836class ArgumentDecoder {
     
    6856    template<typename T> bool decode(T& t)
    6957    {
    70         return ArgumentCoders::decode<T>(*this, t);
     58        return ArgumentCoder<T>::decode(this, t);
    7159    }
    7260
  • trunk/WebKit2/Shared/WebCoreTypeArgumentMarshalling.h

    r61634 r61635  
    4141        encoder->encode(CoreIPC::In(p.x(), p.y()));
    4242    };
     43
     44    static bool decode(ArgumentDecoder* decoder, WebCore::IntPoint& p)
     45    {
     46        int x;
     47        int y;
     48        if (!decoder->decode(CoreIPC::Out(x, y)))
     49            return false;
     50       
     51        p.setX(x);
     52        p.setY(y);
     53        return true;
     54    }
    4355};
    4456
     
    4860        encoder->encode(CoreIPC::In(s.width(), s.height()));
    4961    };
     62   
     63    static bool decode(ArgumentDecoder* decoder, WebCore::IntSize& s)
     64    {
     65        int width;
     66        int height;
     67        if (!decoder->decode(CoreIPC::Out(width, height)))
     68            return false;
     69       
     70        s.setWidth(width);
     71        s.setHeight(height);
     72        return true;
     73    }
     74
    5075};
    5176
     
    5580        encoder->encode(CoreIPC::In(r.location(), r.size()));
    5681    };
     82   
     83    static bool decode(ArgumentDecoder* decoder, WebCore::IntRect& r)
     84    {
     85        WebCore::IntPoint location;
     86        WebCore::IntSize size;
     87        if (!decoder->decode(CoreIPC::Out(location, size)))
     88            return false;
     89       
     90        r.setLocation(location);
     91        r.setSize(size);
     92        return true;
     93    }
    5794};
    5895
     
    64101        encoder->encodeBytes(reinterpret_cast<const uint8_t*>(string.characters()), length * sizeof(UChar));
    65102    }
     103   
     104    static bool decode(ArgumentDecoder* decoder, WebCore::String& s)
     105    {
     106        uint32_t length;
     107        if (!decoder->decode(length))
     108            return false;
     109       
     110        UChar* buffer;
     111        WebCore::String string = WebCore::String::createUninitialized(length, buffer);
     112        if (!decoder->decodeBytes(reinterpret_cast<uint8_t*>(buffer), length * sizeof(UChar)))
     113            return false;
     114       
     115        s = string;
     116        return true;
     117    }
    66118};
    67119
    68 namespace ArgumentCoders {
    69 
    70 // FIXME: IntPoint/IntSize/IntRect/FloatPoint/FloatSize/FloatRect should all
    71 // be able to be treated as POD-like types and thus memcpy-able. 
    72 
    73 // WebCore::IntPoint
    74 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::IntPoint& p)
    75 {
    76     int x;
    77     int y;
    78     if (!decoder.decode(CoreIPC::Out(x, y)))
    79         return false;
    80    
    81     p.setX(x);
    82     p.setY(y);
    83     return true;
    84 }
    85 
    86 // WebCore::IntSize
    87 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::IntSize& s)
    88 {
    89     int width;
    90     int height;
    91     if (!decoder.decode(CoreIPC::Out(width, height)))
    92         return false;
    93    
    94     s.setWidth(width);
    95     s.setHeight(height);
    96     return true;
    97 }
    98 
    99 // WebCore::IntRect
    100 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::IntRect& r)
    101 {
    102     WebCore::IntPoint location;
    103     WebCore::IntSize size;
    104     if (!decoder.decode(CoreIPC::Out(location, size)))
    105         return false;
    106    
    107     r.setLocation(location);
    108     r.setSize(size);
    109     return true;
    110 }
    111 
    112 // WebCore::FloatPoint
    113 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::FloatPoint& p)
    114 {
    115     float x;
    116     float y;
    117     if (!decoder.decode(CoreIPC::Out(x, y)))
    118         return false;
    119    
    120     p.setX(x);
    121     p.setY(y);
    122     return true;
    123 }
    124 
    125 // WebCore::FloatSize
    126 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::FloatSize& s)
    127 {
    128     float width;
    129     float height;
    130     if (!decoder.decode(CoreIPC::Out(width, height)))
    131         return false;
    132    
    133     s.setWidth(width);
    134     s.setHeight(height);
    135     return true;
    136 }
    137 
    138 // WebCore::FloatRect
    139 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::FloatRect& r)
    140 {
    141     WebCore::FloatPoint location;
    142     WebCore::FloatSize size;
    143     if (!decoder.decode(CoreIPC::Out(location, size)))
    144         return false;
    145    
    146     r.setLocation(location);
    147     r.setSize(size);
    148     return true;
    149 }
    150 
    151 // WebCore::String
    152 template<> inline bool decode(ArgumentDecoder& decoder, WebCore::String& s)
    153 {
    154     uint32_t length;
    155     if (!decoder.decode(length))
    156         return false;
    157 
    158     UChar* buffer;
    159     WebCore::String string = WebCore::String::createUninitialized(length, buffer);
    160     if (!decoder.decodeBytes(reinterpret_cast<uint8_t*>(buffer), length * sizeof(UChar)))
    161         return false;
    162 
    163     s = string;
    164     return true;
    165 }
    166 
    167 } // namespace ArgumentCoders
    168120} // namespace CoreIPC
    169121
Note: See TracChangeset for help on using the changeset viewer.