// // stf_input.hpp // AwesomeAttract0r // // Created by Joshua Moerman on 1/2/12. // Copyright (c) 2012 Vadovas. All rights reserved. // #ifndef AwesomeAttract0r_stf_input_hpp #define AwesomeAttract0r_stf_input_hpp #include #include #include #include "stf.hpp" #include "std_string_ext.hpp" namespace stfu { // prototypes template T from_stf(node const & n); // implemtations namespace { template struct from_stf_struct { T operator()(node const & n){ return T::from_stf(n); } }; template struct from_stf_struct, typename std::enable_if::value>::type>; template struct from_stf_struct, typename std::enable_if::value>::type>; template struct from_stf_struct, typename std::enable_if::value>::type>; template struct from_stf_struct, typename std::enable_if::value>::type>; template struct from_stf_struct, typename std::enable_if::value>::type>{ std::vector operator()(node const & n){ std::vector v; bool done = false; for(unsigned int i = 0; !done; ++i){ try { v.push_back(from_stf(n.getChild(i))); } catch (std::out_of_range& e) { done = true; } } return v; } }; template struct from_stf_struct, typename std::enable_if::value>::type>{ std::vector operator()(node const & n){ std::vector v; bool done = false; for(unsigned int i = 0; !done; ++i){ try { v.push_back(std::from_string(n.getValue(i))); } catch (std::out_of_range& e) { done = true; } } return v; } }; template struct from_stf_struct, typename std::enable_if::value>::type>{ std::array operator()(node const & n){ std::array v; for(unsigned int i = 0; i < N; ++i){ v[i] = from_stf(n.getChild(i)); } return v; } }; template struct from_stf_struct, typename std::enable_if::value>::type>{ std::array operator()(node const & n){ std::array v; for(unsigned int i = 0; i < N; ++i){ v[i] = std::from_string(n.getValue(i)); } return v; } }; } template T from_stf(node const & n){ return from_stf_struct()(n); } } // namespace stfu #endif