|
| 1 | +/*********************************************************************************************************************** |
| 2 | +/* __ __ _ _ * |
| 3 | +/* _ __ _ \ \ / /__ _ __ ___(_) ___ _ __ (_)_ __ __ _ * |
| 4 | +/* | '_ \| | | \ \ / / _ \ '__/ __| |/ _ \| '_ \| | '_ \ / _` | * |
| 5 | +/* | |_) | |_| |\ V / __/ | \__ \ | (_) | | | | | | | | (_| | * |
| 6 | +/* | .__/ \__, | \_/ \___|_| |___/_|\___/|_| |_|_|_| |_|\__, | * |
| 7 | +/* |_| |___/ |___/ * |
| 8 | +/*********************************************************************************************************************** |
| 9 | +/* @author Patrick Lehmann * |
| 10 | +/* * |
| 11 | +/* @brief Code example in C++ * |
| 12 | +/* * |
| 13 | +/* @copyright Copyright 2020-2024 Patrick Lehmann - Boetzingen, Germany * |
| 14 | +/* * |
| 15 | +/* Licensed under the Apache License, Version 2.0 (the "License"); * |
| 16 | +/* you may not use this file except in compliance with the License. * |
| 17 | +/* You may obtain a copy of the License at * |
| 18 | +/* * |
| 19 | +/* http://www.apache.org/licenses/LICENSE-2.0 * |
| 20 | +/* * |
| 21 | +/* Unless required by applicable law or agreed to in writing, software * |
| 22 | +/* distributed under the License is distributed on an "AS IS" BASIS, * |
| 23 | +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
| 24 | +/* See the License for the specific language governing permissions and * |
| 25 | +/* limitations under the License. * |
| 26 | +/* * |
| 27 | +/* SPDX-License-Identifier: Apache-2.0 * |
| 28 | +/**********************************************************************************************************************/ |
| 29 | +#include <iostream> |
| 30 | +#include <iomanip> |
| 31 | +#include <cstdlib> |
| 32 | + |
| 33 | +#include "versioning.hpp" |
| 34 | + |
| 35 | +void printVersion() |
| 36 | +{ |
| 37 | + using namespace pyVersioning; |
| 38 | + |
| 39 | + std::cout << "Project: " |
| 40 | + << versioningInformation.project.name |
| 41 | + << " - " |
| 42 | + << versioningInformation.project.variant |
| 43 | + << "\n"; |
| 44 | + |
| 45 | + std::cout << "Version: v" |
| 46 | + << std::to_string(versioningInformation.version.major) |
| 47 | + << "." |
| 48 | + << std::to_string(versioningInformation.version.minor) |
| 49 | + << "." |
| 50 | + << std::to_string(versioningInformation.version.patch) |
| 51 | + << "\n"; |
| 52 | + |
| 53 | + std::cout << "Git: " |
| 54 | + << versioningInformation.git.reference |
| 55 | + << " - " |
| 56 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.git.commit.datetime.date.day) |
| 57 | + << "." |
| 58 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.git.commit.datetime.date.month) |
| 59 | + << "." |
| 60 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.git.commit.datetime.date.year) |
| 61 | + << "-" |
| 62 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.git.commit.datetime.time.hour) |
| 63 | + << ":" |
| 64 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.git.commit.datetime.time.minute) |
| 65 | + << ":" |
| 66 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.git.commit.datetime.time.second) |
| 67 | + << "\n"; |
| 68 | + |
| 69 | + std::cout << " " << versioningInformation.git.commit.hash << "\n"; |
| 70 | + std::cout << " " << versioningInformation.git.repository << "\n"; |
| 71 | + std::cout << "Build on: " |
| 72 | + << versioningInformation.git.reference |
| 73 | + << " - " |
| 74 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.build.datetime.date.day) |
| 75 | + << "." |
| 76 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.build.datetime.date.month) |
| 77 | + << "." |
| 78 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.build.datetime.date.year) |
| 79 | + << "-" |
| 80 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.build.datetime.time.hour) |
| 81 | + << ":" |
| 82 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.build.datetime.time.minute) |
| 83 | + << ":" |
| 84 | + << std::setw(2) << std::setfill('0') << std::to_string(versioningInformation.build.datetime.time.second) |
| 85 | + << "\n"; |
| 86 | + |
| 87 | + std::cout << "Compiler: " |
| 88 | + << versioningInformation.build.compiler.name |
| 89 | + << " (" |
| 90 | + << std::to_string(versioningInformation.build.compiler.version.major) |
| 91 | + << "." |
| 92 | + << std::to_string(versioningInformation.build.compiler.version.minor) |
| 93 | + << "." |
| 94 | + << std::to_string(versioningInformation.build.compiler.version.patch) |
| 95 | + << ")" << std::endl; |
| 96 | +} |
| 97 | + |
| 98 | +int main() |
| 99 | +{ |
| 100 | + std::cout << "========================================\n" |
| 101 | + << "pyVersioning Example C++\n" |
| 102 | + << "========================================" |
| 103 | + << std::endl; |
| 104 | + |
| 105 | + printVersion(); |
| 106 | + |
| 107 | + return EXIT_SUCCESS; |
| 108 | +} |
0 commit comments