<commit_before>#pragma once

#include "defaults.hpp"
#include <fstream>
#include <iomanip>

namespace gftools {

/** num_io is a wrapper around another object (of type T). 
    num_io does input/output operations.
    such as streaming, saving to/loading from plaintext files.
    Internally it stores references to an instance of type T.
    Typical objects are: numbers, arrays of numbers, complex numbers, grid points*/
template <typename T> class num_io {
public:
    typedef typename std::remove_reference<T>::type type; 

    /// Construct from value
    num_io(type& v):value_(v){}

    /// Access the internally stored value
    type &operator()(){return value_;}
    /// Const access to the internally stored value
    const type &operator()() const{return value_;}
    /// Save the object to a file with a filename passed in as a name
    void savetxt(const std::string& filename) { 
        std::cout << "Saving " << typeid(*this).name() << " to " << filename << std::endl;
        std::ofstream out; out.open(filename.c_str()); out << *this << std::endl; out.close(); 
    }; 
    /// Read the object from a file with a filename passed in as a name
    void loadtxt(const std::string& filename) { 
        std::cout << "Loading " << typeid(*this).name() << " from " << filename << std::endl;
        std::ifstream out; out.open(filename.c_str()); if (out.fail()) throw (std::bad_exception()); out >> *this; out.close(); 
    }; 

    static constexpr int precision() { return prec_; }
    static constexpr double tolerance() { return tol_; }

private:
    /// Underlying value.
    type& value_;
    /// Output precision. TODO: replace c++-11 construct constexpr with something backwards compatible.
    static constexpr int prec_ = std::numeric_limits<double>::max_digits10;
    /// Comparison tolerance
    static constexpr double tol_ = 1e-10;
};<commit_msg>num_io : add helper value() method<commit_after>#pragma once

#include "defaults.hpp"
#include <fstream>
#include <iomanip>

namespace gftools {

/** num_io is a wrapper around another object (of type T). 
    num_io does input/output operations.
    such as streaming, saving to/loading from plaintext files.
    Internally it stores references to an instance of type T.
    Typical objects are: numbers, arrays of numbers, complex numbers, grid points*/
template <typename T> class num_io {
public:
    typedef typename std::remove_reference<T>::type type; 

    /// Construct from value
    num_io(type& v):value_(v){}

    /// Access the internally stored value
    type &operator()(){return value_;}
    /// Const access to the internally stored value
    const type &operator()() const{return value_;}
    /// Save the object to a file with a filename passed in as a name
    void savetxt(const std::string& filename) { 
        std::cout << "Saving " << typeid(*this).name() << " to " << filename << std::endl;
        std::ofstream out; out.open(filename.c_str()); out << *this << std::endl; out.close(); 
    }; 
    /// Read the object from a file with a filename passed in as a name
    void loadtxt(const std::string& filename) { 
        std::cout << "Loading " << typeid(*this).name() << " from " << filename << std::endl;
        std::ifstream out; out.open(filename.c_str()); if (out.fail()) throw (std::bad_exception()); out >> *this; out.close(); 
    }; 

    type& value() { return value_; } // TODO : test using it
    type const& value() const { return value_; } // TODO : test using it
    static constexpr int precision() { return prec_; }
    static constexpr double tolerance() { return tol_; }

private:
    /// Underlying value.
    type& value_;
    /// Output precision. TODO: replace c++-11 construct constexpr with something backwards compatible.
    static constexpr int prec_ = std::numeric_limits<double>::max_digits10;
    /// Comparison tolerance
    static constexpr double tol_ = 1e-10;
};
{'fraction_non_alphanumeric': 0.12996667521148422, 'fraction_numerical': 0.0035888233786208665, 'mean_word_length': 3.3452115812917596, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6567839', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1072, 'n_words': 408}