本文整理汇总了C++中output_data类的典型用法代码示例。如果您正苦于以下问题:C++ output_data类的具体用法?C++ output_data怎么用?C++ output_data使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了output_data类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: format_json_uniform_dim
static void format_json_uniform_dim(output_data& out, const ndt::type& dt, const char *metadata, const char *data)
{
out.write('[');
switch (dt.get_type_id()) {
case strided_dim_type_id: {
const strided_dim_type *sad = static_cast<const strided_dim_type *>(dt.extended());
const strided_dim_type_metadata *md = reinterpret_cast<const strided_dim_type_metadata *>(metadata);
ndt::type element_tp = sad->get_element_type();
intptr_t size = md->size, stride = md->stride;
metadata += sizeof(strided_dim_type_metadata);
for (intptr_t i = 0; i < size; ++i) {
::format_json(out, element_tp, metadata, data + i * stride);
if (i != size - 1) {
out.write(',');
}
}
break;
}
case fixed_dim_type_id: {
const fixed_dim_type *fad = static_cast<const fixed_dim_type *>(dt.extended());
ndt::type element_tp = fad->get_element_type();
intptr_t size = (intptr_t)fad->get_fixed_dim_size(), stride = fad->get_fixed_stride();
for (intptr_t i = 0; i < size; ++i) {
::format_json(out, element_tp, metadata, data + i * stride);
if (i != size - 1) {
out.write(',');
}
}
break;
}
case var_dim_type_id: {
const var_dim_type *vad = static_cast<const var_dim_type *>(dt.extended());
const var_dim_type_metadata *md = reinterpret_cast<const var_dim_type_metadata *>(metadata);
const var_dim_type_data *d = reinterpret_cast<const var_dim_type_data *>(data);
ndt::type element_tp = vad->get_element_type();
intptr_t size = d->size, stride = md->stride;
const char *begin = d->begin + md->offset;
metadata += sizeof(var_dim_type_metadata);
for (intptr_t i = 0; i < size; ++i) {
::format_json(out, element_tp, metadata, begin + i * stride);
if (i != size - 1) {
out.write(',');
}
}
break;
}
default: {
stringstream ss;
ss << "Formatting dynd type " << dt << " as JSON is not implemented yet";
throw runtime_error(ss.str());
}
}
out.write(']');
}
开发者ID:garaud,项目名称:libdynd,代码行数:54,代码来源:json_formatter.cpp
示例2: format_json_bool
static void format_json_bool(output_data &out, const ndt::type &dt, const char *arrmeta, const char *data)
{
bool1 value(false);
if (dt.get_type_id() == bool_type_id) {
value = (*data != 0);
} else {
typed_data_assign(ndt::type::make<bool1>(), NULL, reinterpret_cast<char *>(&value), dt, arrmeta, data);
}
if (value) {
out.write("true");
} else {
out.write("false");
}
}
开发者ID:melodylail,项目名称:libdynd,代码行数:14,代码来源:json_formatter.cpp
示例3: format_json_encoded_string
static void format_json_encoded_string(output_data &out, const char *begin, const char *end, string_encoding_t encoding)
{
uint32_t cp;
next_unicode_codepoint_t next_fn;
append_unicode_codepoint_t append_fn;
next_fn = get_next_unicode_codepoint_function(encoding, assign_error_nocheck);
append_fn = get_append_unicode_codepoint_function(string_encoding_utf_8, assign_error_nocheck);
out.write('\"');
while (begin < end) {
cp = next_fn(begin, end);
print_escaped_unicode_codepoint(out, cp, append_fn);
}
out.write('\"');
}
开发者ID:melodylail,项目名称:libdynd,代码行数:14,代码来源:json_formatter.cpp
示例4: format_json_number
static void format_json_number(output_data &out, const ndt::type &dt,
const char *arrmeta, const char *data)
{
stringstream ss;
dt.print_data(ss, arrmeta, data);
out.write(ss.str());
}
开发者ID:aterrel,项目名称:libdynd,代码行数:7,代码来源:json_formatter.cpp
示例5: format_json_struct
static void format_json_struct(output_data &out, const ndt::type &dt, const char *arrmeta, const char *data)
{
const ndt::base_struct_type *bsd = dt.extended<ndt::base_struct_type>();
intptr_t field_count = bsd->get_field_count();
const size_t *data_offsets = bsd->get_data_offsets(arrmeta);
const size_t *arrmeta_offsets = bsd->get_arrmeta_offsets_raw();
if (out.struct_as_list) {
out.write('[');
for (intptr_t i = 0; i < field_count; ++i) {
::format_json(out, bsd->get_field_type(i), arrmeta + arrmeta_offsets[i], data + data_offsets[i]);
if (i != field_count - 1) {
out.write(',');
}
}
out.write(']');
} else {
out.write('{');
for (intptr_t i = 0; i < field_count; ++i) {
const dynd::string &fname = bsd->get_field_name_raw(i);
format_json_encoded_string(out, fname.begin(), fname.end(), string_encoding_utf_8);
out.write(':');
::format_json(out, bsd->get_field_type(i), arrmeta + arrmeta_offsets[i], data + data_offsets[i]);
if (i != field_count - 1) {
out.write(',');
}
}
out.write('}');
}
}
开发者ID:melodylail,项目名称:libdynd,代码行数:30,代码来源:json_formatter.cpp
示例6: format_json_option
static void format_json_option(output_data &out, const ndt::type &dt, const char *arrmeta, const char *data)
{
const ndt::option_type *ot = dt.extended<ndt::option_type>();
if (ot->is_avail(arrmeta, data, &eval::default_eval_context)) {
format_json(out, ot->get_value_type(), arrmeta, data);
} else {
out.write("null");
}
}
开发者ID:melodylail,项目名称:libdynd,代码行数:9,代码来源:json_formatter.cpp
示例7: format_json_struct
static void format_json_struct(output_data& out, const ndt::type& dt, const char *metadata, const char *data)
{
const base_struct_type *bsd = static_cast<const base_struct_type *>(dt.extended());
size_t field_count = bsd->get_field_count();
const string *field_names = bsd->get_field_names();
const ndt::type *field_types = bsd->get_field_types();
const size_t *data_offsets = bsd->get_data_offsets(metadata);
const size_t *metadata_offsets = bsd->get_metadata_offsets();
out.write('{');
for (size_t i = 0; i < field_count; ++i) {
const string& fname = field_names[i];
format_json_encoded_string(out, fname.data(), fname.data() + fname.size(), string_encoding_utf_8);
out.write(':');
::format_json(out, field_types[i], metadata + metadata_offsets[i], data + data_offsets[i]);
if (i != field_count - 1) {
out.write(',');
}
}
out.write('}');
}
开发者ID:garaud,项目名称:libdynd,代码行数:21,代码来源:json_formatter.cpp
示例8: format_json_string
static void format_json_string(output_data& out, const ndt::type& dt, const char *metadata, const char *data)
{
if (dt.get_type_id() == json_type_id) {
// Copy the JSON data directly
const json_type_data *d = reinterpret_cast<const json_type_data *>(data);
out.write(d->begin, d->end);
} else {
const base_string_type *bsd = static_cast<const base_string_type *>(dt.extended());
string_encoding_t encoding = bsd->get_encoding();
const char *begin = NULL, *end = NULL;
bsd->get_string_range(&begin, &end, metadata, data);
format_json_encoded_string(out, begin, end, encoding);
}
}
开发者ID:garaud,项目名称:libdynd,代码行数:14,代码来源:json_formatter.cpp
示例9: format_json_dynamic
static void format_json_dynamic(output_data &out, const ndt::type &dt,
const char *DYND_UNUSED(arrmeta),
const char *data)
{
if (dt.get_type_id() == json_type_id) {
// Copy the JSON data directly
const json_type_data *d = reinterpret_cast<const json_type_data *>(data);
out.write(d->begin, d->end);
} else {
stringstream ss;
ss << "Formatting dynd type " << dt << " as JSON is not implemented yet";
throw runtime_error(ss.str());
}
}
开发者ID:aterrel,项目名称:libdynd,代码行数:14,代码来源:json_formatter.cpp
示例10: print_escaped_unicode_codepoint
static void print_escaped_unicode_codepoint(output_data &out, uint32_t cp, append_unicode_codepoint_t append_fn)
{
if (cp < 0x80) {
switch (cp) {
case '\b':
out.write("\\b");
break;
case '\f':
out.write("\\f");
break;
case '\n':
out.write("\\n");
break;
case '\r':
out.write("\\r");
break;
case '\t':
out.write("\\t");
break;
case '\\':
out.write("\\\\");
break;
case '/':
out.write("\\/");
break;
case '\"':
out.write("\\\"");
break;
default:
if (cp < 0x20 || cp == 0x7f) {
stringstream ss;
ss << "\\u";
hexadecimal_print(ss, static_cast<uint16_t>(cp));
out.write(ss.str());
} else {
out.write(static_cast<char>(cp));
}
break;
}
} else {
out.ensure_capacity(16);
append_fn(cp, out.out_end, out.out_capacity_end);
}
// TODO: Could have an ASCII output mode where unicode is always escaped
/*
else if (cp < 0x10000) {
stringstream ss;
ss << "\\u";
hexadecimal_print(ss, static_cast<uint16_t>(cp));
out.write(ss.str());
} else {
stringstream ss;
ss << "\\U";
hexadecimal_print(ss, static_cast<uint32_t>(cp));
out.write(ss.str());
}
*/
}
开发者ID:melodylail,项目名称:libdynd,代码行数:58,代码来源:json_formatter.cpp
注:本文中的output_data类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论