diff --git a/io/include/gz/common/DataFrame.hh b/io/include/gz/common/DataFrame.hh index bc340015e..fda99d060 100644 --- a/io/include/gz/common/DataFrame.hh +++ b/io/include/gz/common/DataFrame.hh @@ -68,6 +68,18 @@ namespace gz return this->storage.at(_key); } + /// \brief Retrieve all keys + /// \return A vector with keys + public: const std::vector Keys() const + { + std::vector keyList; + for (auto &[k, _]: this->storage) + { + keyList.push_back(k); + } + return keyList; + } + /// \brief Data frame storage private: std::unordered_map storage; }; diff --git a/io/src/DataFrame_TEST.cc b/io/src/DataFrame_TEST.cc index 5418d6879..fd2e8a215 100644 --- a/io/src/DataFrame_TEST.cc +++ b/io/src/DataFrame_TEST.cc @@ -66,6 +66,9 @@ TEST(DataFrameTests, SimpleCSV) temperatureSession.value(), position); ASSERT_TRUE(temperature.has_value()); EXPECT_DOUBLE_EQ(25.1, temperature.value()); + auto keys = df.Keys(); + ASSERT_EQ(keys.size(), 1); + ASSERT_EQ(keys[0], "temperature"); } ///////////////////////////////////////////////// @@ -87,7 +90,8 @@ TEST(DataFrameTests, ComplexCSV) EXPECT_TRUE(df.Has("temperature")); EXPECT_TRUE(df.Has("humidity")); ASSERT_TRUE(df.Has("pressure")); - + auto keys = df.Keys(); + ASSERT_EQ(keys.size(), 3); const DataT &pressureData = df["pressure"]; auto pressureSession = pressureData.CreateSession(); const math::Vector3d position{36.80079505, -121.789472517, 0.8};