{"id":18359160,"url":"https://github.com/cihansari/vah","last_synced_at":"2025-04-10T03:18:48.727Z","repository":{"id":95977334,"uuid":"278135071","full_name":"CihanSari/vah","owner":"CihanSari","description":"Variant Access Helper","archived":false,"fork":false,"pushed_at":"2021-11-07T17:59:19.000Z","size":207,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T03:18:46.743Z","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/CihanSari.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":"2020-07-08T16:05:10.000Z","updated_at":"2021-11-07T17:59:21.000Z","dependencies_parsed_at":"2023-06-13T09:00:40.774Z","dependency_job_id":null,"html_url":"https://github.com/CihanSari/vah","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/CihanSari%2Fvah","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CihanSari%2Fvah/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CihanSari%2Fvah/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CihanSari%2Fvah/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CihanSari","download_url":"https://codeload.github.com/CihanSari/vah/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248148247,"owners_count":21055548,"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-11-05T22:21:09.862Z","updated_at":"2025-04-10T03:18:48.706Z","avatar_url":"https://github.com/CihanSari.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Runtime variant access helper\r\n\r\nSingle header only variant access helper. Useful for serializing or handling variant types with template specialization. Useful for factory code or replacing inheritance.\r\n\r\n[![Build Status](https://csari.visualstudio.com/VariantAccessHelper/_apis/build/status/CihanSari.vah?branchName=master)](https://csari.visualstudio.com/VariantAccessHelper/_build/latest?definitionId=3\u0026branchName=master)\r\n\r\n# Example codes\r\n## Serialization example\r\nThis example is just provided as a showcase and shouldn't be used in production. Use your own serialization library in combination of the vah for best results.\r\n\r\n```c++\r\n#include \u003csstream\u003e\r\n#include \u003ccsari/vah.hpp\u003e\r\ntemplate \u003cclass V\u003e\r\nauto serializeVariantVector(std::vector\u003cV\u003e const\u0026 vecVar) -\u003e std::string {\r\n  auto ss = std::stringstream{};\r\n  auto const fWriteStream = [\u0026ss](auto const\u0026 val) {\r\n    ss.write(reinterpret_cast\u003cchar const*\u003e(\u0026val), sizeof(val));\r\n  };\r\n  fWriteStream(size(vecVar));\r\n  std::for_each(begin(vecVar), end(vecVar), [\u0026fWriteStream](V const\u0026 var) {\r\n    fWriteStream(var.index());\r\n    csari::vah::performOnData(\r\n        var, [\u0026fWriteStream](auto\u0026 val) { fWriteStream(val); });\r\n  });\r\n  return ss.str();\r\n}\r\n\r\ntemplate \u003cclass V\u003e\r\nauto loadVariantVector(std::string\u0026\u0026 serializedData) -\u003e std::vector\u003cV\u003e {\r\n  auto ss = std::stringstream{std::forward\u003cstd::string\u003e(serializedData)};\r\n  auto const fReadStream = [\u0026ss](auto\u0026 val) {\r\n    ss.read(reinterpret_cast\u003cchar*\u003e(\u0026val), sizeof(val));\r\n  };\r\n  auto dataVectorLoaded = std::vector\u003cV\u003e{};\r\n  auto nElements = std::size_t{};\r\n  fReadStream(nElements);\r\n  dataVectorLoaded.reserve(nElements);\r\n  std::generate_n(std::back_inserter(dataVectorLoaded), nElements,\r\n                  [\u0026fReadStream] {\r\n                    auto index = std::size_t{};\r\n                    fReadStream(index);\r\n                    return csari::vah::constructAndPerformOnData\u003cV\u003e(\r\n                        index, [\u0026fReadStream](auto\u0026 val) { fReadStream(val); });\r\n                  });\r\n  return dataVectorLoaded;\r\n}\r\n\r\nvoid serializationExample() {\r\n  using V = std::variant\u003cstd::size_t, char\u003e;\r\n  auto const dataVector = std::vector\u003cV\u003e{std::size_t{42U}, 'a', 'b'};\r\n  auto const dataVectorLoaded =\r\n      loadVariantVector\u003cV\u003e(serializeVariantVector(dataVector));\r\n}\r\n```\r\n\r\n## Construction and update example\r\n```cpp\r\n#include \u003ccsari/vah.hpp\u003e\r\nvoid variantConstructAndUpdate(std::size_t index = 1U) {\r\n  using namespace csari::vah;\r\n  using V = std::variant\u003cfloat, int, char\u003e;\r\n  // initialize index 1 (integer) with default value\r\n  auto var = constructVariantFromIndexRuntime\u003cV\u003e(index);\r\n  performOnData(var, [](auto\u0026 val) constexpr {\r\n        using U = std::remove_reference_t\u003cdecltype(val)\u003e;\r\n        if constexpr (std::is_same_v\u003cU, float\u003e) {\r\n          val = 48;\r\n        } else if constexpr (std::is_same_v\u003cU, int\u003e) {\r\n          val = 14.8f;\r\n        } else if constexpr (std::is_same_v\u003cU, char\u003e) {\r\n          val = 'k';\r\n        }\r\n      });\r\n}\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcihansari%2Fvah","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcihansari%2Fvah","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcihansari%2Fvah/lists"}