Skip to content

Commit

Permalink
Merge pull request #3557 from dmitry-ganyushin/group-API-cleanup
Browse files Browse the repository at this point in the history
Refactoring and clean-up group API
  • Loading branch information
eisenhauer authored Mar 24, 2023
2 parents 4a59197 + 126f936 commit 0355290
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 82 deletions.
19 changes: 2 additions & 17 deletions bindings/CXX11/adios2/cxx11/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ Group Group::InquireGroup(std::string group_name)
auto m = m_Group->InquireGroup(group_name);
return Group(m);
}
void Group::PrintTree()
{
m_Group->PrintTree();
return;
}

void Group::BuildTree()
{
m_Group->BuildTree();
return;
}
std::vector<std::string> Group::AvailableVariables()
{
return m_Group->AvailableVariables();
Expand All @@ -45,11 +34,6 @@ std::vector<std::string> Group::AvailableGroups()
return m_Group->AvailableGroups();
}

std::map<std::string, std::set<std::string>> &Group::getTreeMap()
{
return m_Group->getTreeMap();
}

std::string Group::InquirePath() { return m_Group->InquirePath(); }

void Group::setPath(std::string path) { m_Group->setPath(path); }
Expand All @@ -64,7 +48,8 @@ DataType Group::AttributeType(const std::string &name) const
helper::CheckForNullptr(m_Group, "in call to IO::AttributeType");
return m_Group->InquireAttributeType(name);
}
Group::~Group(){};
Group::~Group() = default;
;
// Explicit declaration of the public template methods
// Limits the types
#define declare_template_instantiation(T) \
Expand Down
17 changes: 0 additions & 17 deletions bindings/CXX11/adios2/cxx11/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,11 @@ class Group
{
friend class IO;

private:
Group(core::Group *group);
core::Group *m_Group = nullptr;

public:
~Group();
/**
* @brief Builds map that represents tree structure from m_Variable and
* m_Attributes from IO class
* @param
*/
void BuildTree();
/**
* @brief Prints map that represents tree structure
* @param
*/
void PrintTree();
/**
* @brief returns available groups on the path set
* @param
Expand Down Expand Up @@ -91,11 +79,6 @@ class Group
* @return new group object
*/
Group InquireGroup(std::string group_name);
/**
* @brief returns a reference to the map representing the tree stucture
* @param delimiter symbol
*/
std::map<std::string, std::set<std::string>> &getTreeMap();
/**
* @brief Gets an existing variable of primitive type by name. A wrapper for
* the corresponding function of the IO class
Expand Down
46 changes: 7 additions & 39 deletions source/adios2/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
#include "Group.h"
#include "Group.tcc"
#include <iostream>
#include <memory>
#include <set>
#include <string>
Expand Down Expand Up @@ -59,16 +58,6 @@ Group *Group::InquireGroup(std::string groupName)
m_Gr->mapPtr = this->mapPtr;
return m_Gr.get();
}
void Group::PrintTree()
{
for (auto k : mapPtr->treeMap)
{
std::cout << k.first << "=>";
for (auto v : k.second)
std::cout << v << " ";
std::cout << std::endl;
}
}

void Group::BuildTree()
{
Expand All @@ -83,16 +72,7 @@ void Group::BuildTree()
else
tokens.insert(tokens.begin(), ADIOS_root);
currentPath = ADIOS_root;

if (tokens.size() == 0)
{
// record = "group". Handled by default case
}
else if (tokens.size() == 1)
{
// case record = "/group1" or "group/"
}
else
if (tokens.size() > 1)
{
std::string key = tokens[0];
for (size_t level = 1; level < tokens.size(); level++)
Expand All @@ -112,15 +92,6 @@ void Group::BuildTree()
{
std::vector<std::string> tokens =
split(attributePair.first, groupDelimiter);

if (tokens.size() == 0)
{
// record = "group". Handled by default case
}
else if (tokens.size() == 1)
{
// case record = "/group1" or "group/"
}
if (tokens.size() > 1)
{
std::string key = tokens[0];
Expand All @@ -141,9 +112,8 @@ std::vector<std::string> Group::AvailableVariables()
{
// look into map
std::set<std::string> val = mapPtr->treeMap[currentPath];
// TODODG check that currentPath exists
std::vector<std::string> available_variables;
for (auto v : val)
for (auto const &v : val)
{
if (mapPtr->treeMap.find(currentPath + groupDelimiter + v) ==
mapPtr->treeMap.end())
Expand All @@ -168,7 +138,7 @@ std::vector<std::string> Group::AvailableAttributes()
std::set<std::string> val = mapPtr->treeMap[currentPath];
// TODODG check that currentPath exists
std::vector<std::string> available_attributes;
for (auto v : val)
for (auto const &v : val)
{
if (mapPtr->treeMap.find(currentPath + groupDelimiter + v) ==
mapPtr->treeMap.end())
Expand All @@ -192,13 +162,11 @@ std::vector<std::string> Group::AvailableGroups()

std::vector<std::string> available_groups;
std::set<std::string> val = mapPtr->treeMap[currentPath];
for (auto const &v : val)
{
for (auto v : val)
{
if (mapPtr->treeMap.find(currentPath + groupDelimiter + v) !=
mapPtr->treeMap.end())
available_groups.push_back(v);
}
if (mapPtr->treeMap.find(currentPath + groupDelimiter + v) !=
mapPtr->treeMap.end())
available_groups.push_back(v);
}
return available_groups;
}
Expand Down
13 changes: 4 additions & 9 deletions source/adios2/core/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Group
std::shared_ptr<TreeMap> mapPtr = nullptr;
/** root of the tree */
const std::string ADIOS_root = "_ADIOS_ROOT_";
/** a pointer to a Group Object */
std::shared_ptr<Group> m_Gr;
/** reference to object that created current Group */
IO &m_IO;

public:
/**
Expand All @@ -52,19 +56,12 @@ class Group
Group(const Group &G);
/** destructor */
~Group();
/** a pointer to a Group Object */
std::shared_ptr<Group> m_Gr;
/**
* @brief Builds map that represents tree structure from m_Variable and
* m_Attributes from IO class
* @param
*/
void BuildTree();
/**
* @brief Prints map that represents tree structure
* @param
*/
void PrintTree();
/**
* @brief returns available groups on the path set
* @param
Expand Down Expand Up @@ -110,8 +107,6 @@ class Group
* @param delimiter symbol
*/
std::map<std::string, std::set<std::string>> &getTreeMap();
/** reference to object that created current Group */
IO &m_IO;
/**
* @brief Gets an existing variable of primitive type by name. A wrapper for
* the corresponding function of the IO class
Expand Down

0 comments on commit 0355290

Please sign in to comment.