Previous 199869 Revisions Next

r41826 Sunday 22nd November, 2015 at 17:07:36 UTC by Miodrag Milanović
Made fast delegates work on VS x64 builds (nw)
[src/lib/util]delegate.h

trunk/src/lib/util/delegate.h
r250337r250338
9090// types of delegates supported
9191#define DELEGATE_TYPE_COMPATIBLE 0
9292#define DELEGATE_TYPE_INTERNAL 1
93#define DELEGATE_TYPE_MSVC 2
9394
9495// select which one we will be using
9596#if defined(__GNUC__)
r250337r250338
110111      #define MEMBER_ABI
111112      #define HAS_DIFFERENT_ABI 0
112113   #endif
114#elif defined(_MSC_VER) && defined (PTR64)
115#define MEMBER_ABI
116#define HAS_DIFFERENT_ABI 0
117#define USE_DELEGATE_TYPE DELEGATE_TYPE_MSVC
113118#else
114119#define USE_DELEGATE_TYPE DELEGATE_TYPE_COMPATIBLE
115120#endif
r250337r250338
541546   int                     m_this_delta;       // delta to apply to the 'this' pointer
542547};
543548
549#elif (USE_DELEGATE_TYPE == DELEGATE_TYPE_MSVC)
550
551// ======================> delegate_mfp
552const int SINGLE_MEMFUNCPTR_SIZE = sizeof(void (delegate_generic_class::*)());
553
554// struct describing the contents of a member function pointer
555class delegate_mfp
556{
557public:
558   // default constructor
559   delegate_mfp()
560      : m_function(0) { }
561
562   // copy constructor
563   delegate_mfp(const delegate_mfp &src)
564      : m_function(src.m_function) { }
565
566   // construct from any member function pointer
567   template<typename _MemberFunctionType, class _MemberFunctionClass, typename _ReturnType, typename _StaticFunctionType>
568   delegate_mfp(_MemberFunctionType mfp, _MemberFunctionClass *, _ReturnType *, _StaticFunctionType)
569   {
570      //assert(sizeof(mfp) == 12 || sizeof(mfp) == 16);
571      m_size = sizeof(mfp);
572      *reinterpret_cast<_MemberFunctionType *>(this) = mfp;
573   }
574
575   // comparison helpers
576   bool operator==(const delegate_mfp &rhs) const { return (m_function == rhs.m_function); }
577   bool isnull() const { return (m_function == 0); }
578
579   // getters
580   delegate_generic_class *real_object(delegate_generic_class *original) const { return original; }
581
582   // binding helper
583   template<typename _FunctionType>
584   void update_after_bind(_FunctionType &funcptr, delegate_generic_class *&object)
585   {
586      funcptr = reinterpret_cast<_FunctionType>(m_function);
587      if (m_size == SINGLE_MEMFUNCPTR_SIZE + sizeof(int))
588         object = reinterpret_cast<delegate_generic_class *>(reinterpret_cast<UINT8 *>(object) + m_this_delta);
589   }
590
591private:
592   // extract the generic function and adjust the object pointer
593   delegate_generic_function convert_to_generic(delegate_generic_class *&object) const;
594
595   // actual state
596   FPTR                    m_function;         // first item can be one of two things:
597                                    //    if even, it's a pointer to the function
598                                    //    if odd, it's the byte offset into the vtable
599   int                     m_this_delta;       // delta to apply to the 'this' pointer
600
601   int                  m_dummy1;
602   int                  m_dummy2;
603
604   int                  m_size;   
605};
606
544607#endif
545608
546609


Previous 199869 Revisions Next


© 1997-2024 The MAME Team