Function operator<<

Summary

#include <toml/comments.hpp>

(1) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const preserve_comments &com)

(2) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const discard_comments &)

#include <toml/datetime.hpp>

(3) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const local_date &date)

(4) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const local_time &time)

(5) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const time_offset &offset)

(6) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const local_datetime &dt)

(7) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const offset_datetime &dt)

#include <toml/serializer.hpp>

(8) template <typename charT, typename traits, typename C, template< typename ... > class M, template< typename ... > class V>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const basic_value< C, M, V > &v)

#include <toml/string.hpp>

(9) template <typename charT, typename traits>
    std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const string &s)

#include <toml/types.hpp>

(10) template <typename charT, typename traits>
     std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, value_t t)

Function overload

Synopsis

#include <toml/comments.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const preserve_comments &com)

Description

No description yet.

Source

Lines 259-268 in toml/comments.hpp. Line 253 in toml/comments.hpp.

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const preserve_comments& com)
{
    for(const auto& c : com)
    {
        os << '#' << c << '\n';
    }
    return os;
}

Synopsis

#include <toml/comments.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const discard_comments &)

Description

No description yet.

Source

Lines 462-469 in toml/comments.hpp.

inline void swap(const discard_comments&, const discard_comments&) noexcept {return;}

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const discard_comments&)
{
    return os;
}

Synopsis

#include <toml/datetime.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const local_date &date)

Description

No description yet.

Source

Lines 172-180 in toml/datetime.hpp. Line 167 in toml/datetime.hpp.

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const local_date& date)
{
    os << std::setfill('0') << std::setw(4) << static_cast<int>(date.year )     << '-';
    os << std::setfill('0') << std::setw(2) << static_cast<int>(date.month) + 1 << '-';
    os << std::setfill('0') << std::setw(2) << static_cast<int>(date.day  )    ;
    return os;
}

Synopsis

#include <toml/datetime.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const local_time &time)

Description

No description yet.

Source

Lines 275-296 in toml/datetime.hpp. Line 270 in toml/datetime.hpp.

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const local_time& time)
{
    os << std::setfill('0') << std::setw(2) << static_cast<int>(time.hour  ) << ':';
    os << std::setfill('0') << std::setw(2) << static_cast<int>(time.minute) << ':';
    os << std::setfill('0') << std::setw(2) << static_cast<int>(time.second);
    if(time.millisecond != 0 || time.microsecond != 0 || time.nanosecond != 0)
    {
        os << '.';
        os << std::setfill('0') << std::setw(3) << static_cast<int>(time.millisecond);
        if(time.microsecond != 0 || time.nanosecond != 0)
        {
            os << std::setfill('0') << std::setw(3) << static_cast<int>(time.microsecond);
            if(time.nanosecond != 0)
            {
                os << std::setfill('0') << std::setw(3) << static_cast<int>(time.nanosecond);
            }
        }
    }
    return os;
}

Synopsis

#include <toml/datetime.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const time_offset &offset)

Description

No description yet.

Source

Lines 349-363 in toml/datetime.hpp. Line 344 in toml/datetime.hpp.

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const time_offset& offset)
{
    if(offset.hour == 0 && offset.minute == 0)
    {
        os << 'Z';
        return os;
    }
    int minute = static_cast<int>(offset.hour) * 60 + offset.minute;
    if(minute < 0){os << '-'; minute = std::abs(minute);} else {os << '+';}
    os << std::setfill('0') << std::setw(2) << minute / 60 << ':';
    os << std::setfill('0') << std::setw(2) << minute % 60;
    return os;
}

Synopsis

#include <toml/datetime.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const local_datetime &dt)

Description

No description yet.

Source

Lines 471-477 in toml/datetime.hpp. Line 466 in toml/datetime.hpp.

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const local_datetime& dt)
{
    os << dt.date << 'T' << dt.time;
    return os;
}

Synopsis

#include <toml/datetime.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const offset_datetime &dt)

Description

No description yet.

Source

Lines 622-628 in toml/datetime.hpp. Line 617 in toml/datetime.hpp.

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const offset_datetime& dt)
{
    os << dt.date << 'T' << dt.time << dt.offset;
    return os;
}

Synopsis

#include <toml/serializer.hpp>

template <typename charT, typename traits, typename C, template< typename ... > class M, template< typename ... > class V>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const basic_value< C, M, V > &v)

Description

No description yet.

Source

Lines 802-850 in toml/serializer.hpp. Line 795 in toml/serializer.hpp.

