int fputs (const char *s, FILE *stream) { if (stream == (FILE*)stdout) return stream_puts (to_stream (stdout), s); else if (stream == (FILE*)stderr) return stream_puts (to_stream (stderr), s); return 0; }
void to_stream( T& os, const variant& v, json::output_formatting format ) { switch( v.get_type() ) { case variant::null_type: os << "null"; return; case variant::int64_type: { int64_t i = v.as_int64(); if( format == json::stringify_large_ints_and_doubles && i > 0xffffffff ) os << '"'<<v.as_string()<<'"'; else os << i; return; } case variant::uint64_type: { uint64_t i = v.as_uint64(); if( format == json::stringify_large_ints_and_doubles && i > 0xffffffff ) os << '"'<<v.as_string()<<'"'; else os << i; return; } case variant::double_type: if (format == json::stringify_large_ints_and_doubles) os << '"'<<v.as_string()<<'"'; else os << v.as_string(); return; case variant::bool_type: os << v.as_string(); return; case variant::string_type: escape_string( v.get_string(), os ); return; case variant::blob_type: escape_string( v.as_string(), os ); return; case variant::array_type: { const variants& a = v.get_array(); to_stream( os, a, format ); return; } case variant::object_type: { const variant_object& o = v.get_object(); to_stream(os, o, format ); return; } } }
void to_stream( T& os, const variant& v, json::output_formatting format, uint32_t max_depth ) { FC_ASSERT( max_depth > 0, "Too many nested objects!" ); switch( v.get_type() ) { case variant::null_type: os << "null"; return; case variant::int64_type: if( format == json::stringify_large_ints_and_doubles && ( v.as_int64() > INT32_MAX || v.as_int64() < INT32_MIN ) ) os << '"'<<v.as_string()<<'"'; else os << v.as_int64(); return; case variant::uint64_type: if( format == json::stringify_large_ints_and_doubles && v.as_uint64() > 0xffffffff ) os << '"'<<v.as_string()<<'"'; else os << v.as_uint64(); return; case variant::double_type: if (format == json::stringify_large_ints_and_doubles) os << '"'<<v.as_string()<<'"'; else os << v.as_string(); return; case variant::bool_type: os << v.as_string(); return; case variant::string_type: escape_string( v.get_string(), os ); return; case variant::blob_type: escape_string( v.as_string(), os ); return; case variant::array_type: to_stream( os, v.get_array(), format, max_depth - 1 ); return; case variant::object_type: to_stream(os, v.get_object(), format, max_depth - 1 ); return; default: FC_THROW_EXCEPTION( fc::invalid_arg_exception, "Unsupported variant type: ${type}", ( "type", v.get_type() ) ); } }
void BTree<Key, Value>::to_stream(std::ostream&stream, const typename BTree<Key, Value>::Node::Ptr& root)const { stream << "{ ["; for (auto v : root->vals) { stream << " " << v.first; } stream << "], "; for (auto c : root->childs) { to_stream(stream, getNode(c)); } stream << "}" << std::endl; }
void to_stream( T& os, const variants& a, json::output_formatting format, uint32_t max_depth ) { os << '['; auto itr = a.begin(); while( itr != a.end() ) { to_stream( os, *itr, format, max_depth ); ++itr; if( itr != a.end() ) os << ','; } os << ']'; }
inline std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) { os << "["; bool emit = false; for(auto& i : v) { if (emit) { os << ", "; } else { emit = true; } to_stream(os, i, 0, 0); } os << "]"; return os; }
void to_stream( T& os, const variant_object& o, json::output_formatting format, uint32_t max_depth ) { os << '{'; auto itr = o.begin(); while( itr != o.end() ) { escape_string( itr->key(), os ); os << ':'; to_stream( os, itr->value(), format, max_depth ); ++itr; if( itr != o.end() ) os << ','; } os << '}'; }
std::ostream& to_stream( std::ostream& str, const prop_node& pn, int depth, int align ) { if ( align == 0 ) align = get_align_width( pn, depth ); for ( auto& child : pn ) { string key_str( depth * 2, ' ' ); key_str += child.first; str << std::left << std::setw( align ) << key_str; if ( child.second.has_value() || child.second.size() == 0 ) str << std::setw( 0 ) << " = " << child.second.get_value(); str << std::endl; to_stream( str, child.second, depth + 1, align ); } return str; }
void BTree<Key, Value>::to_stream(std::ostream&stream)const { to_stream(stream, m_root); }
// Prefer the above function over this one std::string _str() const { std::ostringstream os; to_stream(os); return os.str(); }
size_t write (int fd, const void *buf, size_t count){ FILE* f = fdopen(fd, 0); if (f == 0) return 0; return stream_write(to_stream((stream_t*)f), buf, count); //fclose(f); }