{"id":17800973,"url":"https://github.com/refi64/fnwrap","last_synced_at":"2025-04-02T04:40:52.365Z","repository":{"id":69429181,"uuid":"89408894","full_name":"refi64/fnwrap","owner":"refi64","description":"fnwrap makes it easy to create wrappers over C++11 functions","archived":false,"fork":false,"pushed_at":"2017-04-25T21:34:28.000Z","size":85,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T05:06:48.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/refi64.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-25T21:34:16.000Z","updated_at":"2017-04-26T08:11:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c6ffe93-dfca-4d1b-9315-f8021d858f02","html_url":"https://github.com/refi64/fnwrap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Ffnwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Ffnwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Ffnwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refi64%2Ffnwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/refi64","download_url":"https://codeload.github.com/refi64/fnwrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246758278,"owners_count":20828919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T12:32:54.116Z","updated_at":"2025-04-02T04:40:52.333Z","avatar_url":"https://github.com/refi64.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"fnwrap\n======\n\n*fnwrap* is a header-only, C++11 library that makes it easy to wrap functions.\nFor instance, this Python code:\n\n.. code-block:: python\n\n  def myfunc(a, b): # Whatever...\n\n  def wrapper(*args, **kw):\n      print('Before myfunc')\n      myfunc()\n      print('After myfunc')\n\nis equivalent to this code using *fnwrap*:\n\n.. code-block:: c++\n\n  #include \"fnwrap.hpp\"\n\n  void myfunc(int a, int b) { /* ... */ }\n\n  FNWRAP(myfunc, , wrapper, puts(\"Before myfunc\"), puts(\"After myfunc\"))\n\nDownloading\n***********\n\nJust clone and copy *fnwrap.hpp* into your project.\n\nUsage\n*****\n\nUsing *fnwrap* revolves around the ``FNWRAP`` macro. It's defined like so:\n\n.. code-block:: c++\n\n  #define FNWRAP(original_function, which_overload, new_wrapper_name,\n                 code_to_run_before, code_to_run_after)\n\n(Ignore the ``which_overload`` parameter for now.) The parameters\n``which_overload``, ``code_to_run_before``, and ``code_to_run_after`` can be\nempty.\n\nExample usage:\n\n.. code-block:: c++\n\n  // Creates a function myfunc_wrapper1 that *just* calls myfunc.\n  FNWRAP(myfunc, , myfunc_wrapper1, , )\n  // Creates a function myfunc_wrapper2 that prints a message, then calls myfunc.\n  FNWRAP(myfunc, , myfunc_wrapper2, puts(\"This is printed before!\"), )\n  // Creates a function myfunc_wrapper3 that calls myfunc, then prints a message.\n  FNWRAP(myfunc, , myfunc_wrapper3, , puts(\"This is printed after!\"))\n  // Creates a function myfunc_wrapper4 that prints a message, calls myfunc,\n  // and then prints another message.\n  FNWRAP(myfunc, , myfunc_wrapper4, puts(\"This is printed before!\"),\n         puts(\"This is printed after!\"))\n\nNote that the content of the ``code_to_run_before`` and ``code_to_run_after``\nparameters must be a basic expression; more complex code should instead be in\na separate function, e.g. ``void before() { puts(\"Before!\"); }`` and\n``FNWRAP(myfunc, , myfunc_wrapper, before(), )``.\n\nYou can access the content of the arguments passed to the function using the\nvariables ``a0`` through ``a9``:\n\n.. code-block:: c++\n\n  int myfunc(int x) { return x; }\n  FNWRAP(myfunc, , myfunc_wrapper, printf(\"myfunc(%d) was called\\n\", a0), )\n\nIf you want to wrap an overloaded function, you must specify which one using\nthe ``which_overload`` parameter:\n\n.. code-block:: c++\n\n  int overload() { puts(\"Overload #1\"); }\n  int overload(int x) { puts(\"Overload #2\"); }\n\n  FNWRAP(overload, int(), overload_wrapper1, puts(\"Before overload() #1\"), )\n  FNWRAP(overload, int(int), overload_wrapper2,\n         printf(\"Before overload(%d) #2\\n\", a0), )\n\nLicense\n*******\n\n*fnwrap* is licensed under the MIT Expat license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefi64%2Ffnwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefi64%2Ffnwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefi64%2Ffnwrap/lists"}