当前位置: 首页>>代码示例>>C++>>正文


C++ type::get_type_id方法代码示例

本文整理汇总了C++中ndt::type::get_type_id方法的典型用法代码示例。如果您正苦于以下问题:C++ type::get_type_id方法的具体用法?C++ type::get_type_id怎么用?C++ type::get_type_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ndt::type的用法示例。


在下文中一共展示了type::get_type_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse_dynd_builtin_json

static void parse_dynd_builtin_json(const ndt::type& tp, const char *DYND_UNUSED(metadata), char *out_data,
                const char *&begin, const char *end)
{
    const char *saved_begin = begin;
    const char *nbegin = NULL, *nend = NULL;
    string val;
    if (parse_json_number(begin, end, nbegin, nend)) {
        try {
            assign_utf8_string_to_builtin(tp.get_type_id(), out_data, nbegin, nend);
        } catch (const std::exception& e) {
            throw json_parse_error(skip_whitespace(saved_begin, begin), e.what(), tp);
        }
    } else if (parse_json_string(begin, end, val)) {
        try {
            assign_utf8_string_to_builtin(tp.get_type_id(), out_data, val.data(), val.data() + val.size());
        } catch (const std::exception& e) {
            throw json_parse_error(skip_whitespace(saved_begin, begin), e.what(), tp);
        }
    } else {
        throw json_parse_error(begin, "invalid input", tp);
    }
}
开发者ID:talumbau,项目名称:libdynd,代码行数:22,代码来源:json_parser.cpp

示例2: is_lossless_assignment

bool cfixed_dim_type::is_lossless_assignment(const ndt::type &dst_tp,
                                             const ndt::type &src_tp) const
{
  if (dst_tp.extended() == this) {
    if (src_tp.extended() == this) {
      return true;
    } else if (src_tp.get_type_id() == cfixed_dim_type_id) {
      return *dst_tp.extended() == *src_tp.extended();
    }
  }

  return false;
}
开发者ID:nevermindewe,项目名称:libdynd,代码行数:13,代码来源:cfixed_dim_type.cpp

示例3: make_expr_kernel

  size_t make_expr_kernel(void *ckb, intptr_t ckb_offset,
                          const ndt::type &dst_tp, const char *dst_arrmeta,
                          size_t src_count, const ndt::type *src_tp,
                          const char *const *src_arrmeta,
                          kernel_request_t kernreq,
                          const eval::eval_context *ectx) const
  {
    if (src_count != 1) {
      stringstream ss;
      ss << "date_strftime_kernel_generator requires 1 src operand, ";
      ss << "received " << src_count;
      throw runtime_error(ss.str());
    }
    bool require_elwise = dst_tp.get_type_id() != string_type_id ||
                          src_tp[0].get_type_id() != date_type_id;
    // If the types don't match the ones for this generator,
    // call the elementwise dimension handler to handle one dimension,
    // giving 'this' as the next kernel generator to call
    if (require_elwise) {
      return make_elwise_dimension_expr_kernel(
          ckb, ckb_offset, dst_tp, dst_arrmeta, src_count, src_tp, src_arrmeta,
          kernreq, ectx, this);
    }

    date_strftime_kernel_extra *e =
        reinterpret_cast<ckernel_builder<kernel_request_host> *>(ckb)
            ->alloc_ck<date_strftime_kernel_extra>(ckb_offset);
    switch (kernreq) {
    case kernel_request_single:
      e->base.function =
          reinterpret_cast<void *>(&date_strftime_kernel_extra::single_unary);
      break;
    case kernel_request_strided:
      e->base.function =
          reinterpret_cast<void *>(&date_strftime_kernel_extra::strided_unary);
      break;
    default: {
      stringstream ss;
      ss << "date_strftime_kernel_generator: unrecognized request "
         << (int)kernreq;
      throw runtime_error(ss.str());
    }
    }
    // The lifetime of kernels must be shorter than that of the kernel
    // generator,
    // so we can point at data in the kernel generator
    e->format_size = m_format.size();
    e->format = m_format.c_str();
    e->dst_arrmeta = reinterpret_cast<const string_type_arrmeta *>(dst_arrmeta);
    return ckb_offset;
  }
开发者ID:hainm,项目名称:libdynd,代码行数:51,代码来源:date_expr_kernels.cpp

示例4: make_strided_dim

