2019-06-11 22:59:03 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2019-06-11 22:59:03 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2019-06-11 22:59:03 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2019-06-11 22:59:03 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#include <folly/Expected.h>
|
|
|
|
#include <folly/Portability.h>
|
|
|
|
#include <folly/Range.h>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
enum class ChronoParseError {
|
|
|
|
UnknownUnit,
|
|
|
|
InvalidChronoUnitOrder,
|
|
|
|
Overflow,
|
|
|
|
EmptyInputString,
|
|
|
|
InvalidLeadingChar,
|
|
|
|
NoDigits,
|
|
|
|
NonDigitChar,
|
|
|
|
NonWhitespaceAfterEnd,
|
|
|
|
OtherError,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a human-readable string describing a ChronoParseError code.
|
|
|
|
*/
|
|
|
|
folly::StringPiece chronoParseErrorToString(ChronoParseError error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the human-readable description of a ChronoParseError to a string.
|
|
|
|
*
|
|
|
|
* This allows ChronoParseError arguments to be used with
|
|
|
|
* folly::to<std::string>().
|
|
|
|
*/
|
|
|
|
template <typename String>
|
|
|
|
void toAppend(ChronoParseError error, String* result) {
|
|
|
|
toAppend(chronoParseErrorToString(error), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a string to a std::chrono::nanoseconds duration.
|
|
|
|
*/
|
|
|
|
FOLLY_NODISCARD folly::Expected<std::chrono::nanoseconds, ChronoParseError>
|
|
|
|
stringToDuration(folly::StringPiece src);
|
|
|
|
|
2019-06-11 22:59:03 +03:00
|
|
|
/**
|
|
|
|
* Convert a duration value to a string.
|
|
|
|
*
|
|
|
|
* The resulting string can be parsed with stringToDuration().
|
|
|
|
*/
|
|
|
|
std::string durationToString(std::chrono::nanoseconds duration);
|
|
|
|
|
2019-06-11 22:59:03 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|