2019-01-15 13:35:34 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2019-01-21 19:48:49 +00:00
|
|
|
* This source code is licensed as defined on the LICENSE file found in the
|
|
|
|
* root directory of this source tree.
|
2019-01-15 13:35:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osquery/utils/conversions/tryto.h>
|
|
|
|
#include <osquery/utils/expected/expected.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
|
|
|
class SemanticVersion {
|
|
|
|
public:
|
|
|
|
unsigned major = 0;
|
|
|
|
unsigned minor = 0;
|
|
|
|
unsigned patches = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr auto separator = '.';
|
|
|
|
|
|
|
|
public:
|
|
|
|
static Expected<SemanticVersion, ConversionError> tryFromString(
|
|
|
|
const std::string& str);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename ToType>
|
|
|
|
inline typename std::enable_if<std::is_same<ToType, SemanticVersion>::value,
|
|
|
|
Expected<ToType, ConversionError>>::type
|
|
|
|
tryTo(const std::string& str) {
|
|
|
|
return SemanticVersion::tryFromString(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace osquery
|