⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typedecl.h

📁 java 反射机制详解示例,实现类属性及方法修改
💻 H
📖 第 1 页 / 共 2 页
字号:

#if defined(__GNUC__) && __GNUC_MINOR__ < 96
template<class __P>
inline RTTIType* RTTITypeOfPtrToPtr(__P const*const*const*) { 
    extern RTTIClassDescriptor* RTTIGetClassDescriptor(__P*);
    return new RTTIPtrType(new RTTIPtrType(RTTIGetClassDescriptor((__P*)0)));
}
#else
template<class __P>
inline RTTIType* RTTITypeOfPtrToPtr(__P const*const*const*) { 
    return new RTTIPtrType(new RTTIPtrType(&__P::RTTIDescriptor));
}
#endif
    
template<class __RT, class __C>
class RTTIFuncType0 : public RTTIMethodType { 
  public:
    typedef __RT (__C::*fptr)();
    fptr f;
    RTTIFuncType0(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = RTTITypeOfPtr((__RT*)0);
	nParams = 0;
	paramTypes = NULL;
    }
    void invoke(void* result, void* obj, void* params[]) { 
	*(__RT*)result = (((__C*)obj)->*f)();
    }
};

template<class __RT, class __C, class __P1>
class RTTIFuncType1 : public RTTIMethodType{ 
  public:
    typedef __RT (__C::*fptr)(__P1);
    fptr f;
    RTTIFuncType1(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = RTTITypeOfPtr((__RT*)0);
	nParams = 1;
	paramTypes = new RTTIType*[1];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
    }
    void invoke(void* result, void* obj, void* params[]) { 
	*(__RT*)result = (((__C*)obj)->*f)(*(__P1*)params[0]);
    }
};