template<typename charT, typename traits, typename C,
         template<typename ...> class M, template<typename ...> class V>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const basic_value<C, M, V>& v)
{
    using value_type = basic_value<C, M, V>;

    // get status of std::setw().
    const auto w     = static_cast<std::size_t>(os.width());
    const int  fprec = static_cast<int>(os.precision());
    os.width(0);

    // by defualt, iword is initialized byl 0. And by default, toml11 outputs
    // comments. So `0` means showcomment. 1 means nocommnet.
    const bool no_comment = (1 == os.iword(detail::comment_index(os)));

    if(!no_comment && v.is_table() && !v.comments().empty())
    {
        os << v.comments();
        os << '\n'; // to split the file comment from the first element
    }
    // the root object can't be an inline table. so pass `false`.
    const auto serialized = visit(serializer<value_type>(w, fprec, no_comment, false), v);
    os << serialized;

    // if v is a non-table value, and has only one comment, then
    // put a comment just after a value. in the following way.
    //
    // ```toml
    // key = "value" # comment.
    // ```
    //
    // Since the top-level toml object is a table, one who want to put a
    // non-table toml value must use this in a following way.
    //
    // ```cpp
    // toml::value v;
    // std::cout << "user-defined-key = " << v << std::endl;
    // ```
    //
    // In this case, it is impossible to put comments before key-value pair.
    // The only way to preserve comments is to put all of them after a value.
    if(!no_comment && !v.is_table() && !v.comments().empty())
    {
        os << " #";
        for(const auto& c : v.comments()) {os << c;}
    }
    return os;
}

Synopsis

#include <toml/string.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const string &s)

Description

No description yet.

Source

Lines 147-221 in toml/string.hpp.

inline bool
operator>=(const char* lhs, const string& rhs) {return std::string(lhs) >= rhs.str;}

template<typename charT, typename traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const string& s)
{
    if(s.kind == string_t::basic)
    {
        if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend())
        {
            // it contains newline. make it multiline string.
            os << "\"\"\"\n";
            for(auto i=s.str.cbegin(), e=s.str.cend(); i!=e; ++i)
            {
                switch(*i)
                {
                    case '\\': {os << "\\\\"; break;}
                    case '\"': {os << "\\\""; break;}
                    case '\b': {os << "\\b";  break;}
                    case '\t': {os << "\\t";  break;}
                    case '\f': {os << "\\f";  break;}
                    case '\n': {os << '\n';   break;}
                    case '\r':
                    {
                        // since it is a multiline string,
                        // CRLF is not needed to be escaped.
                        if(std::next(i) != e && *std::next(i) == '\n')
                        {
                            os << "\r\n";
                            ++i;
                        }
                        else
                        {
                            os << "\\r";
                        }
                        break;
                    }
                    default: {os << *i; break;}
                }
            }
            os << "\\\n\"\"\"";
            return os;
        }
        // no newline. make it inline.
        os << "\"";
        for(const auto c : s.str)
        {
            switch(c)
            {
                case '\\': {os << "\\\\"; break;}
                case '\"': {os << "\\\""; break;}
                case '\b': {os << "\\b";  break;}
                case '\t': {os << "\\t";  break;}
                case '\f': {os << "\\f";  break;}
                case '\n': {os << "\\n";  break;}
                case '\r': {os << "\\r";  break;}
                default  : {os << c;      break;}
            }
        }
        os << "\"";
        return os;
    }
    // the string `s` is literal-string.
    if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend() ||
       std::find(s.str.cbegin(), s.str.cend(), '\'') != s.str.cend() )
    {
        // contains newline or single quote. make it multiline.
        os << "'''\n" << s.str << "'''";
        return os;
    }
    // normal literal string
    os << '\'' << s.str << '\'';
    return os;
}

Synopsis

#include <toml/types.hpp>

template <typename charT, typename traits>
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, value_t t)

Description

No description yet.

Source

Lines 78-97 in toml/types.hpp. Line 1 in toml/types.hpp.

template<typename charT, typename traits>
inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, value_t t)
{
    switch(t)
    {
        case value_t::boolean         : os << "boolean";         return os;
        case value_t::integer         : os << "integer";         return os;
        case value_t::floating        : os << "floating";        return os;
        case value_t::string          : os << "string";          return os;
        case value_t::offset_datetime : os << "offset_datetime"; return os;
        case value_t::local_datetime  : os << "local_datetime";  return os;
        case value_t::local_date      : os << "local_date";      return os;
        case value_t::local_time      : os << "local_time";      return os;
        case value_t::array           : os << "array";           return os;
        case value_t::table           : os << "table";           return os;
        case value_t::empty           : os << "empty";           return os;
        default                       : os << "unknown";         return os;
    }
}





Add Discussion as Guest

Log in