~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/JavaScriptCore/wtf/StdLibExtras.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
24
 */
25
25
 
 
26
#ifndef WTF_StdLibExtras_h
 
27
#define WTF_StdLibExtras_h
 
28
 
26
29
#include <wtf/Platform.h>
 
30
#include <wtf/Assertions.h>
27
31
 
28
32
// Use these to declare and define a static local variable (static T;) so that
29
33
//  it is leaked so that its destructors are not called at exit. Using this
36
40
#define DEFINE_STATIC_LOCAL(type, name, arguments) \
37
41
    static type& name = *new type arguments
38
42
#endif
 
43
 
 
44
// OBJECT_OFFSETOF: Like the C++ offsetof macro, but you can use it with classes.
 
45
// The magic number 0x4000 is insignificant. We use it to avoid using NULL, since
 
46
// NULL can cause compiler problems, especially in cases of multiple inheritance.
 
47
#define OBJECT_OFFSETOF(class, field) (reinterpret_cast<ptrdiff_t>(&(reinterpret_cast<class*>(0x4000)->field)) - 0x4000)
 
48
 
 
49
namespace WTF {
 
50
 
 
51
    /*
 
52
     * C++'s idea of a reinterpret_cast lacks sufficient cojones.
 
53
     */
 
54
    template<typename TO, typename FROM>
 
55
    TO bitwise_cast(FROM from)
 
56
    {
 
57
        COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal);
 
58
        union {
 
59
            FROM from;
 
60
            TO to;
 
61
        } u;
 
62
        u.from = from;
 
63
        return u.to;
 
64
    }
 
65
 
 
66
} // namespace WTF
 
67
 
 
68
#endif