ndt::type ndt::make_strided_dim(const ndt::type& element_tp)
{
    // Static instances of the types, which have a reference
    // count > 0 for the lifetime of the program. This static
    // construction is inside a function to ensure correct creation
    // order during startup.
    static static_strided_dims ssd;

    if (element_tp.is_builtin()) {
        return ssd.static_builtins_instance[element_tp.get_type_id()];
    } else {
        return ndt::type(new strided_dim_type(element_tp), false);
    }
}
开发者ID:nevermindewe,项目名称:libdynd,代码行数:14,代码来源:strided_dim_type.cpp

示例5: 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

示例6: 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

示例7: make_value_to_pointer_assignment_kernel

size_t dynd::make_value_to_pointer_assignment_kernel(void *ckb,
        intptr_t ckb_offset,
        const ndt::type &tp,
        kernel_request_t kernreq)
{
    if (tp.is_builtin()) {
        return make_builtin_value_to_pointer_assignment_kernel(
                   ckb, ckb_offset, tp.get_type_id(), kernreq);
    }

    stringstream ss;
    ss << "make_value_to_pointer_assignment_kernel: unrecognized type " << tp;
    throw runtime_error(ss.str());
}
开发者ID:mdboom,项目名称:libdynd,代码行数:14,代码来源:pointer_assignment_kernels.cpp

示例8: result

static nd::array view_concrete(const nd::array &arr, const ndt::type &tp)
{
  // Allocate a result array to attempt the view in it
  nd::array result(make_array_memory_block(tp.get_arrmeta_size()));
  // Copy the fields
  result.get_ndo()->data.ptr = arr.get_ndo()->data.ptr;
  if (arr.get_ndo()->data.ref == NULL) {
    // Embedded data, need reference to the array
    result.get_ndo()->data.ref = arr.get_memblock().release();
  } else {
    // Use the same data reference, avoid producing a chain
    result.get_ndo()->data.ref = arr.get_data_memblock().release();
  }
  result.get_ndo()->m_type = ndt::type(tp).release();
  result.get_ndo()->m_flags = arr.get_ndo()->m_flags;
  // First handle a special case of viewing outermost "var" as "fixed[#]"
  if (arr.get_type().get_type_id() == var_dim_type_id && tp.get_type_id() == fixed_dim_type_id) {
    const var_dim_type_arrmeta *in_am = reinterpret_cast<const var_dim_type_arrmeta *>(arr.get_arrmeta());
    const var_dim_type_data *in_dat = reinterpret_cast<const var_dim_type_data *>(arr.get_readonly_originptr());
    fixed_dim_type_arrmeta *out_am = reinterpret_cast<fixed_dim_type_arrmeta *>(result.get_arrmeta());
    out_am->dim_size = tp.extended<ndt::fixed_dim_type>()->get_fixed_dim_size();
    out_am->stride = in_am->stride;
    if ((intptr_t)in_dat->size == out_am->dim_size) {
      // Use the more specific data reference from the var arrmeta if possible
      if (in_am->blockref != NULL) {
        memory_block_decref(result.get_ndo()->data.ref);
        memory_block_incref(in_am->blockref);
        result.get_ndo()->data.ref = in_am->blockref;
      }
      result.get_ndo()->data.ptr = in_dat->begin + in_am->offset;
      // Try to copy the rest of the arrmeta as a view
      if (try_view(arr.get_type().extended<ndt::base_dim_type>()->get_element_type(),
                   arr.get_arrmeta() + sizeof(var_dim_type_arrmeta),
                   tp.extended<ndt::base_dim_type>()->get_element_type(),
                   result.get_arrmeta() + sizeof(fixed_dim_type_arrmeta), arr.get_memblock().get())) {
        return result;
      }
    }
  }
  // Otherwise try to copy the arrmeta as a view
  else if (try_view(arr.get_type(), arr.get_arrmeta(), tp, result.get_arrmeta(), arr.get_memblock().get())) {
    // If it succeeded, return it
    return result;
  }

  stringstream ss;
  ss << "Unable to view nd::array of type " << arr.get_type();
  ss << " as type " << tp;
  throw type_error(ss.str());
}
开发者ID:hainm,项目名称:libdynd,代码行数:50,代码来源:view.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: parse_number_json

