Skip to content

Commit

Permalink
Remove awkward operator<< overload, use operator() instead (#2427)
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes authored Sep 25, 2024
1 parent 33f35be commit abe3f99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ class AstDOTStyleVisitor: public NodeVisitor<void, std::ostream&>
*/
std::string name() const override;

/**
* @brief Outputs the DOT representation of a node to a stream.
*
* This operator overload facilitates the use of the `AstDOTStyleVisitor` with a node
* for direct streaming of the DOT representation.
*
* @param os The output stream to which the DOT representation is written.
* @param root The root of the expression to be output.
*/
void operator()(std::ostream& os, Nodes::Node* root);

private:
void visit(const Nodes::SumNode* node, std::ostream& os) override;
void visit(const Nodes::SubtractionNode* node, std::ostream& os) override;
Expand Down Expand Up @@ -179,18 +190,4 @@ class AstDOTStyleVisitor: public NodeVisitor<void, std::ostream&>
*/
unsigned int nodeCount_ = 0;
};

/**
* @brief Outputs the DOT representation of a node to a stream.
*
* This operator overload facilitates the use of the `AstDOTStyleVisitor` with a node
* for direct streaming of the DOT representation.
*
* @param os The output stream to which the DOT representation is written.
* @param visitorExpr A pair consisting of the visitor and the node to be output.
* @return The output stream.
*/
std::ostream& operator<<(std::ostream& os,
const std::pair<AstDOTStyleVisitor&, Nodes::Node*>& visitorExpr);

} // namespace Antares::Solver::Visitors
11 changes: 4 additions & 7 deletions src/solver/expressions/visitors/AstDOTStyleVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,10 @@ void AstDOTStyleVisitor::EndTreeGraph(std::ostream& os)
nodeIds_.clear();
}

std::ostream& operator<<(std::ostream& os,
const std::pair<AstDOTStyleVisitor&, Nodes::Node*>& visitorExpr)
void AstDOTStyleVisitor::operator()(std::ostream& os, Nodes::Node* root)
{
auto& [visitor, root] = visitorExpr;
visitor.NewTreeGraph(os);
visitor.dispatch(root, os);
visitor.EndTreeGraph(os);
return os;
NewTreeGraph(os);
dispatch(root, os);
EndTreeGraph(os);
}
} // namespace Antares::Solver::Visitors
4 changes: 1 addition & 3 deletions src/tests/src/solver/expressions/test_AstDOTStyleVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ BOOST_FIXTURE_TEST_CASE(tree_with_all_type_node, Fixture)
std::ostringstream os;

AstDOTStyleVisitor astGraphVisitor;

std::pair<AstDOTStyleVisitor&, Node*> pair1(astGraphVisitor, makeExpression());
os << pair1;
astGraphVisitor(os, makeExpression());

// read the content of os
BOOST_CHECK_EQUAL(expectedDotContent(), os.str());
Expand Down

0 comments on commit abe3f99

Please sign in to comment.