{"id":18406479,"url":"https://github.com/georgiifirsov/objects","last_synced_at":"2025-04-12T20:29:05.518Z","repository":{"id":159274038,"uuid":"529794475","full_name":"GeorgiiFirsov/objects","owner":"GeorgiiFirsov","description":"COM-inspired, lightweight object management framework for C++17 and later.","archived":false,"fork":false,"pushed_at":"2022-12-22T22:30:59.000Z","size":264,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-16T04:29:04.188Z","etag":null,"topics":["cplusplus","cplusplus-17","cpp","cpp-library","cpp17","framework","interface-builder","object-oriented-programming"],"latest_commit_sha":null,"homepage":"https://georgyfirsov.github.io/objects","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GeorgiiFirsov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-28T07:36:11.000Z","updated_at":"2022-12-15T00:36:28.000Z","dependencies_parsed_at":"2023-06-11T16:10:24.766Z","dependency_job_id":null,"html_url":"https://github.com/GeorgiiFirsov/objects","commit_stats":null,"previous_names":["georgiifirsov/objects"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2Fobjects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2Fobjects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2Fobjects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2Fobjects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GeorgiiFirsov","download_url":"https://codeload.github.com/GeorgiiFirsov/objects/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248628471,"owners_count":21136087,"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","cplusplus-17","cpp","cpp-library","cpp17","framework","interface-builder","object-oriented-programming"],"created_at":"2024-11-06T03:09:16.432Z","updated_at":"2025-04-12T20:29:05.484Z","avatar_url":"https://github.com/GeorgiiFirsov.png","language":"C++","readme":"# objects\n\nCOM-inspired, lightweight object management framework for C++17 and later.\n\n## Installation\n\n`objects` is header-only framework, so you can just clone this repository\nand include the framework as follows:\n\n```cpp\n#include \"objects.hpp\"\n```\n\nNothing else is required.\n\n## Example\n\n```cpp\n//\n// Defines all following stuff:\n//  - Interface identifier: obj::iid_t IID_ISequentialStream;\n//  - Smart pointer specialization: ISequentialStreamPtr (as \n//    obj::SmartPtr\u003cISequentialStream\u003e);\n//  - Struct ISequentialStream inherited from obj::IObject.\n//\nOBJECTS_INTERFACE(ISequentialStream, obj::IObject)\n{\n    //\n    // Read from stream\n    //\n    OBJECTS_INTERFACE_METHOD_DECL(std::size_t, Read)(unsigned char* buffer, \n        std::size_t buffer_size) OBJECTS_PURE;\n\n    //\n    // Write to stream\n    //\n    OBJECTS_INTERFACE_METHOD_DECL(void, Write)(const unsigned char* buffer, \n        std::size_t buffer_size) OBJECTS_PURE;\n};\n\n\n//\n// This interface inherits from ISequentialStream and already contains\n// 'Read' and 'Write' methods.\n//\nOBJECTS_INTERFACE(IStream, ISequentialStream)\n{\n    enum class SeekBase {\n        Begin,\n        End,\n        Current\n    };\n\n    OBJECTS_INTERFACE_METHOD_DECL(void, Seek)(SeekBase base, \n        std::ptrdiff_t offset) OBJECTS_PURE;\n};\n\n\n//\n// Implementation class:\n//  - it inherits obj::hlp::ObjectBase, that implements\n//    internal logic for obj::IObject::Query;\n//  - for creation it uses obj::hlp::DynamicObject, that\n//    implements Acquire, Release and Query methods (the\n//    last one is implemented using obj::hlp::ObjectBase\n//    methods).\n//\nclass Stream\n    : public obj::hlp::ObjectBase\u003cStream, IStream\u003e\n    , public IStream\n{\npublic:\n    static IStreamPtr Create() noexcept\n    {\n        return IStreamPtr{ obj::hlp::DynamicObject\u003cStream\u003e::Create() };\n    }\n\n    //\n    // ISequentialStream\n    //\n\n    OBJECTS_INTERFACE_METHOD(std::size_t, Read)(unsigned char* buffer,\n        std::size_t buffer_size) override\n    {\n        // Implementation\n    }\n\n    OBJECTS_INTERFACE_METHOD(void, Write)(const unsigned char* buffer, \n        std::size_t buffer_size) override\n    {\n        // Implementation\n    }\n\n    //\n    // IStream\n    //\n\n    OBJECTS_INTERFACE_METHOD(void, Seek)(IStream::SeekBase base, \n        std::ptrdiff_t offset) override\n    {\n        // Implementation\n    }\n};\n\n\nvoid ProcessSequentialData(ISequentialStream* stream)\n{\n    // Implementation\n}\n\n\nint main()\n{\n    const auto data = GetDataFrom(\"127.0.0.1\", 8080);\n\n    //\n    // Now we create Stream object, that is wrapped\n    // into IStreamPtr pointer.\n    // It allows us to use it just like IStream* interface \n    // pointer in C++.\n    //\n\n    IStreamPtr stream = Stream::Create();\n    stream-\u003eWrite(data.data(), data.size());\n\n    //\n    // For some purposes we may need to obtain an instance\n    // of another interface (in our case it is ISequentialStream).\n    // It is very simple: just create another smart pointer.\n    // There will be no copies, just reference counter increment.\n    // Underlying object will be destroyed as soon as both of\n    // pointers will go out of scope.\n    //\n\n    ISequentialStreamPtr seq_stream = stream;\n\n    //\n    // SmartPtr\u003cIface\u003e can be implicitly casted to an internal\n    // pointer type (Iface*) and used in some API functions,\n    // that does not require ownership sharing.\n    //\n\n    ProcessSequentialData(seq_stream);\n\n    return 0;\n}\n```\n\nMore examples you can find in so named folder.\n\n## TODO\n\nThese features are in progress. They will be implemented in future releases.\n\n- Support for automatic objects (with automatic storage duration)\n- Single header generator\n- More examples\n- Tests and CI\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgiifirsov%2Fobjects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorgiifirsov%2Fobjects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgiifirsov%2Fobjects/lists"}