Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
FunctorWithAddress.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Functor.h (C) 2000-2005 */
9/* */
10/* Functor. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_FUNCTOR_WITH_ADDRESS_H
13#define ARCANE_UTILS_FUNCTOR_WITH_ADDRESS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/IFunctorWithAddress.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
32template <typename T>
35{
36 public:
37
38 typedef void (T::*FuncPtr)();
39
40 public:
41
44 FuncPtr funcptr)
45 : m_function(funcptr)
46 , m_object(object)
47 {}
48
49 virtual ~FunctorWithAddressT() {}
50
51 protected:
52
55 {
56 (m_object->*m_function)();
57 }
58
66 {
67 //GG: DO NOT DO THIS, because it is too platform dependent
68#if defined(__x86_64__) && defined(ARCANE_OS_LINUX)
69 long unsigned int* func = (long unsigned int*)&m_function;
70 //printf("\t\33[7m m_object @%p, m_function @%p=0x%lx 0x%lx (sizeof=%ld)\33[m\n\r", m_object, func, *func, *(func+1), sizeof(m_function));
71 // Par exemple pour la fonction d'un module utilisateur (depuis executeFunctor):
72 // rcx = 0x79
73 // rdx = this
74 // rax = *(m_object)
75 // rdi = m_function.__delta (=0)
76 // movl (%rax,%rdi,1),%rax => m_object->$vtable (@ offset 0)
77 // rax = m_object->$vtable
78 // rdi=m_function.__delta+m_object ( = 0+m_object)
79 // movl -1(%rcx,%rax,1),%rcx => rcx=0x004280c0!
80 long unsigned int pfn = *func;
81 long unsigned int of7 = (pfn - 1) >> 3;
82 //long unsigned int delta=*(func+1);
83 long unsigned int* module_vtable = (long unsigned int*)((long unsigned int*)&(*m_object))[0];
84 //printf("\t\33[7mpfn=0x%lx, delta=0x%lx module_vtable @ %p\33[m\n\r", pfn,delta,module_vtable);
85 //for(int i=0;i<20;++i) printf("\t\t\33[7vtable[%ld]=0x%lx\33[m\n\r",i,module_vtable[i]);
86 // If the least significant bit is 1, there is af
87 if ((pfn & 1) == 1) {
88 //printf("\t\t\33[7mfunctorAddress @ 0x%lx\33[m\n\r",module_vtable[of7]);
89 return (void*)module_vtable[of7];
90 }
91 return (void*)pfn;
92#else
93 return 0;
94#endif
95 }
96
97 public:
98
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106} // namespace Arcane
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111#endif
FunctorWithAddress associated with a method of a class T.
FuncPtr m_function
Pointer to the associated method.
FunctorWithAddressT(T *object, FuncPtr funcptr)
Constructor.
void executeFunctor()
Executes the associated method.
T * m_object
Associated object.
void(T::* FuncPtr)()
Type of the method pointer.
void * functorAddress()
Returns the address of the associated method.
Interface of a functor.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --