From: Aina Niemetz Date: Wed, 14 Feb 2018 00:34:08 +0000 (-0800) Subject: Provide a uniform way to serialize node containers to output stream. (#1604) X-Git-Tag: cvc5-1.0.0~5287 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78495d12a4b5b0fc6f5f8e841af665ae49392af1;p=cvc5.git Provide a uniform way to serialize node containers to output stream. (#1604) --- diff --git a/src/expr/node.h b/src/expr/node.h index 92f905c8b..84278ff8a 100644 --- a/src/expr/node.h +++ b/src/expr/node.h @@ -2,9 +2,9 @@ /*! \file node.h ** \verbatim ** Top contributors (to current version): - ** Morgan Deters, Dejan Jovanovic, Tim King + ** Morgan Deters, Dejan Jovanovic, Aina Niemetz ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS + ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS ** in the top-level source directory) and their institutional affiliations. ** All rights reserved. See the file COPYING in the top-level source ** directory for licensing information.\endverbatim @@ -923,24 +923,100 @@ inline std::ostream& operator<<(std::ostream& out, TNode n) { return out; } +namespace { + +template +void nodeContainerToOut(std::ostream& out, const T& container) +{ + out << "["; + bool is_first = true; + for (const auto& item : container) + { + out << (!is_first ? ", " : "") << item; + is_first = false; + } + out << "]"; +} + +} + /** - * Serializes a vector of node to the given stream. + * Serialize a vector of nodes to given stream. * * @param out the output stream to use - * @param ns the vector of nodes to output to the stream + * @param container the vector of nodes to output to the stream * @return the stream */ -template -inline std::ostream& operator<<(std::ostream& out, - const std::vector< NodeTemplate > & ns) { - for(typename std::vector< NodeTemplate >::const_iterator - i=ns.begin(), end=ns.end(); - i != end; ++i){ - out << *i; - } +template +std::ostream& operator<<(std::ostream& out, + const std::vector>& container) +{ + nodeContainerToOut(out, container); + return out; +} + +/** + * Serialize a set of nodes to the given stream. + * + * @param out the output stream to use + * @param container the set of nodes to output to the stream + * @return the stream + */ +template +std::ostream& operator<<(std::ostream& out, + const std::set>& container) +{ + nodeContainerToOut(out, container); + return out; +} + +/** + * Serialize an unordered_set of nodes to the given stream. + * + * @param out the output stream to use + * @param container the unordered_set of nodes to output to the stream + * @return the stream + */ +template +std::ostream& operator<<( + std::ostream& out, + const std::unordered_set, hash_function>& container) +{ + nodeContainerToOut(out, container); return out; } +/** + * Serialize a map of nodes to the given stream. + * + * @param out the output stream to use + * @param container the map of nodes to output to the stream + * @return the stream + */ +template +std::ostream& operator<<( + std::ostream& out, + const std::map, V>& container) +{ + nodeContainerToOut(out, container); + return out; +} + +/** + * Serialize an unordered_map of nodes to the given stream. + * + * @param out the output stream to use + * @param container the unordered_map of nodes to output to the stream + * @return the stream + */ +template +std::ostream& operator<<( + std::ostream& out, + const std::unordered_map, V, HF>& container) +{ + nodeContainerToOut(out, container); + return out; +} }/* CVC4 namespace */