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


C++ Msg::add_fld方法代码示例

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


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

示例1: register_fields

void register_fields(Model& model, Msg& msg, VALUE type, VALUE mapping) {
  VALUE deflators = rb_get(type, "deflators");
  VALUE inflators = rb_get(type, "inflators");

  for (VALUE rb_fld : arr2vec(rb_get(type, "fields"))) {
    VALUE fld_name = rb_get(rb_fld, "name");
    Fld fld;
    fld.num = NUM2INT(rb_get(rb_fld, "num"));
    fld.name = rb_sym_to_cstr(fld_name);
    int fld_type = NUM2INT(rb_get(rb_fld, "type"));
    fld.fld_type = fld_type;
    if (fld_type == FLD_MESSAGE)
      fld.embedded_msg = &get_msg_for_type(model, rb_get(rb_fld, "msg_class"));
    fld.wire_type = wire_type_for_fld_type(fld_type);
    fld.label = NUM2INT(rb_get(rb_fld, "label"));
    if (fld.label == LABEL_REQUIRED)
      msg.num_required_fields++;
    fld.is_packed = RTEST(rb_get(rb_fld, "packed"));
    fld.deflate = rb_hash_aref(deflators, fld_name);
    keep_alive(model, fld.deflate);
    fld.inflate = rb_hash_aref(inflators, fld_name);
    keep_alive(model, fld.inflate);
    fld.get_lazy_type = rb_get(rb_fld, "get_lazy_type");
    keep_alive(model, fld.get_lazy_type);
    if (fld_type == FLD_ENUM) {
      fld.enum_module = rb_get(rb_fld, "msg_class");
      keep_alive(model, fld.enum_module);
      fld.enum_values = arr2vec(rb_get(fld.enum_module, "values"));
      // (we don't need to keep_alive() Fixnums)
    }

    if (msg.target_is_hash) {
      fld.target_key = rb_call1(rb_get(mapping, "get_target_key"), rb_fld);
      keep_alive(model, fld.target_key);
    } else {
      VALUE tf = rb_call1(rb_get(mapping, "get_target_field"), rb_fld);
      string target_field_name = TYPE(tf) == T_STRING ? RSTRING_PTR(tf) : rb_sym_to_cstr(tf);
      fld.target_field_getter = rb_intern(target_field_name.c_str());
      fld.target_field_setter = rb_intern((target_field_name + "=").c_str());
    }

    fld.write = get_val_writer(fld_type);
    fld.read = get_val_reader(fld_type);
    msg.add_fld(msg, fld);
  }
}
开发者ID:wintonpc,项目名称:pbr,代码行数:46,代码来源:pbr_ext.cpp


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