static void parse_number_json(const ndt::type &tp, const char *arrmeta,
                              char *out_data, const char *&rbegin,
                              const char *end, bool option,
                              const eval::eval_context *ectx)
{
  const char *begin = rbegin;
  const char *nbegin, *nend;
  bool escaped = false;
  if (option && parse::parse_token_no_ws(begin, end, "null")) {
    ndt::option_type::make(tp).extended<ndt::option_type>()->assign_na(
        arrmeta, out_data, ectx);
  } else if (parse::parse_json_number_no_ws(begin, end, nbegin, nend)) {
    parse::string_to_number(out_data, tp.get_type_id(), nbegin, nend, false,
                            ectx->errmode);
  } else if (parse::parse_doublequote_string_no_ws(begin, end, nbegin, nend,
                                                   escaped)) {
    // Interpret the data inside the string as an int
    try {
      if (!escaped) {
        parse::string_to_number(out_data, tp.get_type_id(), nbegin, nend,
                                option, ectx->errmode);
      } else {
        string s;
        parse::unescape_string(nbegin, nend, s);
        parse::string_to_number(out_data, tp.get_type_id(), nbegin, nend,
                                option, ectx->errmode);
      }
    }
    catch (const std::exception &e) {
      throw json_parse_error(rbegin, e.what(), tp);
    }
  } else {
    throw json_parse_error(rbegin, "expected a number", tp);
  }
  rbegin = begin;
}
开发者ID:Laeeth,项目名称:libdynd,代码行数:36,代码来源:json_parser.cpp

示例11: is_lossless_assignment

bool datetime_type::is_lossless_assignment(const ndt::type& dst_tp, const ndt::type& src_tp) const
{
    if (dst_tp.extended() == this) {
        if (src_tp.extended() == this) {
            return true;
        } else if (src_tp.get_type_id() == date_type_id) {
            // There is only one possibility for the date type (TODO: timezones!)
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
开发者ID:pombredanne,项目名称:libdynd,代码行数:15,代码来源:datetime_type.cpp

示例12: is_lossless_assignment

bool fixedbytes_type::is_lossless_assignment(const ndt::type& dst_tp, const ndt::type& src_tp) const
{
    if (dst_tp.extended() == this) {
        if (src_tp.extended() == this) {
            return true;
        } else if (src_tp.get_type_id() == fixedbytes_type_id) {
            const fixedbytes_type *src_fs = static_cast<const fixedbytes_type*>(src_tp.extended());
            return get_data_size() == src_fs->get_data_size();
        } else {
            return false;
        }
    } else {
        return false;
    }
}
开发者ID:nevermindewe,项目名称:libdynd,代码行数:15,代码来源:fixedbytes_type.cpp

示例13: make_expr_kernel

    size_t make_expr_kernel(void *ckb, intptr_t ckb_offset,
                            const ndt::type &dst_tp, const char *dst_arrmeta,
                            size_t src_count, const ndt::type *src_tp,
                            const char *const *src_arrmeta,
                            kernel_request_t kernreq,
                            const eval::eval_context *ectx) const
    {
      if (src_count != 1) {
        stringstream ss;
        ss << "date_replace_kernel_generator requires 1 src operand, ";
        ss << "received " << src_count;
        throw runtime_error(ss.str());
      }
      bool require_elwise = dst_tp.get_type_id() != date_type_id ||
                            src_tp[0].get_type_id() != date_type_id;
      // If the types don't match the ones for this generator,
      // call the elementwise dimension handler to handle one dimension,
      // giving 'this' as the next kernel generator to call
      if (require_elwise) {
        return make_elwise_dimension_expr_kernel(
            ckb, ckb_offset, dst_tp, dst_arrmeta, src_count, src_tp,
            src_arrmeta, kernreq, ectx, this);
      }

      date_replace_kernel_extra *e =
          reinterpret_cast<ckernel_builder<kernel_request_host> *>(ckb)
              ->alloc_ck_leaf<date_replace_kernel_extra>(ckb_offset);
      switch (kernreq) {
      case kernel_request_single:
        e->base.set_function<expr_single_t>(
            &date_replace_kernel_extra::single_unary);
        break;
      case kernel_request_strided:
        e->base.set_function<expr_strided_t>(
            &date_replace_kernel_extra::strided_unary);
        break;
      default: {
        stringstream ss;
        ss << "date_replace_kernel_generator: unrecognized request "
           << (int)kernreq;
        throw runtime_error(ss.str());
      }
      }
      e->year = m_year;
      e->month = m_month;
      e->day = m_day;
      return ckb_offset;
    }
开发者ID:aterrel,项目名称:libdynd,代码行数:48,代码来源:date_expr_kernels.cpp

示例14: make_assignment_kernel

size_t date_type::make_assignment_kernel(
    ckernel_builder *out, size_t offset_out,
    const ndt::type& dst_tp, const char *dst_metadata,
    const ndt::type& src_tp, const char *src_metadata,
    kernel_request_t kernreq, assign_error_mode errmode,
    const eval::eval_context *ectx) const
{
    if (this == dst_tp.extended()) {
        if (src_tp.get_type_id() == date_type_id) {
            return make_pod_typed_data_assignment_kernel(out, offset_out,
                    get_data_size(), get_data_alignment(), kernreq);
        } else if (src_tp.get_kind() == string_kind) {
            // Assignment from strings
            return make_string_to_date_assignment_kernel(out, offset_out,
                    src_tp, src_metadata,
                    kernreq, errmode, ectx);
        } else if (src_tp.get_kind() == struct_kind) {
            // Convert to struct using the "struct" property
            return ::make_assignment_kernel(out, offset_out,
                                            ndt::make_property(dst_tp, "struct"), dst_metadata,
                                            src_tp, src_metadata,
                                            kernreq, errmode, ectx);
        } else if (!src_tp.is_builtin()) {
            return src_tp.extended()->make_assignment_kernel(out, offset_out,
                    dst_tp, dst_metadata,
                    src_tp, src_metadata,
                    kernreq, errmode, ectx);
        }
    } else {
        if (dst_tp.get_kind() == string_kind) {
            // Assignment to strings
            return make_date_to_string_assignment_kernel(out, offset_out,
                    dst_tp, dst_metadata,
                    kernreq, errmode, ectx);
        } else if (dst_tp.get_kind() == struct_kind) {
            // Convert to struct using the "struct" property
            return ::make_assignment_kernel(out, offset_out,
                                            dst_tp, dst_metadata,
                                            ndt::make_property(src_tp, "struct"), src_metadata,
                                            kernreq, errmode, ectx);
        }
        // TODO
    }

    stringstream ss;
    ss << "Cannot assign from " << src_tp << " to " << dst_tp;
    throw runtime_error(ss.str());
}
开发者ID:pombredanne,项目名称:libdynd,代码行数:48,代码来源:date_type.cpp

示例15: make_expr_kernel

    size_t make_expr_kernel(
                ckernel_builder *out, size_t offset_out,
                const ndt::type& dst_tp, const char *dst_metadata,
                size_t src_count, const ndt::type *src_tp, const char **src_metadata,
                kernel_request_t kernreq, const eval::eval_context *ectx) const
    {
        if (src_count != 1) {
            stringstream ss;
            ss << "date_strftime_kernel_generator requires 1 src operand, ";
            ss << "received " << src_count;
            throw runtime_error(ss.str());
        }
        bool require_elwise = dst_tp.get_type_id() != string_type_id ||
                        src_tp[0].get_type_id() != date_type_id;
        // If the types don't match the ones for this generator,
        // call the elementwise dimension handler to handle one dimension,
        // giving 'this' as the next kernel generator to call
        if (require_elwise) {
            return make_elwise_dimension_expr_kernel(out, offset_out,
                            dst_tp, dst_metadata,
                            src_count, src_tp, src_metadata,
                            kernreq, ectx,
                            this);
        }

        size_t extra_size = sizeof(date_strftime_kernel_extra);
        out->ensure_capacity_leaf(offset_out + extra_size);
        date_strftime_kernel_extra *e = out->get_at<date_strftime_kernel_extra>(offset_out);
        switch (kernreq) {
            case kernel_request_single:
                e->base.set_function<unary_single_operation_t>(&date_strftime_kernel_extra::single_unary);
                break;
            case kernel_request_strided:
                e->base.set_function<unary_strided_operation_t>(&date_strftime_kernel_extra::strided_unary);
                break;
            default: {
                stringstream ss;
                ss << "date_strftime_kernel_generator: unrecognized request " << (int)kernreq;
                throw runtime_error(ss.str());
            }
        }
        // The lifetime of kernels must be shorter than that of the kernel generator,
        // so we can point at data in the kernel generator
        e->format_size = m_format.size();
        e->format = m_format.c_str();
        e->dst_metadata = reinterpret_cast<const string_type_metadata *>(dst_metadata);
        return offset_out + extra_size;
    }
开发者ID:garaud,项目名称:libdynd,代码行数:48,代码来源:date_expr_kernels.cpp


注:本文中的ndt::type::get_type_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。