Skip to content

Templated version of sourcehook.h #134

@mixern6

Description

@mixern6

Hello, I'm using sourcehook in my extensions and would like to propose that it should be changed.
I see several drawbacks in the current implementation:

  • The code in sourcehook.h is hard to read.
  • Debugging the code generated by SH_DECL_* macros is difficult because they contain many nested macros with generated variable names.
  • The macros cannot be wrapped into classes and they always have to be defined at the top of the CPP file.
  • All the hooks have to be managed "manually" as there is no RAII to handle them.
  • There is a separate macro for different number of arguments.
  • The macros are not well handled by Visual Studio and Qt Creator.

One templated class could replace all the SH_DECL_* macros and solve these problems.

template<typename R, typename... A> // return type and argument types
class VirtualHookHandler
{
public:
    void Reconfigure(...);
    void Enable(...);
    void Disable(...);
    void AddListener(...); 
    void RemoveListener(...);
    void CallOriginal(...);
    ...
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions