random colours and stf output
This commit is contained in:
parent
5e3dfb30c7
commit
bd16762319
16 changed files with 217 additions and 71 deletions
|
@ -2,6 +2,7 @@
|
||||||
#define ATTRACTOR_HPP
|
#define ATTRACTOR_HPP
|
||||||
|
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
|
#include "stfu/stf_ext.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -66,14 +67,12 @@ public:
|
||||||
LogMoreInfo("\n");
|
LogMoreInfo("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
stfu::node stf_output(){
|
stfu::node to_stf() const {
|
||||||
stfu::node kernel_node = kernel-> stf_output();
|
stfu::node node;
|
||||||
stfu::node projector_node;/* = projector->stf_output();*/
|
node.addChild("attractor_kernel") = stfu::to_stf(*kernel);
|
||||||
stfu::node system;
|
node.addChild("Projector"); /* = to_stf(*projector);*/
|
||||||
system.addChild("AttractorKernel", kernel_node);
|
node.addValue("Projector") = "Projector";
|
||||||
system.addChild("Projector", projector_node);
|
return node;
|
||||||
system.addValue("Projector") = "Projector";
|
|
||||||
return system;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
#define ATTRACTORKERNEL_HPP
|
#define ATTRACTORKERNEL_HPP
|
||||||
|
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
|
#include "stfu/stf_ext.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "stfu/stf.hpp"
|
|
||||||
|
|
||||||
class AttractorKernel {
|
class AttractorKernel {
|
||||||
public:
|
public:
|
||||||
virtual ~AttractorKernel() {
|
virtual ~AttractorKernel() {
|
||||||
|
@ -57,30 +56,24 @@ public:
|
||||||
// iterate his formula, implemented by subclasses
|
// iterate his formula, implemented by subclasses
|
||||||
virtual void operator()() = 0;
|
virtual void operator()() = 0;
|
||||||
|
|
||||||
stfu::node stf_output() {
|
stfu::node to_stf() const {
|
||||||
stfu::node output;
|
stfu::node output;
|
||||||
output.value("type") = type();
|
output.value("type") = type();
|
||||||
{
|
output.value("dimensions") = std::to_string(dimension);
|
||||||
std::stringstream dimStream;
|
stf_other(output);
|
||||||
dimStream << dimension;
|
|
||||||
output.value("dimensions") = dimStream.str();
|
|
||||||
stf_other(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
stfu::node parameters_node;
|
stfu::node parameters_node;
|
||||||
for(unsigned int i = 0; i < numberOfParameters; ++i){
|
for(unsigned int i = 0; i < numberOfParameters; ++i){
|
||||||
std::stringstream ss;
|
parameters_node.addValue() = std::to_string(parameters[i]);
|
||||||
ss << parameters[i];
|
|
||||||
parameters_node.value(i) = ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output.addChild("parameters", parameters_node);
|
output.addChild("parameters", parameters_node);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string type() = 0;
|
virtual std::string type() const = 0;
|
||||||
|
|
||||||
virtual void stf_other(stfu::node&) {}
|
virtual void stf_other(stfu::node&) const {}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark vector
|
#pragma mark vector
|
||||||
|
|
|
@ -63,6 +63,9 @@
|
||||||
427057A81475637B00CBE978 /* ImageFormatBMP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatBMP.hpp; sourceTree = "<group>"; };
|
427057A81475637B00CBE978 /* ImageFormatBMP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatBMP.hpp; sourceTree = "<group>"; };
|
||||||
427057A91475637B00CBE978 /* ImageFormatPNG.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatPNG.hpp; sourceTree = "<group>"; };
|
427057A91475637B00CBE978 /* ImageFormatPNG.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatPNG.hpp; sourceTree = "<group>"; };
|
||||||
427057AB1475637B00CBE978 /* Tonemapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tonemapper.hpp; sourceTree = "<group>"; };
|
427057AB1475637B00CBE978 /* Tonemapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tonemapper.hpp; sourceTree = "<group>"; };
|
||||||
|
42CEC38414AB797200C3AEDA /* Random.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Random.hpp; sourceTree = "<group>"; };
|
||||||
|
42CEC38614ABB85200C3AEDA /* stf_ext.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = stf_ext.hpp; path = stfu/stf_ext.hpp; sourceTree = "<group>"; };
|
||||||
|
42CEC38714ABC2C000C3AEDA /* UnravelHeart3D.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = UnravelHeart3D.hpp; path = kernels/UnravelHeart3D.hpp; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -82,6 +85,7 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
01C5703013B63B78009D151B /* stf.hpp */,
|
01C5703013B63B78009D151B /* stf.hpp */,
|
||||||
|
42CEC38614ABB85200C3AEDA /* stf_ext.hpp */,
|
||||||
01C5703113B63B78009D151B /* stf.cpp */,
|
01C5703113B63B78009D151B /* stf.cpp */,
|
||||||
);
|
);
|
||||||
name = stf;
|
name = stf;
|
||||||
|
@ -93,6 +97,7 @@
|
||||||
01C5700513B63AF0009D151B /* AttractorKernel.hpp */,
|
01C5700513B63AF0009D151B /* AttractorKernel.hpp */,
|
||||||
01C5700F13B63AF0009D151B /* AttractorKernel.cpp */,
|
01C5700F13B63AF0009D151B /* AttractorKernel.cpp */,
|
||||||
01C5703913B63BA3009D151B /* Unravel3D.hpp */,
|
01C5703913B63BA3009D151B /* Unravel3D.hpp */,
|
||||||
|
42CEC38714ABC2C000C3AEDA /* UnravelHeart3D.hpp */,
|
||||||
01C5703A13B63BA3009D151B /* PolynomialA3D.hpp */,
|
01C5703A13B63BA3009D151B /* PolynomialA3D.hpp */,
|
||||||
01C5703B13B63BA3009D151B /* Polynomial.hpp */,
|
01C5703B13B63BA3009D151B /* Polynomial.hpp */,
|
||||||
01C5703C13B63BA3009D151B /* Lorenz3D.hpp */,
|
01C5703C13B63BA3009D151B /* Lorenz3D.hpp */,
|
||||||
|
@ -121,6 +126,7 @@
|
||||||
427057A81475637B00CBE978 /* ImageFormatBMP.hpp */,
|
427057A81475637B00CBE978 /* ImageFormatBMP.hpp */,
|
||||||
427057A91475637B00CBE978 /* ImageFormatPNG.hpp */,
|
427057A91475637B00CBE978 /* ImageFormatPNG.hpp */,
|
||||||
427057AB1475637B00CBE978 /* Tonemapper.hpp */,
|
427057AB1475637B00CBE978 /* Tonemapper.hpp */,
|
||||||
|
42CEC38414AB797200C3AEDA /* Random.hpp */,
|
||||||
427057A5147562DB00CBE978 /* Projectors */,
|
427057A5147562DB00CBE978 /* Projectors */,
|
||||||
01C5709D13B63E3A009D151B /* Kernels */,
|
01C5709D13B63E3A009D151B /* Kernels */,
|
||||||
01C5709C13B63E2F009D151B /* stf */,
|
01C5709C13B63E2F009D151B /* stf */,
|
||||||
|
|
43
Random.hpp
Normal file
43
Random.hpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
//
|
||||||
|
// Random.hpp
|
||||||
|
// AwesomeAttract0r
|
||||||
|
//
|
||||||
|
// Created by Joshua Moerman on 12/28/11.
|
||||||
|
// Copyright (c) 2011 Vadovas. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef AwesomeAttract0r_Random_hpp
|
||||||
|
#define AwesomeAttract0r_Random_hpp
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// capital because random() was already defined :(
|
||||||
|
namespace Random {
|
||||||
|
// used as dummy paramter
|
||||||
|
struct parameters {};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
All uniform distributions are inclusive (ie [min, max]).
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_integral<T>::value, T>::type uniform(T min, T max){
|
||||||
|
return min + (rand() / (T) RAND_MAX) * (max - min);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename std::enable_if<std::is_arithmetic<T>::value && std::is_integral<T>::value, T>::type uniform(T min, T max){
|
||||||
|
return min + (rand() % (max - min + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::vector<T> make_vector(T min, T max, size_t number_of_elements){
|
||||||
|
std::vector<T> ret;
|
||||||
|
for (size_t i = 0; i < number_of_elements; ++i) {
|
||||||
|
ret.push_back(uniform(min, max));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
#endif
|
|
@ -14,6 +14,9 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include "stf_ext.hpp"
|
||||||
|
#include "Random.hpp"
|
||||||
|
|
||||||
namespace Tonemappers {
|
namespace Tonemappers {
|
||||||
|
|
||||||
struct Normalizer {
|
struct Normalizer {
|
||||||
|
@ -78,25 +81,15 @@ namespace Tonemappers {
|
||||||
struct Colorizer {
|
struct Colorizer {
|
||||||
Colorizer(size_t n_planes)
|
Colorizer(size_t n_planes)
|
||||||
: gamma_correctors(n_planes)
|
: gamma_correctors(n_planes)
|
||||||
, gammas()
|
, gammas({{std::vector<double>(n_planes, 2.0), std::vector<double>(n_planes, 2.0), std::vector<double>(n_planes, 2.0)}})
|
||||||
, colors()
|
, colors({{std::vector<double>(n_planes, 2.0), std::vector<double>(n_planes, 2.0), std::vector<double>(n_planes, 2.0)}})
|
||||||
{
|
{}
|
||||||
gammas[0].push_back(1.3);
|
|
||||||
gammas[1].push_back(2.0);
|
Colorizer(size_t n_planes, Random::parameters)
|
||||||
gammas[2].push_back(3.0);
|
: gamma_correctors(n_planes)
|
||||||
|
, gammas({{Random::make_vector(1.0, 3.0, n_planes), Random::make_vector(1.0, 3.0, n_planes), Random::make_vector(1.0, 3.0, n_planes)}})
|
||||||
gammas[0].push_back(3.0);
|
, colors({{Random::make_vector(-2.0, 4.0, n_planes), Random::make_vector(-2.0, 4.0, n_planes), Random::make_vector(-2.0, 4.0, n_planes)}})
|
||||||
gammas[1].push_back(1.0);
|
{}
|
||||||
gammas[2].push_back(1.0);
|
|
||||||
|
|
||||||
colors[0].push_back(1.5);
|
|
||||||
colors[1].push_back(2.0);
|
|
||||||
colors[2].push_back(1.0);
|
|
||||||
|
|
||||||
colors[0].push_back(-1.0);
|
|
||||||
colors[1].push_back(-0.5);
|
|
||||||
colors[2].push_back(0.7);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
void analyse(C const & canvas){
|
void analyse(C const & canvas){
|
||||||
|
@ -117,7 +110,6 @@ namespace Tonemappers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
double get_value(T const & n, size_t color) const {
|
double get_value(T const & n, size_t color) const {
|
||||||
double ret = 0.0;
|
double ret = 0.0;
|
||||||
|
@ -129,6 +121,17 @@ namespace Tonemappers {
|
||||||
else
|
else
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stfu::node to_stf() const {
|
||||||
|
stfu::node node;
|
||||||
|
node.addValue("class") = "colorizer";
|
||||||
|
node.addChild("gamma_matrix") = stfu::to_stf(gammas);
|
||||||
|
node.addChild("color_matrix") = stfu::to_stf(colors);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
std::vector<GammaCorrector> gamma_correctors;
|
std::vector<GammaCorrector> gamma_correctors;
|
||||||
std::array<std::vector<double>, 3> gammas;
|
std::array<std::vector<double>, 3> gammas;
|
||||||
std::array<std::vector<double>, 3> colors;
|
std::array<std::vector<double>, 3> colors;
|
||||||
|
|
|
@ -20,9 +20,9 @@ public:
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string type() { return "ikeda"; };
|
virtual std::string type() const { return "ikeda"; };
|
||||||
|
|
||||||
virtual void generate_random_parameters() {
|
virtual void generate_random_parameters() {
|
||||||
parameters[0] = rand() / double(RAND_MAX) *2.0 - 0.5;
|
parameters[0] = rand() / double(RAND_MAX) *2.0 - 0.5;
|
||||||
parameters[1] = rand() / double(RAND_MAX) *2.0 - 0.5; // wikipedia: u
|
parameters[1] = rand() / double(RAND_MAX) *2.0 - 0.5; // wikipedia: u
|
||||||
parameters[2] = rand() / double(RAND_MAX) *2.0 - 0.5;
|
parameters[2] = rand() / double(RAND_MAX) *2.0 - 0.5;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string type() { return "logistic"; };
|
virtual std::string type() const { return "logistic"; };
|
||||||
|
|
||||||
virtual void generate_random_parameters() {
|
virtual void generate_random_parameters() {
|
||||||
for(unsigned int i = 0; i < numberOfParameters; ++i) {
|
for(unsigned int i = 0; i < numberOfParameters; ++i) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ public:
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string type() { return "lorenz"; };
|
virtual std::string type() const { return "lorenz"; };
|
||||||
|
|
||||||
virtual void generate_random_parameters() {
|
virtual void generate_random_parameters() {
|
||||||
parameters[0] = rand() / double(RAND_MAX) * 0.02;
|
parameters[0] = rand() / double(RAND_MAX) * 0.02;
|
||||||
|
|
|
@ -38,7 +38,11 @@ public:
|
||||||
Polynomial(const unsigned int dimension, const unsigned int orde):
|
Polynomial(const unsigned int dimension, const unsigned int orde):
|
||||||
AttractorKernel(dimension, calculateNumberOfParameters(dimension, orde)), orde(orde) {}
|
AttractorKernel(dimension, calculateNumberOfParameters(dimension, orde)), orde(orde) {}
|
||||||
|
|
||||||
virtual std::string type() { return "polynomial"; };
|
virtual std::string type() const { return "polynomial"; };
|
||||||
|
|
||||||
|
virtual void stf_other(stfu::node & node) const {
|
||||||
|
node.addValue("orde") = std::to_string(orde);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void operator()() {
|
virtual void operator()() {
|
||||||
std::swap(vectorNew, vectorOld);
|
std::swap(vectorNew, vectorOld);
|
||||||
|
|
|
@ -8,7 +8,7 @@ public:
|
||||||
PolynomialA3D():
|
PolynomialA3D():
|
||||||
AttractorKernel(3, 3) {}
|
AttractorKernel(3, 3) {}
|
||||||
|
|
||||||
virtual std::string type() { return "polynomial a"; };
|
virtual std::string type() const { return "polynomial a"; };
|
||||||
|
|
||||||
virtual void operator()() {
|
virtual void operator()() {
|
||||||
std::swap(vectorNew, vectorOld);
|
std::swap(vectorNew, vectorOld);
|
||||||
|
|
|
@ -10,7 +10,7 @@ public:
|
||||||
Unravel3D():
|
Unravel3D():
|
||||||
AttractorKernel(3, 7) {}
|
AttractorKernel(3, 7) {}
|
||||||
|
|
||||||
virtual std::string type() { return "unravel"; };
|
virtual std::string type() const { return "unravel"; };
|
||||||
|
|
||||||
virtual void operator()() {
|
virtual void operator()() {
|
||||||
std::swap(vectorNew, vectorOld);
|
std::swap(vectorNew, vectorOld);
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
UnravelHeart3D():
|
UnravelHeart3D():
|
||||||
AttractorKernel(3, 8) {}
|
AttractorKernel(3, 8) {}
|
||||||
|
|
||||||
virtual std::string type() { return "unravel heart"; };
|
virtual std::string type() const { return "unravel heart"; };
|
||||||
|
|
||||||
virtual void operator()() {
|
virtual void operator()() {
|
||||||
std::swap(vectorNew, vectorOld);
|
std::swap(vectorNew, vectorOld);
|
||||||
|
|
27
main.cpp
27
main.cpp
|
@ -13,12 +13,16 @@
|
||||||
#include "Canvas.hpp"
|
#include "Canvas.hpp"
|
||||||
#include "Image.hpp"
|
#include "Image.hpp"
|
||||||
#include "Tonemapper.hpp"
|
#include "Tonemapper.hpp"
|
||||||
|
#include "Random.hpp"
|
||||||
|
|
||||||
|
#include "stf_ext.hpp"
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
int verbose = 4;
|
int verbose = 4;
|
||||||
|
|
||||||
|
|
||||||
std::string generate_filename(){
|
std::string generate_filename(){
|
||||||
char filename[64];
|
char filename[64];
|
||||||
time_t t = time(0);
|
time_t t = time(0);
|
||||||
|
@ -44,8 +48,9 @@ void render(Attractor & myAttractor, C & canvas, unsigned int iterations){
|
||||||
canvas.plot(blur, 1);
|
canvas.plot(blur, 1);
|
||||||
}
|
}
|
||||||
progress.show(j, iterations);
|
progress.show(j, iterations);
|
||||||
if(j == iterations/3) if(!filled(canvas, 0.01)) return;
|
if(j == iterations/4) if(!filled(canvas, 0.01)) return;
|
||||||
if(j == iterations/3 * 2) if(!filled(canvas, 0.02)) return;
|
if(j == iterations/4 * 2) if(!filled(canvas, 0.02)) return;
|
||||||
|
if(j == iterations/4 * 3) if(!filled(canvas, 0.03)) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +79,7 @@ int main(int argc, char* argv[]) try {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string filename = output_path + generate_filename();
|
std::string filename = output_path + generate_filename();
|
||||||
|
stfu::node output;
|
||||||
|
|
||||||
Logger logger(std::cout, LOG_VERBOSE);
|
Logger logger(std::cout, LOG_VERBOSE);
|
||||||
LayeredCanvas<Canvas2D<unsigned int> > canvas(width, height, 2);
|
LayeredCanvas<Canvas2D<unsigned int> > canvas(width, height, 2);
|
||||||
|
@ -86,24 +92,31 @@ int main(int argc, char* argv[]) try {
|
||||||
render(my_attractor, canvas, iterations);
|
render(my_attractor, canvas, iterations);
|
||||||
logger.stop();
|
logger.stop();
|
||||||
|
|
||||||
if(!filled(canvas, 0.05)){
|
if(!filled(canvas, 0.04)){
|
||||||
logger.log("The canvas is too empty. Stopping.");
|
logger.log("The canvas is too empty. Stopping.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string path(filename + ".stf");
|
output = stfu::to_stf(my_attractor);
|
||||||
std::ofstream file(path.c_str());
|
|
||||||
file << my_attractor.stf_output() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Tonemappers::Colorizer tonemapper(canvas.layers());
|
Tonemappers::Colorizer tonemapper(canvas.layers(), Random::parameters());
|
||||||
tonemapper.analyse(canvas);
|
tonemapper.analyse(canvas);
|
||||||
|
|
||||||
logger.start("saving image");
|
logger.start("saving image");
|
||||||
ImageFormats::png::png_stream image(canvas.size<0>(), canvas.size<1>(), filename + ".png");
|
ImageFormats::png::png_stream image(canvas.size<0>(), canvas.size<1>(), filename + ".png");
|
||||||
tonemapper.process(canvas, image);
|
tonemapper.process(canvas, image);
|
||||||
logger.stop();
|
logger.stop();
|
||||||
|
|
||||||
|
output.addChild("tonemapper") = stfu::to_stf(tonemapper);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
output.addValue("version") = __DATE__" "__TIME__;
|
||||||
|
output.addValue("notes") = "This is the version with `cheap` blur and random colours";
|
||||||
|
std::string path(filename + ".stf");
|
||||||
|
std::ofstream file(path.c_str());
|
||||||
|
file << output << std::endl;
|
||||||
}
|
}
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
std::cout << "Terminated because of: " << e.what() << std::endl;
|
std::cout << "Terminated because of: " << e.what() << std::endl;
|
||||||
|
|
|
@ -44,19 +44,11 @@ std::ostream& operator<< (std::ostream& out, const node& root) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<< (const char* filename, const node& root) {
|
|
||||||
return root.write(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::istream& operator>> (std::istream& in, node& root) {
|
std::istream& operator>> (std::istream& in, node& root) {
|
||||||
root.read(in);
|
root.read(in);
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>> (const char* filename, node& root) {
|
|
||||||
return root.read(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& node::getValue(const std::string& name, size_t index) const throw(std::out_of_range) {
|
const std::string& node::getValue(const std::string& name, size_t index) const throw(std::out_of_range) {
|
||||||
return get_indexed<std::string, std::string>(values, name, index);
|
return get_indexed<std::string, std::string>(values, name, index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,15 +56,9 @@ class node {
|
||||||
/** Overloaded ostream's operator<< */
|
/** Overloaded ostream's operator<< */
|
||||||
friend std::ostream& operator<< (std::ostream& out, const node& root);
|
friend std::ostream& operator<< (std::ostream& out, const node& root);
|
||||||
|
|
||||||
/** Acts like write(), but looks like this: "filename" << node */
|
|
||||||
friend bool operator<< (const char* filename, const node& root);
|
|
||||||
|
|
||||||
/** Overloaded istream's operator>> */
|
/** Overloaded istream's operator>> */
|
||||||
friend std::istream& operator>> (std::istream& in, node& root);
|
friend std::istream& operator>> (std::istream& in, node& root);
|
||||||
|
|
||||||
/** Acts like read(), but looks like this: "filename" >> node */
|
|
||||||
friend bool operator>> (const char* filename, node& root);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//@{
|
//@{
|
||||||
/** The values and children belonging to this node. To add, remove, do whatever: you CAN use these variables directly. To use indexing, use the member functions below*/
|
/** The values and children belonging to this node. To add, remove, do whatever: you CAN use these variables directly. To use indexing, use the member functions below*/
|
||||||
|
|
99
stfu/stf_ext.hpp
Normal file
99
stfu/stf_ext.hpp
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
//
|
||||||
|
// 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 <sstream>
|
||||||
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "stf.hpp"
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template <typename T>
|
||||||
|
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 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)
|
||||||
|
to_stf_container_proto(std::list)
|
||||||
|
|
||||||
|
#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)
|
||||||
|
to_stf_container(std::list)
|
||||||
|
|
||||||
|
#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
|
Reference in a new issue