// // stf_output.hpp // AwesomeAttract0r // // Created by Joshua Moerman on 1/2/12. // Copyright (c) 2012 Vadovas. All rights reserved. // #ifndef AwesomeAttract0r_stf_output_hpp #define AwesomeAttract0r_stf_output_hpp #include #include #include #include "stf.hpp" #include "std_string_ext.hpp" namespace stfu { // Prototypes #define to_stf_container_proto(x) \ template \ typename std::enable_if::value, node>::type to_stf(x const & array); \ template \ typename std::enable_if::value, node>::type to_stf(x const & array); to_stf_container_proto(std::vector) #undef to_stf_container_proto template typename std::enable_if::value, node>::type to_stf(std::array const & array); template typename std::enable_if::value, node>::type to_stf(std::array const & array); template node to_stf(T const & x); // implementations #define to_stf_container(x) \ template \ typename std::enable_if::value, node>::type to_stf(x const & array) { \ node node; \ for (auto it = array.cbegin(); it != array.cend(); ++it) \ node.addValue() = std::to_string(*it); \ return node; \ } \ \ template \ typename std::enable_if::value, node>::type to_stf(x const & array) { \ node node; \ for (auto it = array.cbegin(); it != array.cend(); ++it) \ node.addChild() = to_stf(*it); \ return node; \ } to_stf_container(std::vector) #undef to_stf_container template typename std::enable_if::value, node>::type to_stf(std::array const & array) { node node; for (auto it = array.cbegin(); it != array.cend(); ++it){ node.addValue() = std::to_string(*it); } return node; } template typename std::enable_if::value, node>::type to_stf(std::array const & array) { node node; for (auto it = array.cbegin(); it != array.cend(); ++it){ node.addChild() = to_stf(*it); } return node; } template node to_stf(T const & x){ return x.to_stf(); } } // namespace stfu #endif