Skip to content

Commit

Permalink
add filter functions for log nodes (#424)
Browse files Browse the repository at this point in the history
* * Added the 'conduit::utils::log::filter_{invalid|nonoptional}' functions to help users create less verbose info outputs.
* Added the 't_conduit_log.cpp' test case to validate all of the functions in the 'conduit::utils::log' namespace.

* * Improved the names for the "filtering" functions to use the more active verb "remove".
* Added the "conduit::utils::log::remove_invalid" function and its associated test cases.
* Refactored the implementation between all of the "conduit::utils::log::remove_*" functions to reduce code duplication.

* * Updated the CHANGELOG to include the implementation of the new 'conduit::utils::log::remove_*' functions.
  • Loading branch information
xjrc authored and cyrush committed Jan 27, 2020
1 parent b6d6420 commit feb58d6
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Notable changes to Conduit are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project aspires to adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

#### General
- Added a set of conduit::utils::log::remove_* filtering functions, which process conduit log/info nodes and strip out the requested information (useful for focusing the often verbose output in log/info nodes).


## [0.5.1] - Released 2020-01-18

Expand Down
80 changes: 80 additions & 0 deletions src/libs/conduit/conduit_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

using namespace conduit;

typedef bool (*VerifyFun)(const Node&);

//-----------------------------------------------------------------------------
// -- begin conduit:: --
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -114,6 +116,84 @@ validation(Node &info,
}


//-----------------------------------------------------------------------------
bool
remove_tree(Node &info, const VerifyFun should_remove_fun)
{
if(info.dtype().is_object() || info.dtype().is_list())
{
std::vector<index_t> removal_subtrees;

NodeIterator info_itr = info.children();
while(info_itr.has_next())
{
conduit::Node &info_child = info_itr.next();
if(remove_tree(info_child, should_remove_fun))
{
removal_subtrees.push_back(info_itr.index());
}
}

for(index_t ci = removal_subtrees.size(); ci-- > 0;)
{
info.remove(removal_subtrees[ci]);
}

// FIXME: This part of the solution makes it imperfect from a recursive
// standpoint, but it makes it well-suited to accomodate the child-informed
// removal criteria used for the 'log::remove_*' functions.
if(should_remove_fun(info))
{
info.set(DataType::empty());
}
}

return should_remove_fun(info);
}


//-----------------------------------------------------------------------------
bool is_valid(const Node &n)
{
return n.dtype().is_empty() || (n.has_child("valid") && n["valid"].dtype().is_string() && n["valid"].as_string() == "true");
};

//-----------------------------------------------------------------------------
void
remove_valid(Node &info)
{
remove_tree(info, is_valid);
}


//-----------------------------------------------------------------------------
bool is_invalid(const Node &n)
{
return n.dtype().is_empty() || (n.has_child("valid") && n["valid"].dtype().is_string() && n["valid"].as_string() == "false");
};

//-----------------------------------------------------------------------------
void
remove_invalid(Node &info)
{
remove_tree(info, is_invalid);
}


//-----------------------------------------------------------------------------
bool is_optional(const Node &n)
{
return n.dtype().is_empty() || (n.name() == "optional");
};

//-----------------------------------------------------------------------------
void
remove_optional(Node &info)
{
remove_tree(info, is_optional);
}


//-----------------------------------------------------------------------------
std::string
quote(const std::string &str,
Expand Down
9 changes: 9 additions & 0 deletions src/libs/conduit/conduit_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ void CONDUIT_API error(conduit::Node &info,
void CONDUIT_API validation(conduit::Node &info,
bool res);


//-----------------------------------------------------------------------------
void CONDUIT_API remove_valid(conduit::Node &info);
//-----------------------------------------------------------------------------
void CONDUIT_API remove_invalid(conduit::Node &info);

//-----------------------------------------------------------------------------
void CONDUIT_API remove_optional(conduit::Node &info);

//-----------------------------------------------------------------------------
std::string CONDUIT_API quote(const std::string &str,
bool pad_before = false);
Expand Down
1 change: 1 addition & 0 deletions src/tests/conduit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ set(BASIC_TESTS t_conduit_smoke
t_conduit_node_iterator
t_conduit_schema
t_conduit_error
t_conduit_log
t_conduit_utils)


Expand Down
Loading

0 comments on commit feb58d6

Please sign in to comment.