aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/encoder_state.h
diff options
context:
space:
mode:
authorSergey Polovko <sergey@polovko.me>2022-02-10 16:47:02 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:02 +0300
commit3e0b762a82514bac89c1dd6ea7211e381d8aa248 (patch)
treec2d1b379ecaf05ca8f11ed0b5da9d1a950e6e554 /library/cpp/monlib/encode/encoder_state.h
parentab3783171cc30e262243a0227c86118f7080c896 (diff)
downloadydb-3e0b762a82514bac89c1dd6ea7211e381d8aa248.tar.gz
Restoring authorship annotation for Sergey Polovko <sergey@polovko.me>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/encode/encoder_state.h')
-rw-r--r--library/cpp/monlib/encode/encoder_state.h88
1 files changed, 44 insertions, 44 deletions
diff --git a/library/cpp/monlib/encode/encoder_state.h b/library/cpp/monlib/encode/encoder_state.h
index e6a098f404..51562a3d5f 100644
--- a/library/cpp/monlib/encode/encoder_state.h
+++ b/library/cpp/monlib/encode/encoder_state.h
@@ -1,62 +1,62 @@
-#pragma once
-
+#pragma once
+
#include "encoder_state_enum.h"
#include <util/generic/serialized_enum.h>
-#include <util/generic/yexception.h>
-
+#include <util/generic/yexception.h>
+
-namespace NMonitoring {
+namespace NMonitoring {
template <typename EEncoderState>
class TEncoderStateImpl {
- public:
+ public:
using EState = EEncoderState;
-
+
explicit TEncoderStateImpl(EEncoderState state = EEncoderState::ROOT)
- : State_(state)
- {
- }
-
+ : State_(state)
+ {
+ }
+
TEncoderStateImpl& operator=(EEncoderState rhs) noexcept {
- State_ = rhs;
- return *this;
- }
-
- inline bool operator==(EEncoderState rhs) const noexcept {
- return State_ == rhs;
- }
-
- inline bool operator!=(EEncoderState rhs) const noexcept {
- return !operator==(rhs);
- }
-
+ State_ = rhs;
+ return *this;
+ }
+
+ inline bool operator==(EEncoderState rhs) const noexcept {
+ return State_ == rhs;
+ }
+
+ inline bool operator!=(EEncoderState rhs) const noexcept {
+ return !operator==(rhs);
+ }
+
[[noreturn]] inline void ThrowInvalid(TStringBuf message) const {
- ythrow yexception() << "invalid encoder state: "
- << ToStr() << ", " << message;
- }
-
- inline void Expect(EEncoderState expected) const {
- if (Y_UNLIKELY(State_ != expected)) {
- ythrow yexception()
- << "invalid encoder state: " << ToStr()
+ ythrow yexception() << "invalid encoder state: "
+ << ToStr() << ", " << message;
+ }
+
+ inline void Expect(EEncoderState expected) const {
+ if (Y_UNLIKELY(State_ != expected)) {
+ ythrow yexception()
+ << "invalid encoder state: " << ToStr()
<< ", expected: " << TEncoderStateImpl(expected).ToStr();
- }
- }
-
- inline void Switch(EEncoderState from, EEncoderState to) {
- Expect(from);
- State_ = to;
- }
-
+ }
+ }
+
+ inline void Switch(EEncoderState from, EEncoderState to) {
+ Expect(from);
+ State_ = to;
+ }
+
TStringBuf ToStr() const noexcept {
return NEnumSerializationRuntime::GetEnumNamesImpl<EEncoderState>().at(State_);
}
-
- private:
- EEncoderState State_;
- };
-
+
+ private:
+ EEncoderState State_;
+ };
+
using TEncoderState = TEncoderStateImpl<EEncoderState>;
} // namespace NMonitoring