// // stf_ext.hpp // AwesomeAttract0r // // Created by Joshua Moerman on 12/28/11. // Copyright (c) 2011 Vadovas. All rights reserved. // #ifndef AwesomeAttract0r_stf_ext_hpp #define AwesomeAttract0r_stf_ext_hpp #include #include #include #include #include "stf.hpp" namespace std { template std::string to_string(T const & x){ std::stringstream ss; ss << x; return ss.str(); } } 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) to_stf_container_proto(std::list) #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) to_stf_container(std::list) #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