From e51b937211118409e4847cbbfea3055de7d23e91 Mon Sep 17 00:00:00 2001 From: Bulat Gayazov Date: Thu, 29 Aug 2024 17:51:43 +0000 Subject: [PATCH] Refactored operation id --- .../library/operation_id/operation_id.h | 12 +++++++- .../library/yql_common/issue/yql_issue.h | 4 +-- src/library/operation_id/operation_id.cpp | 28 +++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/include/ydb-cpp-sdk/library/operation_id/operation_id.h b/include/ydb-cpp-sdk/library/operation_id/operation_id.h index 4d29c77a29..8418288129 100644 --- a/include/ydb-cpp-sdk/library/operation_id/operation_id.h +++ b/include/ydb-cpp-sdk/library/operation_id/operation_id.h @@ -35,8 +35,17 @@ class TOperationId { TOperationId(); explicit TOperationId(const std::string& string, bool allowEmpty = false); + + TOperationId(const TOperationId& other); + TOperationId(TOperationId&& other) = default; + + TOperationId& operator=(const TOperationId& other); + TOperationId& operator=(TOperationId&& other) = default; + + ~TOperationId() = default; + EKind GetKind() const; - EKind& GetMutableKind(); + void SetKind(const EKind& kind); const TDataList& GetData() const; TDataList& GetMutableData(); @@ -47,6 +56,7 @@ class TOperationId { private: bool IsValidKind(int kind); + void CopyData(const TOperationId::TDataList& otherData); EKind Kind; TDataList Data; diff --git a/include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h b/include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h index abea688129..02b814c65d 100644 --- a/include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h +++ b/include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h @@ -112,7 +112,7 @@ class TIssue; using TIssuePtr = TIntrusivePtr; class TIssue: public TThrRefBase { std::vector> Children_; - std::string Message; + TString Message; public: TPosition Position; TPosition EndPosition; @@ -209,7 +209,7 @@ class TIssue: public TThrRefBase { } // Unsafe method. Doesn't call SanitizeNonAscii(Message) - std::string* MutableMessage() { + TString* MutableMessage() { return &Message; } diff --git a/src/library/operation_id/operation_id.cpp b/src/library/operation_id/operation_id.cpp index 146e45b4fe..ea843bef03 100644 --- a/src/library/operation_id/operation_id.cpp +++ b/src/library/operation_id/operation_id.cpp @@ -120,19 +120,35 @@ TOperationId::TOperationId(const std::string &string, bool allowEmpty) { } } -TOperationId::EKind TOperationId::GetKind() const { - return Kind; +TOperationId::TOperationId(const TOperationId& other) { + Kind = other.Kind; + CopyData(other.Data); +} + +TOperationId& TOperationId::operator=(const TOperationId& other) { + Kind = other.Kind; + Data.clear(); + Index.clear(); + CopyData(other.Data); + return *this; } -TOperationId::EKind& TOperationId::GetMutableKind() { +void TOperationId::CopyData(const TOperationId::TDataList& otherData) { + for (const auto& data : otherData) { + Data.push_back(std::make_unique(data->Key, data->Value)); + Index[data->Key].push_back(&Data.back()->Value); + } +} + +TOperationId::EKind TOperationId::GetKind() const { return Kind; } -const TOperationId::TDataList& TOperationId::GetData() const { - return Data; +void TOperationId::SetKind(const EKind& kind) { + Kind = kind; } -TOperationId::TDataList& TOperationId::GetMutableData() { +const TOperationId::TDataList& TOperationId::GetData() const { return Data; }