| 1 | // |
|---|---|
| 2 | // uuidgen.cpp |
| 3 | // |
| 4 | // This sample demonstrates the UUIDGenerator and UUID classes. |
| 5 | // |
| 6 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 7 | // and Contributors. |
| 8 | // |
| 9 | // SPDX-License-Identifier: BSL-1.0 |
| 10 | // |
| 11 | |
| 12 | |
| 13 | #include "Poco/UUID.h" |
| 14 | #include "Poco/UUIDGenerator.h" |
| 15 | #include "Poco/Exception.h" |
| 16 | #include <iostream> |
| 17 | |
| 18 | |
| 19 | using Poco::UUID; |
| 20 | using Poco::UUIDGenerator; |
| 21 | using Poco::Exception; |
| 22 | |
| 23 | |
| 24 | int main(int argc, char** argv) |
| 25 | { |
| 26 | UUID uuid; |
| 27 | |
| 28 | std::string arg; |
| 29 | if (argc > 1) |
| 30 | arg = argv[1]; |
| 31 | |
| 32 | try |
| 33 | { |
| 34 | if (arg == "-random") |
| 35 | uuid = UUIDGenerator::defaultGenerator().createRandom(); |
| 36 | else if (arg.empty()) |
| 37 | uuid = UUIDGenerator::defaultGenerator().create(); |
| 38 | else |
| 39 | uuid = UUIDGenerator::defaultGenerator().createFromName(UUID::uri(), arg); |
| 40 | |
| 41 | std::cout << uuid.toString() << std::endl; |
| 42 | } |
| 43 | catch (Exception& exc) |
| 44 | { |
| 45 | std::cerr << exc.displayText() << std::endl; |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 |