isapego commented on code in PR #1287:
URL: https://github.com/apache/ignite-3/pull/1287#discussion_r1010206394


##########
modules/platforms/cpp/ignite/client/table/ignite_tuple.h:
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "ignite/common/config.h"
+#include "ignite/common/ignite_error.h"
+
+#include <any>
+#include <initializer_list>
+#include <string_view>
+#include <unordered_map>
+#include <vector>
+#include <utility>
+
+namespace ignite {
+
+class ignite_tuple_builder;
+
+/**
+ * Ignite tuple.
+ */
+class ignite_tuple {
+    friend class ignite_tuple_builder;
+public:
+    // Default
+    ignite_tuple() = default;
+
+    /**
+     * Constructor.
+     *
+     * @param pairs Pairs.
+     */
+    ignite_tuple(std::initializer_list<std::pair<std::string, std::any>> pairs)
+        : m_pairs(pairs)
+        , m_indices()
+    {
+        for (size_t i = 0; i < m_pairs.size(); ++i)
+            m_indices.emplace(std::make_pair(parse_name(m_pairs[i].first), i));
+    }
+
+    /**
+     * Gets a number of columns in the tuple.
+     *
+     * @return Number of columns in the tuple.
+     */
+    [[nodiscard]] std::int32_t column_count() const noexcept {
+        return std::int32_t(m_pairs.size());
+    }
+
+    /**
+     * Gets the value of the specified column.
+     *
+     * @param idx The column index.
+     * @return Column value.
+     */
+    [[nodiscard]] const std::any& get(uint32_t idx) const {
+        if (idx > m_pairs.size()) {
+            throw ignite_error("Index is too large: idx=" + 
std::to_string(idx) +
+                ", columns_num=" + std::to_string(m_pairs.size()));
+        }
+        return m_pairs[idx].second;
+    }
+
+    /**
+     * Gets the value of the specified column.
+     *
+     * @tparam T Column type.
+     * @param idx The column index.
+     * @return Column value.
+     */
+    template<typename T>
+    [[nodiscard]] T get(uint32_t idx) const {
+        return std::any_cast<T>(get(idx));
+    }
+
+    /**
+     * Sets the value of the specified column.
+     *
+     * @tparam T Column type.
+     * @param idx The column index.
+     * @param value Value.
+     */
+    template<typename T>
+    void set(uint32_t idx, T&& value) {
+        if (idx > m_pairs.size()) {
+            throw ignite_error("Index is too large: idx=" + 
std::to_string(idx) +
+                ", columns_num=" + std::to_string(m_pairs.size()));
+        }
+        m_pairs[idx].second = std::forward<T>(value);
+    }
+
+    /**
+     * Gets the value of the specified column.
+     *
+     * @param name The column name.
+     * @return Column value.
+     */
+    [[nodiscard]] const std::any& get(std::string_view name) const {
+        auto it = m_indices.find(parse_name(name));
+        if (it == m_indices.end())
+            throw ignite_error("Can not find column with the name '" + 
std::string(name) + "' in the tuple");
+        auto idx = it->second;
+        return m_pairs[idx].second;
+    }
+
+    /**
+     * Gets the value of the specified column.
+     *
+     * @tparam T Column type.
+     * @param name The column name.
+     * @return Column value.
+     */
+    template<typename T>
+    [[nodiscard]] T get(std::string_view name) const {
+        return std::any_cast<T>(get(name));
+    }
+
+    /**
+     * Sets the value of the specified column.
+     *
+     * @tparam T Column type.
+     * @param name The column name.
+     * @param value Value.
+     */
+    template<typename T>
+    void set(std::string_view name, T&& value) {

Review Comment:
   Agreed. Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to