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


C++ Writer::attribute方法代码示例

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


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

示例1: write

void base_write_archive::write( Writer w, const str& name, variant& v)
  {
    schema* type  = true_type(v);
    void*   this_ = v.get_pointer();

    //3 use cases:
    //- we know the type as attibuted (ints, strings, things like that)
    //  note the implementor is free to define its custom types
    //
    //- we are saving an iterable type
    //
    //- or we are saving an object, these seem to be reasonable assumptions.
    if (attributed_type(type))
      {
        assert(!name.empty());
        w->attribute(name, v);
      }
    else
      {
        size_t type_options = type->options();
        if (type_options & TYPE_ITERATED)
          {
            iterable iter(v);
            iterator it = iter.begin();
            iterator nd = iter.end();

            WriteIterator wit = w->create_iterator(name, iter.iterated_type());

            for(; it != nd; ++it)
              {
                variant iv = *it;
                Writer  iw = wit->next(iv);
                if (iw)
                  write(iw, "", iv);
              }
          }
        else
          {
            Writer writer_ = name.empty()? w : w->create_node(name);

            schema* otype = v.get_schema(); assert(otype);
            size_t  oopt  = otype->options();
            if (oopt & TYPE_NON_INSTANTIABLE)
              {
                assert(type != otype);
                assert(types_);

                str class_id = types_->type_name(type); assert( !class_id.empty() );
                w->attribute("class", class_id);
              }

            //collect what we're saving
            schema_collector sc;
            type->visit(&sc);

            schema_collector::container::iterator it = sc.begin();
            schema_collector::container::iterator nd = sc.end();
            for(; it != nd; it++)
              {
                schema_item& item = it->second;
                if (item.flags & CONST)
                  continue;

                if (item.flags & TRANSIENT)
                  continue;

                if (item.get)
                  {
                    variant value = item.get->get(this_);
                    write(writer_, it->first, value);
                  }
              }
          }
      }
  }
开发者ID:gcubar,项目名称:XKP,代码行数:75,代码来源:serial.cpp


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