summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/string/enum.h
blob: 322485a560dace7e96865981c553256b7bf7d4ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include "format_arg.h"

#include <library/cpp/yt/misc/enum.h>

#include <optional>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

std::optional<std::string> TryDecodeEnumValue(TStringBuf value);
std::string DecodeEnumValue(TStringBuf value);
std::string EncodeEnumValue(TStringBuf value);

template <class T>
std::optional<T> TryParseEnum(TStringBuf str, bool enableUnknown = false);

//! Parses an enum value from a string.
//! Link against library/cpp/yt/string/enable_enum_suggestions_on_enum_parse_error
//! to include suggestions in the exception message on parse failure.
template <class T>
T ParseEnum(TStringBuf str);

template <class T>
void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase);

template <class T>
std::string FormatEnum(T value);

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT

#define ENUM_INL_H_
#include "enum-inl.h"
#undef ENUM_INL_H_