{"id":15047911,"url":"https://github.com/hiitiger/coolercppidiom","last_synced_at":"2025-04-10T01:08:30.499Z","repository":{"id":37499595,"uuid":"103106455","full_name":"hiitiger/CoolerCppIdiom","owner":"hiitiger","description":"cooler c++  patterns like async, event delegate, json auto serialization","archived":false,"fork":false,"pushed_at":"2019-07-12T19:00:16.000Z","size":175,"stargazers_count":53,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T01:08:24.918Z","etag":null,"topics":["cplusplus-11","cpp","design-patterns","toolkits"],"latest_commit_sha":null,"homepage":"","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/hiitiger.png","metadata":{"files":{"readme":"readme.md","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}},"created_at":"2017-09-11T07:54:22.000Z","updated_at":"2024-11-21T09:13:24.000Z","dependencies_parsed_at":"2022-09-15T08:20:57.873Z","dependency_job_id":null,"html_url":"https://github.com/hiitiger/CoolerCppIdiom","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/hiitiger%2FCoolerCppIdiom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiitiger%2FCoolerCppIdiom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiitiger%2FCoolerCppIdiom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiitiger%2FCoolerCppIdiom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiitiger","download_url":"https://codeload.github.com/hiitiger/CoolerCppIdiom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137887,"owners_count":21053775,"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":["cplusplus-11","cpp","design-patterns","toolkits"],"created_at":"2024-09-24T21:05:59.245Z","updated_at":"2025-04-10T01:08:30.477Z","avatar_url":"https://github.com/hiitiger.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"CoolerCppIdiom\r\n=======\r\n\r\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/da1719248d20475e91623887977f9f54)](https://www.codacy.com/app/hiitiger/CoolerCppIdiom?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=hiitiger/CoolerCppIdiom\u0026amp;utm_campaign=Badge_Grade)\r\n\r\nCollection of useful c++ tools / common idioms you might not found elsewhere, provide with clean code and easy to use api, mose of then are just one file with minimal dependency.\r\n\r\n\r\n## How to\r\n\r\nJust include the corresponding file.\r\n\r\n## Useful kits\r\n\r\n##### [cooler cpp async](https://github.com/hiitiger/CoolerCppIdiom/blob/master/adapter/ppl/appasync.h)\r\nA cooler version of promise pattern, we can create our own dispatcher to dispatch task to threads(ui,pool,io,http,etc) just like using std::async and future\u003cT\u003e::then.\r\n\r\nThis specific implementation uses ppltask, but we can implement it on any primise-like library for c++.\r\n\r\n```c++\r\nusing namespace concurrency_;\r\n\r\nauto t = delayed(1000)\r\n| ui([] {\r\n    std::cout \u003c\u003c \"running on ui\" \u003c\u003c std::endl;\r\n})\r\n| io([] {\r\n    std::cout \u003c\u003c \"running on io\" \u003c\u003c std::endl;\r\n    return std::this_thread::get_id();\r\n})\r\n| delay\u003cstd::thread::id\u003e(100)\r\n| pool([](std::thread::id id) {\r\n    std::cout \u003c\u003c \"running on pool\" \u003c\u003c std::endl;\r\n    std::cout \u003c\u003c \"received thread_id\" \u003c\u003c id  \u003c\u003c std::endl;\r\n});\r\n\r\n```\r\n\r\n##### [json auto serialize](https://github.com/hiitiger/CoolerCppIdiom/blob/master/json/json_auto.h)\r\n\r\nMake json serialization easier for your life.\r\n\r\nWith nlohmann's [JSON for Modern C++](https://github.com/nlohmann/json) plus a helper file, we can do this now\r\n\r\n```c++\r\nstruct Person{\r\n    std::string name;\r\n    std::optional\u003cstd::uint32_t\u003e age;\r\n    std::optional\u003cstd::vector\u003cPerson\u003e\u003e friends;\r\n};\r\n\r\nJSON_AUTO(Person, name, age, friends)\r\n\r\nvoid func()\r\n{\r\n    Person p;\r\n    p.name = \"John\";\r\n    json obj = p;\r\n    Person op = obj;\r\n}\r\n```\r\n\r\n##### [Event Delegate](https://github.com/hiitiger/CoolerCppIdiom/blob/master/object/event.h)\r\nA simple yet powerful event delegate implementation, support trackable listener, provide an alternate bind to std::bind which support bind to smart pointer.\r\n\r\n```c++\r\nEvent\u003cvoid(const std::string\u0026, std::string\u0026\u0026)\u003e signal1;\r\n\r\nauto func1 = Storm::lambda([\u0026, nocopy]() {\r\n    signal1(\"123\", \"123\");\r\n});\r\n\r\nauto conn1 = signal1.add([\u0026slot1](const std::string\u0026 v, std::string\u0026\u0026 str){\r\n    slot1 = true;\r\n    std::cout \u003c\u003c \"\\nslot 1: \" \u003c\u003c v \u003c\u003c \", \" \u003c\u003c std::string(std::move(str)) \u003c\u003c std::endl;\r\n});\r\n\r\nConnection conn2 = signal1.add([\u0026slot2, \u0026conn2](const std::string\u0026 v, std::string\u0026\u0026 str) {\r\n    slot2 = true;\r\n    std::cout \u003c\u003c \"\\nslot 2: \" \u003c\u003c v \u003c\u003c \", \" \u003c\u003c str \u003c\u003c std::endl;\r\n    conn2.disconnect();\r\n});\r\n\r\n\r\nfunc1();\r\n```\r\n\r\n##### [qasync](https://github.com/hiitiger/CoolerCppIdiom/blob/master/adapter/qt/qasync.h)\r\nAn async call adapter for Qt which enables user to post async lambda to Qt's UI thread.\r\n\r\n##### [workerpool](https://github.com/hiitiger/CoolerCppIdiom/blob/master/thread/workerpool.h)\r\nA easy to use c++11 thread pool.\r\n\r\n##### [snowflake](https://github.com/hiitiger/CoolerCppIdiom/blob/master/tool/snowflake.h)\r\nSnowflake uuid generator in c++.\r\n\r\n##### [throttle](https://github.com/hiitiger/CoolerCppIdiom/blob/master/tool/throttle.h)\r\nA simple throttle control.\r\n\r\n##### [trace](https://github.com/hiitiger/CoolerCppIdiom/tree/master/trace)\r\nObject leak trace, perf timer and extras.\r\n\r\n##### [time](https://github.com/hiitiger/CoolerCppIdiom/tree/master/time)\r\nTimetick, Datetime, FpsTimer.\r\n\r\n##### [com ptr](https://github.com/hiitiger/CoolerCppIdiom/blob/master/object/comptr.h)\r\nWindows Com ptr implementation with clean and safe interface.\r\n\r\n##### [object tree](https://github.com/hiitiger/CoolerCppIdiom/blob/master/object/objecttree.h)\r\nObject tree is a useful way to manage object in c++.\r\n\r\n##### [Qt metecall](https://github.com/hiitiger/CoolerCppIdiom/blob/master/adapter/qt/metacall.h)\r\nGenerica Qt metacall which enables user to call QObject's method with name and QVariantList packed arguments.\r\n\r\n```c++\r\n...\r\nconst QString\u0026 object;\r\nconst QString\u0026 method; \r\nconst QVariantList\u0026 args;\r\n//get meta method from method name\r\nQMetaMethod metaMethod;\r\nQx::metaCall(object, metaMethod, args);\r\n\r\n```\r\n\r\n##### [Qt genericsignalmap](https://github.com/hiitiger/CoolerCppIdiom/blob/master/adapter/qt/genericsignalmap.h)\r\nGenerica Qt signal map which enables user to connect QObject's signal with name and QVariantList packed arguments.\r\n\r\n```c++\r\nGenericSignalMapper* mapper1 = new GenericSignalMapper(method, this);\r\nconnect(object, qFlagLocation(signature.toUtf8().constData()), mapper1, SLOT(mapSlot()));\r\nconnect(mapper1, SIGNAL(mapped(QObject*, QMetaMethod, QVariantList)), this, SLOT(onGenericSignal(QObject*, QMetaMethod, QVariantList)));\r\n\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiitiger%2Fcoolercppidiom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiitiger%2Fcoolercppidiom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiitiger%2Fcoolercppidiom/lists"}