* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#ifndef VERSION_H
#define VERSION_H
#include <cstdint>
#include <string>
#include "securec.h"
class Version {
private:
#if MAJOR_VERSION
static constexpr const uint32_t kMajorVersion = MAJOR_VERSION;
#else
static constexpr const uint32_t kMajorVersion = 1;
#endif
#ifdef MINOR_VERSION
static constexpr const uint32_t kMinorVersion = MINOR_VERSION;
#else
static constexpr const uint32_t kMinorVersion = 0;
#endif
#ifdef RELEASE_VERSION
static constexpr const char *kReleaseVersion = RELEASE_VERSION;
#else
static constexpr const char *kReleaseVersion = "0";
#endif
#ifdef BUILD_VERSION
static constexpr const uint32_t kBuildVersion = BUILD_VERSION;
#endif
#ifdef GIT_REVISION
static constexpr const char *kGitRevision = GIT_REVISION;
#endif
#ifdef MINOR_RUNTIME_VERSION
static constexpr const uint32_t kMinorRuntimeVersion = MINOR_RUNTIME_VERSION;
#else
static constexpr const uint32_t kMinorRuntimeVersion = 0;
#endif
public:
static std::string GetVersionStr()
{
std::ostringstream oss;
oss << kMajorVersion << "." << kMinorVersion << "." << kReleaseVersion;
#ifdef BUILD_VERSION
constexpr int BUILD_VERSION_LEN = 5;
char buffer[BUILD_VERSION_LEN] = {0};
int ret = sprintf_s(buffer, BUILD_VERSION_LEN, "B%03d", kBuildVersion);
if (ret >= 0) {
oss << "." << buffer;
}
#endif
#ifdef GIT_REVISION
oss << " " << kGitRevision;
#endif
return oss.str();
}
static inline uint32_t GetMajorVersion()
{
return kMajorVersion;
}
static inline uint32_t GetMinorVersion()
{
return kMinorVersion;
}
static inline const char *GetReleaseVersion()
{
return kReleaseVersion;
}
static inline uint32_t GetRuntimeVersion()
{
return kMinorRuntimeVersion;
}
};
#endif