{"id":18004558,"url":"https://github.com/erikzenker/clangactiveobjectgenerator","last_synced_at":"2025-03-26T10:31:29.067Z","repository":{"id":151276413,"uuid":"148935823","full_name":"erikzenker/ClangActiveObjectGenerator","owner":"erikzenker","description":"Clang active object generator is a clang plugin for C++ code which generates an active object from a pure virtual class. An active object is a design pattern which decouples method execution from method invocation for objects that each reside  in their own thread of control.","archived":false,"fork":false,"pushed_at":"2018-09-16T13:44:09.000Z","size":35,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T15:10:56.895Z","etag":null,"topics":["activeobject","clang-plugin","cpp","cpp14"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erikzenker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-09-15T20:03:29.000Z","updated_at":"2023-03-18T06:23:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"1f0b7e3e-747f-4c08-97a1-2821f704ddf2","html_url":"https://github.com/erikzenker/ClangActiveObjectGenerator","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/erikzenker%2FClangActiveObjectGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikzenker%2FClangActiveObjectGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikzenker%2FClangActiveObjectGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikzenker%2FClangActiveObjectGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erikzenker","download_url":"https://codeload.github.com/erikzenker/ClangActiveObjectGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245636422,"owners_count":20647962,"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":["activeobject","clang-plugin","cpp","cpp14"],"created_at":"2024-10-30T00:14:49.491Z","updated_at":"2025-03-26T10:31:29.061Z","avatar_url":"https://github.com/erikzenker.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Clang Active Object Generator\n=============================\n\n**Clang active object generator** is a clang plugin for C++ code which generates an active object\nfrom a pure virtual class. An [active object](https://en.wikipedia.org/wiki/Active_object) is a design\npattern which decouples method execution from method invocation for objects that each reside \nin their own thread of control.\n\n![active object](doc/activeObject.svg)\n\nUsage\n=====\n1. Install the clang active object generator (see [Build Plugin](#build-plugin))\n1. You need a header file with a pure virtual class inside e.g.: IPureVirtualClass.hpp.\n    ```c++\n    #pragma once\n    \n    class IPureVirtualClass {\n    public:\n        virtual ~IPureVirtualClass() = default;\n        virtual void foo(int a) = 0;\n    };\n    ```\n   \n2. Call the generator script with the header file name and the interface name. The script will\nprint a generated interface implementation using the active object pattern to standard out.\n    ```bash\n    \n    clang-active-object-generator.sh IPureVirtualClass.hpp IPureVirtualClass \\\n        \u003e IPureVirtualClassActiveObject.hpp\n    \n    ```\n3. The generator script will create an active object header file for you e.g.:\n    ```c++\n    #pragma once\n    /*\n     * This file was generated by the ClangActiveObjectGenerator\n     */\n    \n    #include \"IPureVirtualClass.hpp\"\n    #include \u003cboost/asio/io_service.hpp\u003e\n    #include \u003cmemory\u003e\n    \n    class IPureVirtualClassActiveObject : public IPureVirtualClass {\n    public:\n      IPureVirtualClassActiveObject(const std::shared_ptr\u003cIPureVirtualClass\u003e\u0026 impl, boost::asio::io_service\u0026 ioService)\n          : m_impl(impl)\n          , m_ioService(ioService)\n      {\n      }\n    \n    public: // IPureVirtualClass\n        void foo(int a) override {\n            m_ioService.post(\n                [this, a](){\n                    m_impl.lock()-\u003efoo(a);\n                });\n        }\n    \n    \n    private:\n       std::weak_ptr\u003cIPureVirtualClass\u003e m_impl;\n       boost::asio::io_service\u0026 m_ioService;\n    };\n    \n    #ifndef MAKE_ACTIVE_OBJECT\n    #define MAKE_ACTIVE_OBJECT\n    template \u003cclass TInterface, class TExecutor\u003e\n    class MakeActiveObject {};\n    \n    template \u003cclass TInterface, class TExecutor\u003e\n    std::unique_ptr\u003cTInterface\u003e\n    make_active_object(const std::shared_ptr\u003cTInterface\u003e\u0026 impl, const std::shared_ptr\u003cTExecutor\u003e\u0026 executor)\n    {\n        return MakeActiveObject\u003cTInterface, TExecutor\u003e{}(impl, executor);\n    }\n    #endif\n    \n    template \u003cclass TExecutor\u003e\n    class MakeActiveObject\u003cICalculator, TExecutor\u003e {\n    public:\n        std::unique_ptr\u003cIPureVirtualClass\u003e operator()(const std::shared_ptr\u003cIPureVirtualClass\u003e\u0026 impl, const std::shared_ptr\u003cTExecutor\u003e\u0026 executor){\n                return std::make_unique\u003cIPureVirtualClassActiveObject\u003cTExecutor\u003e\u003e(impl, executor);\n        }\n    };\n    ```\n4. Finally, include the generated active object header into your sources and call methods on the active object\n    ```c++\n    #include \"IPureVirtualClass.hpp\"             // \u003c-- original interface header\n    #include \"IPureVirtualClassActiveObject.hpp\" // \u003c-- generated active object header\n    \n    #include \u003cboost/asio.hpp\u003e\n    #include \u003cthread\u003e\n    #include \u003ciostream\u003e\n    \n    class Impl : public IPureVirtualClass {\n        void foo(int a){\n            std::cout \u003c\u003c a \u003c\u003c std::endl;\n        }\n    }\n    \n    int main()\n    {\n        // Thread loop in which the active object method calls will be executed\n        auto ioService = std::make_shared\u003cboost::asio::io_service\u003e();\n     \n        // The implementation of the interface\n        auto impl = std::make_shared\u003cImpl\u003e();\n        \n        // Generates the active object \n        auto implActiveObject = make_active_object\u003cIPureVirtualClass\u003e(impl, ioService);\n        \n        // Puts the method call into the thread loop\n        implActiveObject-\u003efoo(42);\n    \n        // Executes the method call (prints 42)\n        std::thread t0([ioService]() { ioService-\u003erun(); });\n        t0.join();\n    \n        return 0;\n    }\n    ```\nBuild Plugin\n=============\n```bash\nmkdir build; cd build\ncmake ..\ncmake --build . --target install\n```\n\nBuild Example\n=============\nBuild the plugin in advance\n```bash\nmkdir build; cd build\ncmake ..\ncmake --build . --target clang_active_object_generator_example\n./example/clang_active_object_generator_example\n```\n\nDependencies\n============\n* C++14\n* llvm 6.0.1-4\n* clang 6.0.1-2\n\nLicense\n=======\nMIT\n\nAuthor\n======\nWritten by Erik Zenker (erikzenker (at) hotmail.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikzenker%2Fclangactiveobjectgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferikzenker%2Fclangactiveobjectgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikzenker%2Fclangactiveobjectgenerator/lists"}