template<class __RT, class __C, class __P1, class __P2>
class RTTIFuncType2 : public RTTIMethodType{ 
  public:
    typedef __RT (__C::*fptr)(__P1, __P2);
    fptr f;
    RTTIFuncType2(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = RTTITypeOfPtr((__RT*)0);
	nParams = 2;
	paramTypes = new RTTIType*[2];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
    }
    void invoke(void* result, void* obj, void* params[]) { 
	*(__RT*)result = (((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1]);
    }
};

template<class __RT, class __C, class __P1, class __P2, class __P3>
class RTTIFuncType3 : public RTTIMethodType{ 
  public:
    typedef __RT (__C::*fptr)(__P1, __P2, __P3);
    fptr f;
    RTTIFuncType3(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = RTTITypeOfPtr((__RT*)0);
	nParams = 3;
	paramTypes = new RTTIType*[3];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
	paramTypes[2] = RTTITypeOfPtr((__P3*)0);
    }
    void invoke(void* result, void* obj, void* params[]) { 
	*(__RT*)result = (((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1], *(__P3*)params[2]);
    }
};

template<class __RT, class __C, class __P1, class __P2, class __P3, class __P4>
class RTTIFuncType4 : public RTTIMethodType{ 
  public:
    typedef __RT (__C::*fptr)(__P1, __P2, __P3, __P4);
    fptr f;
    RTTIFuncType4(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = RTTITypeOfPtr((__RT*)0);
	nParams = 4;
	paramTypes = new RTTIType*[4];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
	paramTypes[2] = RTTITypeOfPtr((__P3*)0);
	paramTypes[3] = RTTITypeOfPtr((__P4*)0);
    }
    void invoke(void* result, void* obj, void* params[]) { 
	*(__RT*)result = (((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1], *(__P3*)params[2], *(__P4*)params[3]);
    }
};

template<class __RT, class __C, class __P1, class __P2, class __P3, class __P4, class __P5>
class RTTIFuncType5 : public RTTIMethodType{ 
  public:
    typedef __RT (__C::*fptr)(__P1, __P2, __P3, __P4, __P5);
    fptr f;
    RTTIFuncType5(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = RTTITypeOfPtr((__RT*)0);
	nParams = 5;
	paramTypes = new RTTIType*[5];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
	paramTypes[2] = RTTITypeOfPtr((__P3*)0);
	paramTypes[3] = RTTITypeOfPtr((__P4*)0);
	paramTypes[4] = RTTITypeOfPtr((__P5*)0);
    }
    void invoke(void* result, void* obj, void* params[]) { 
	*(__RT*)result = (((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1], *(__P3*)params[2], *(__P4*)params[3], *(__P5*)params[4]);
    }
};


template<class __C>
class RTTIProcType0 : public RTTIMethodType { 
  public:
    typedef void (__C::*fptr)();
    fptr f;
    RTTIProcType0(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = &voidType;
	nParams = 0;
	paramTypes = NULL;
    }
    void invoke(void*, void* obj, void* params[]) { 
	(((__C*)obj)->*f)();
    }
};

template<class __C, class __P1>
class RTTIProcType1 : public RTTIMethodType{ 
  public:
    typedef void (__C::*fptr)(__P1);
    fptr f;
    RTTIProcType1(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = &voidType;
	nParams = 1;
	paramTypes = new RTTIType*[1];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
    }
    void invoke(void*, void* obj, void* params[]) { 
	(((__C*)obj)->*f)(*(__P1*)params[0]);
    }
};

template<class __C, class __P1, class __P2>
class RTTIProcType2 : public RTTIMethodType{ 
  public:
    typedef void (__C::*fptr)(__P1, __P2);
    fptr f;
    RTTIProcType2(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = &voidType;
	nParams = 2;
	paramTypes = new RTTIType*[2];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
    }
    void invoke(void*, void* obj, void* params[]) { 
	(((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1]);
    }
};

template<class __C, class __P1, class __P2, class __P3>
class RTTIProcType3 : public RTTIMethodType{ 
  public:
    typedef void (__C::*fptr)(__P1, __P2, __P3);
    fptr f;
    RTTIProcType3(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = &voidType;
	nParams = 3;
	paramTypes = new RTTIType*[3];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
	paramTypes[2] = RTTITypeOfPtr((__P3*)0);
    }
    void invoke(void*, void* obj, void* params[]) { 
	(((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1], *(__P3*)params[2]);
    }
};

template<class __C, class __P1, class __P2, class __P3, class __P4>
class RTTIProcType4 : public RTTIMethodType{ 
  public:
    typedef void (__C::*fptr)(__P1, __P2, __P3, __P4);
    fptr f;
    RTTIProcType4(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = &voidType;
	nParams = 4;
	paramTypes = new RTTIType*[4];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
	paramTypes[2] = RTTITypeOfPtr((__P3*)0);
	paramTypes[3] = RTTITypeOfPtr((__P4*)0);
    }
    void invoke(void*, void* obj, void* params[]) { 
	(((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1], *(__P3*)params[2], *(__P4*)params[3]);
    }
};

template<class __C, class __P1, class __P2, class __P3, class __P4, class __P5>
class RTTIProcType5 : public RTTIMethodType { 
  public:
    typedef void (__C::*fptr)(__P1, __P2, __P3, __P4, __P5);
    fptr f;
    RTTIProcType5(fptr f) { 
	this->f = f;
	methodClass = &__C::RTTIDescriptor;
	returnType = &voidType;
	nParams = 5;
	paramTypes = new RTTIType*[5];
	paramTypes[0] = RTTITypeOfPtr((__P1*)0);
	paramTypes[1] = RTTITypeOfPtr((__P2*)0);
	paramTypes[2] = RTTITypeOfPtr((__P3*)0);
	paramTypes[3] = RTTITypeOfPtr((__P4*)0);
	paramTypes[4] = RTTITypeOfPtr((__P5*)0);
    }
    void invoke(void*, void* obj, void* params[]) { 
	(((__C*)obj)->*f)(*(__P1*)params[0], *(__P2*)params[1], *(__P3*)params[2], *(__P4*)params[3], *(__P5*)params[4]);
    }
};


template<class __RT, class __C>
inline RTTIMethodType* RTTIFuncTypeOf(__RT (__C::*f)()) { 
    return new RTTIFuncType0<__RT, __C>(f);
}

template<class __RT, class __C, class __P1>
inline RTTIMethodType* RTTIFuncTypeOf(__RT (__C::*f)(__P1)) { 
    return new RTTIFuncType1<__RT, __C, __P1>(f);
}

template<class __RT, class __C, class __P1, class __P2>
inline RTTIMethodType* RTTIFuncTypeOf(__RT (__C::*f)(__P1, __P2)) { 
    return new RTTIFuncType2<__RT, __C, __P1, __P2>(f);
}

template<class __RT, class __C, class __P1, class __P2, class __P3>
inline RTTIMethodType* RTTIFuncTypeOf(__RT (__C::*f)(__P1, __P2, __P3)) { 
    return new RTTIFuncType3<__RT, __C, __P1, __P2, __P3>(f);
}

template<class __RT, class __C, class __P1, class __P2, class __P3, class __P4>
inline RTTIMethodType* RTTIFuncTypeOf(__RT (__C::*f)(__P1, __P2, __P3, __P4)) { 
    return new RTTIFuncType4<__RT, __C, __P1, __P2, __P3, __P4>(f);
}

template<class __RT, class __C, class __P1, class __P2, class __P3, class __P4, class __P5>
inline RTTIMethodType* RTTIFuncTypeOf(__RT (__C::*f)(__P1, __P2, __P3, __P4, __P5)) { 
    return new RTTIFuncType5<__RT, __C, __P1, __P2, __P3, __P4, __P5>(f);
}


template<class __C>
inline RTTIMethodType* RTTIProcTypeOf(void (__C::*f)()) { 
    return new RTTIProcType0<__C>(f);
}

template<class __C, class __P1>
inline RTTIMethodType* RTTIProcTypeOf(void (__C::*f)(__P1)) { 
    return new RTTIProcType1<__C, __P1>(f);
}

template<class __C, class __P1, class __P2>
inline RTTIMethodType* RTTIProcTypeOf(void (__C::*f)(__P1, __P2)) { 
    return new RTTIProcType2<__C, __P1, __P2>(f);
}

template<class __C, class __P1, class __P2, class __P3>
inline RTTIMethodType* RTTIProcTypeOf(void (__C::*f)(__P1, __P2, __P3)) { 
    return new RTTIProcType3<__C, __P1, __P2, __P3>(f);
}

template<class __C, class __P1, class __P2, class __P3, class __P4>
inline RTTIMethodType* RTTIProcTypeOf(void (__C::*f)(__P1, __P2, __P3, __P4)) { 
    return new RTTIProcType4<__C, __P1, __P2, __P3, __P4>(f);
}

template<class __C, class __P1, class __P2, class __P3, class __P4, class __P5>
inline RTTIMethodType* RTTIProcTypeOf(void (__C::*f)(__P1, __P2, __P3, __P4, __P5)) { 
    return new RTTIProcType5<__C, __P1, __P2, __P3, __P4, __P5>(f);
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -