My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

85 lines
2.3 KiB

//
// 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 <sstream>
#include <vector>
#include <array>
#include "stf.hpp"
#include "std_string_ext.hpp"
namespace stfu {
// Prototypes
#define to_stf_container_proto(x) \
template <typename T> \
typename std::enable_if<std::is_fundamental<T>::value, node>::type to_stf(x<T> const & array); \
template <typename T> \
typename std::enable_if<!std::is_fundamental<T>::value, node>::type to_stf(x<T> const & array);
to_stf_container_proto(std::vector)
#undef to_stf_container_proto
template <typename T, size_t N>
typename std::enable_if<std::is_fundamental<T>::value, node>::type to_stf(std::array<T, N> const & array);
template <typename T, size_t N>
typename std::enable_if<!std::is_fundamental<T>::value, node>::type to_stf(std::array<T, N> const & array);
template <typename T>
node to_stf(T const & x);
// implementations
#define to_stf_container(x) \
template <typename T> \
typename std::enable_if<std::is_fundamental<T>::value, node>::type to_stf(x<T> const & array) { \
node node; \
for (auto it = array.cbegin(); it != array.cend(); ++it) \
node.addValue() = std::to_string(*it); \
return node; \
} \
\
template <typename T> \
typename std::enable_if<!std::is_fundamental<T>::value, node>::type to_stf(x<T> 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 T, size_t N>
typename std::enable_if<std::is_fundamental<T>::value, node>::type to_stf(std::array<T, N> const & array) {
node node;
for (auto it = array.cbegin(); it != array.cend(); ++it){
node.addValue() = std::to_string(*it);
}
return node;
}
template <typename T, size_t N>
typename std::enable_if<!std::is_fundamental<T>::value, node>::type to_stf(std::array<T, N> const & array) {
node node;
for (auto it = array.cbegin(); it != array.cend(); ++it){
node.addChild() = to_stf(*it);
}
return node;
}
template <typename T>
node to_stf(T const & x){
return x.to_stf();
}
} // namespace stfu
#endif