{"id":18031759,"url":"https://github.com/dagronf/libuuidpp","last_synced_at":"2025-09-11T05:18:21.589Z","repository":{"id":50707798,"uuid":"180064161","full_name":"dagronf/libuuidpp","owner":"dagronf","description":"A simple C++ UUID class wrapping libuuid","archived":false,"fork":false,"pushed_at":"2019-06-27T04:20:57.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T21:45:54.697Z","etag":null,"topics":["cpp","libuuid","linux","macos","unix","uuid"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dagronf.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":"2019-04-08T03:40:23.000Z","updated_at":"2025-03-26T01:04:40.000Z","dependencies_parsed_at":"2022-09-02T12:10:12.746Z","dependency_job_id":null,"html_url":"https://github.com/dagronf/libuuidpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dagronf/libuuidpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2Flibuuidpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2Flibuuidpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2Flibuuidpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2Flibuuidpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dagronf","download_url":"https://codeload.github.com/dagronf/libuuidpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2Flibuuidpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274580727,"owners_count":25311228,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cpp","libuuid","linux","macos","unix","uuid"],"created_at":"2024-10-30T10:10:42.185Z","updated_at":"2025-09-11T05:18:21.567Z","avatar_url":"https://github.com/dagronf.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libuuidpp - A lightweight C++ UUID class.\n\nA lightweight C++ class wrapper around the `libuuid` library.\n\n## Features\n\n* Compatible with std containers such as `std::vector`, `std::set`, `std::map` etc.\n* Handles upper and lower case uuids.\n* Automatically handles Microsoft-formatted uuids `{D1ABE846-63D3-4C0A-89EF-68F1A306F6D3}`\n* Multiple formats for output strings (uppercase, lowercase, bracketed).\n* Equality and greater/lesser comparators.\n\n## Why?\n\nI wanted a very simple lightweight UUID class wrapper without having to import boost or some other large framework that would be compatible with the standard library (eg. `std::vector`, `std::map`).  I also didn't want to write the UUID generation myself, as here be dragons (especially relating to privacy).  libuuid is a well defined and tested generator.\n\n`libuuid` is installed by default on macOS and is an easy install for other platforms.\n\n## Usage\n\nJust add `libuuidpp/libuuidpp.hpp` to your project. Requires `libuuid` and standard C++ libraries (compatible back to C++11, tested up to C++17).\n\nYou can find a bunch of tests in `main.cpp`.\n\n## API classes\n\n### `libuuidpp::uuid`\n\nThe uuid class\n\n### `libuuidpp::uuid::formatting`\n\nA typesafe enum bitfield for describing string output.\n\n### `libuuidpp::uuid::binary`\n\nA class used to transport raw binary data in and out of the uuid object.\n\n## Examples\n\n### Simple creation\n```cpp\n// The standard string constructor throws an exception if the guid is invalid\nlibuuidpp::uuid uid1(\"D1ABE846-63D3-4C0A-89EF-68F1A306F6D3\");\nlibuuidpp::uuid uid2(\"d1abe846-63d3-4c0a-89ef-68f1a306f6d3\");\nlibuuidpp::uuid uid3(\"{D1ABE846-63D3-4C0A-89EF-68F1A306F6D3}\");\n```\n\n### Creating random UUIDs and nil UUID.\n```cpp\n// Create a random uuid\nauto random_uid = libuuidpp::uuid::random();\nassert(!random_uid.is_nil());\n\n// nil uuid (statically defined)\nconst auto\u0026 nil_uid = libuuidpp::uuid::nil;\nassert(nil_uid.is_nil());\n```\n\n### Binary handling\n```cpp\n/// Create a uuid object from raw binary data\nlibuuidpp::uuid::binary binaryData {\n   0xc0, 0x6c, 0x89, 0x2b, 0x50, 0xab, 0x45, 0x85, 0x98, 0x19, 0x5f, 0x4b, 0xa3, 0xb8, 0xf6, 0x9b\n};\nlibuuidpp::uuid uuid(binaryData);\n\n/// Get the data back out\nconst libuuidpp::uuid::binary roundTrip = raw.data();\n```\n\n### Setting\n\n#### Constructor throws exceptions for invalid uuids\n```cpp\ntry {\n   libuuidpp::uuid my_dodgy_uuid(\"F211F534-8DFB-4269-9A bad\");\n\t\n   // Do something with my_dodgy_uuid\n\t\n} catch (libuuidpp::exception::invalid_uuid e) {\n   printf(\"Successfully caught exception during creation\\n\");\n}\n```\n#### Basic setters\n```cpp\nlibuuidpp::uuid myUUID;\nbool didSet = myUUID.set(\"F211F534-8DFB-4269-9AF1-245FA0AB8D87\");\nassert(didSet == true);\n\n/// Attempting assignment to an invalid uuid string\ndidSet = myUUID.set(\"D1ABE846-63D3-4C0A-89EF-\");\nassert(didSet == false);\nassert(myUUID.is_nil());\n\n/// Set myUUID to a random guid\nmyUUID.set_random();\nassert(!myUUID.is_nil());\n\n/// Assigning a new uuid\nauto newUUID = libuuidpp::uuid(\"D1ABE846-63D3-4C0A-89EF-68F1A306F6D3\");\nmyUUID = newUUID;\nassert(myUUID == newUUID);\n```\n### Generate a string from the uuid\n```cpp\nlibuuidpp::uuid uid1(\"D1ABE846-63D3-4C0A-89EF-68F1A306F6D3\");\n\n// Default output (uppercase, no brackets)\nstd::string uidString1 = uid1.str();\nassert(uidString1 == \"D1ABE846-63D3-4C0A-89EF-68F1A306F6D3\");\n\n// Lowercase output\nstd::string uidString2 = uid1.str(libuuidpp::uuid::formatting::lowercase);\nassert(uidString2 == \"d1abe846-63d3-4c0a-89ef-68f1a306f6d3\");\n\n// Bracketed output\nstd::string uidString3 = uid1.str(libuuidpp::uuid::formatting::brackets);\nassert(uidString3 == \"{D1ABE846-63D3-4C0A-89EF-68F1A306F6D3}\");\n\n// Lowercase, Bracketed output\nstd::string uidString4 = uid1.str(libuuidpp::uuid::formatting::lowercase | libuuidpp::uuid::formatting::brackets);\nassert(uidString4 == \"{d1abe846-63d3-4c0a-89ef-68f1a306f6d3}\");\n```\n### Comparison operators\n```cpp\nlibuuidpp::uuid uid1(\"d1abe846-63d3-4c0a-89ef-68f1a306f6d3\");\nlibuuidpp::uuid uid2(\"{D1ABE846-63D3-4C0A-89EF-68F1A306F6D3}\");\nlibuuidpp::uuid uid3(\"84AEEDE7-E056-4F89-BAD1-BF97B96FAAAA\");\n\n/// uid1 and uid2 resolve to the same uuid value, therefore they are equal\nassert(uid1 == uid2);\n\n/// uid2 and uid3 are different uuids, so they aren't equal\nassert(uid2 != uid3);\n```\n### Lexigraphic sorting support\n```cpp\nstd::vector\u003clibuuidpp::uuid\u003e result;\nfor (size_t c = 0; c \u003c 10; c++) {\n   result.push_back(libuuidpp::uuid::random());\n}\nstd::sort(result1.begin(), result1.end(), std::less\u003clibuuidpp::uuid\u003e());\nstd::sort(result1.begin(), result1.end(), std::greater\u003clibuuidpp::uuid\u003e());\n```\n## Thanks\n\nTypesafe enum bitfield support from Just Software Solutions.\n\n - See [https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html](https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html)\n\n## License\n\n```\nBoost Software License - Version 1.0 - August 17th, 2003\n\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Flibuuidpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdagronf%2Flibuuidpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Flibuuidpp/lists"}