Skip to content

Commit

Permalink
add version API
Browse files Browse the repository at this point in the history
  • Loading branch information
dsieger committed Feb 17, 2019
1 parent 2d513dc commit afbbeeb
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/pmp/Version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//=============================================================================
// Copyright (C) 2019 The pmp-library developers
// Copyright (c) 2010 Martin Reddy. All rights reserved.
//
// This file is part of the Polygon Mesh Processing Library.
// Distributed under the terms of the MIT license, see LICENSE.txt for details.
//
// SPDX-License-Identifier: MIT
//=============================================================================

#include <pmp/Version.h>

#include <sstream>
#include <string>
#include <set>

//=============================================================================

namespace pmp {

//=============================================================================

int Version::get_major()
{
return int(PMP_MAJOR_VERSION);
}

int Version::get_minor()
{
return int(PMP_MINOR_VERSION);
}

int Version::get_patch()
{
return int(PMP_PATCH_VERSION);
}

std::string Version::get_version()
{
static std::string version("");

if (version.empty())
{
// cache the version string
std::ostringstream stream;
stream << PMP_MAJOR_VERSION << "." << PMP_MINOR_VERSION << "."
<< PMP_PATCH_VERSION;
version = stream.str();
}

return version;
}

bool Version::is_at_least(int major, int minor, int patch)
{
if (PMP_MAJOR_VERSION < major)
return false;
if (PMP_MAJOR_VERSION > major)
return true;
if (PMP_MINOR_VERSION < minor)
return false;
if (PMP_MINOR_VERSION > minor)
return true;
if (PMP_PATCH_VERSION < patch)
return false;
return true;
}

bool Version::has_feature(const std::string& name)
{
static std::set<std::string> features;

if (features.empty())
{
// cache the feature list
// features.insert("XXX");
}

return features.find(name) != features.end();
}

//=============================================================================
} // namespace pmp
//=============================================================================
55 changes: 55 additions & 0 deletions src/pmp/Version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//=============================================================================
// Copyright (C) 2019 The pmp-library developers
// Copyright (c) 2010 Martin Reddy. All rights reserved.
//
// This file is part of the Polygon Mesh Processing Library.
// Distributed under the terms of the MIT license, see LICENSE.txt for details.
//
// SPDX-License-Identifier: MIT
//=============================================================================
#pragma once
//=============================================================================

#include <string>

#define PMP_MAJOR_VERSION 0
#define PMP_MINOR_VERSION 1
#define PMP_PATCH_VERSION 0

//=============================================================================

namespace pmp {

//=============================================================================

//! \addtogroup core core
//!@{

//! API version information
class Version
{
public:
//! return the major version number
static int get_major();

//! return the minor version number
static int get_minor();

//! return the patch version number
static int get_patch();

//! return the current API version number as a string
static std::string get_version();

//! return true if the current version >= (major, minor, patch)
static bool is_at_least(int major, int minor, int patch);

//! return true if the named feature is available in this version
static bool has_feature(const std::string &name);
};

//=============================================================================
//!@}
//=============================================================================
} // namespace pmp
//=============================================================================

0 comments on commit afbbeeb

Please sign in to comment.