From edc14ea380907d7e678846add7b902328a990847 Mon Sep 17 00:00:00 2001 From: Don Turner Date: Tue, 19 Dec 2017 11:46:48 +0000 Subject: [PATCH] Use #defines for version numbers --- CMakeLists.txt | 1 - include/oboe/Version.h | 68 +++++++++++++++++++++++++++++++----------- src/common/Version.cpp | 39 ------------------------ 3 files changed, 50 insertions(+), 58 deletions(-) delete mode 100644 src/common/Version.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d67372f0f..1b82a0fda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ set (oboe_sources src/common/AudioStream.cpp src/common/AudioStreamBuilder.cpp src/common/Utilities.cpp - src/common/Version.cpp src/fifo/FifoBuffer.cpp src/fifo/FifoController.cpp src/fifo/FifoControllerBase.cpp diff --git a/include/oboe/Version.h b/include/oboe/Version.h index dbfd95680..ce468ebdf 100644 --- a/include/oboe/Version.h +++ b/include/oboe/Version.h @@ -17,38 +17,70 @@ #ifndef OBOE_VERSIONINFO_H #define OBOE_VERSIONINFO_H +/** + * A note on use of preprocessor defines: + * + * This is one of the few times when it's suitable to use preprocessor defines rather than constexpr + * Why? Because C++11 requires a lot of boilerplate code to convert integers into compile-time + * string literals. The preprocessor, despite it's lack of type checking, is more suited to the task + * + * See: https://stackoverflow.com/questions/6713420/c-convert-integer-to-string-at-compile-time/26824971#26824971 + * + */ + +// Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description. +#define OBOE_VERSION_MAJOR 0 + +// Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description. +#define OBOE_VERSION_MINOR 9 + +// Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description. +#define OBOE_VERSION_PATCH 0 + +#define OBOE_STRINGIFY(x) #x +#define OBOE_TOSTRING(x) OBOE_STRINGIFY(x) + +// Type: String literal. See below for description. +#define OBOE_VERSION_TEXT \ + OBOE_TOSTRING(OBOE_VERSION_MAJOR) "." \ + OBOE_TOSTRING(OBOE_VERSION_MINOR) "." \ + OBOE_TOSTRING(OBOE_VERSION_PATCH) + +// Type: 32-bit unsigned int. See below for description. +#define OBOE_VERSION_NUMBER ((OBOE_VERSION_MAJOR << 24) | (OBOE_VERSION_MINOR << 16) | OBOE_VERSION_PATCH) + namespace oboe { class Version { public: - // This is incremented when we make breaking API changes. Based loosely on https://semver.org/ - static constexpr uint8_t MajorNumber = 0; + /** + * This is incremented when we make breaking API changes. Based loosely on https://semver.org/. + */ + static constexpr uint8_t Major = OBOE_VERSION_MAJOR; - // This is incremented when we add backwards compatible functionality. Or set to zero when kVersionMajor is - // incremented - static constexpr uint8_t MinorNumber = 9; + /** + * This is incremented when we add backwards compatible functionality. Or set to zero when MAJOR is + * incremented. + */ + static constexpr uint8_t Minor = OBOE_VERSION_MINOR; - // This is incremented when we make backwards compatible bug fixes. Or set to zero when kVersionMinor is - // incremented - static constexpr uint16_t SubMinorNumber = 0; + /** + * This is incremented when we make backwards compatible bug fixes. Or set to zero when MINOR is + * incremented. + */ + static constexpr uint16_t Patch = OBOE_VERSION_PATCH; /** - * Provides a text representation of the current Oboe library version in the form: - * - * MAJOR.MINOR.SUBMINOR - * - * @return A string containing the current Oboe library version + * Version string in the form MAJOR.MINOR.PATCH. */ - static const char * toString(); + static constexpr const char * Text = OBOE_VERSION_TEXT; /** - * Provides an integer representation of the current Oboe library version. This will always increase when the + * Integer representation of the current Oboe library version. This will always increase when the * version number changes so can be compared using integer comparison. - * - * @return an integer representing the current Oboe library version. */ - static uint32_t toInt(); + static constexpr uint32_t Number = OBOE_VERSION_NUMBER; }; } // namespace oboe diff --git a/src/common/Version.cpp b/src/common/Version.cpp deleted file mode 100644 index e5074985e..000000000 --- a/src/common/Version.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "oboe/Version.h" - -namespace oboe { - -// Max digits in 32-bit unsigned int = 10, plus two periods, plus null terminator = 13 -constexpr int kMaxVersionStringLength = 13; - -const char * Version::toString() { - - static char text[kMaxVersionStringLength]; - snprintf(text, kMaxVersionStringLength, "%d.%d.%d", - MajorNumber, - MinorNumber, - SubMinorNumber); - return text; -} - -uint32_t Version::toInt(){ - return MajorNumber << 24 | MinorNumber << 16 | SubMinorNumber; -} - -} // namespace oboe \ No newline at end of file