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


C++ variant::end方法代码示例

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


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

示例1: write_document

    void xml_writer_impl::write_document(const variant& document)
    {
        try
        {
            if ((m_mode & xml_mode::NoHeader)==0)
            {
                // output the XML header
                write_header();
            }

            if ((m_mode & xml_mode::Preserve)!=0)
            {
                bool first(true);
                if (document.is<variant::Mapping>())
                {
                    std::string element_name;
                    variant::const_iterator it, end(document.end());
                    for (it=document.begin(); it!=end; ++it)
                    {
                        if (it.key()==xml_text)
                        {
                            boost::throw_exception(variant_error("Encountered text in document node"));
                        }
                        else if (it.key()==xml_attributes)
                        {
                            boost::throw_exception(variant_error("Encountered attributes in document node"));
                        }
                        else if (it.key()==xml_instruction)
                        {
                            if (!first)
                            {
                                m_os << indent();
                            }
                            write_instruction(it.value());
                        }
                        else if (it.key()==xml_comment)
                        {
                            if (!first)
                            {
                                m_os << indent();
                            }
                            write_comment(it.value());
                        }
                        else
                        {
                            if (element_name.empty())
                            {
                                element_name = it.key();
                            }
                            else
                            {
                                boost::throw_exception(variant_error((boost::format("Illegal element %s encountered in document, expecting single element %s at root") % it.key() % element_name).str()));
                            }

                            push(it.key());
                            if (!first)
                            {
                                m_os << indent();
                            }
                            write_element(it.value());
                            pop();
                        }
                        first = false;
                    }
                }
                else
                {
                    boost::throw_exception(variant_error("Invalid document structure, root node must be a Dictionary or Bag"));
                }
            }
            else
            {
                push();
                write_variant(document);
                pop();
            }
        }
        catch (const std::exception &e)
        {
            boost::throw_exception(variant_error(e.what()));
        }
        catch (...)
        {
            boost::throw_exception(variant_error("Unhandled Exception"));
        }
    }
开发者ID:proteanic,项目名称:protean,代码行数:86,代码来源:xml_writer_impl.cpp

示例2: write_element

    void xml_writer_impl::write_element(const variant& element)
    {
        try
        {
            if (element.is<variant::Collection>() && element.empty() && element.type() != variant::DataTable)
            {
                write_empty_element();
                return;
            }

            switch(element.type())
            {
            case variant::None:
            {
                write_empty_element();
                break;
            }
            case variant::Any:
            case variant::String:
            {
                if (element.as<std::string>().empty())
                {
                    write_empty_element();
                    break;
                }
            }
            case variant::Float:
            case variant::Double:
            case variant::Int32:
            case variant::UInt32:
            case variant::Int64:
            case variant::UInt64:
            case variant::Boolean:
            case variant::Date:
            case variant::Time:
            case variant::DateTime:
            {
                m_os << start_tag();
                write_text(element);
                m_os << end_tag();
                break;
            }
            case variant::Dictionary:
            case variant::Bag:
            {
                if ((m_mode & xml_mode::Preserve)!=0)
                {
                    if (element.has_key(xml_attributes))
                    {
                        m_stack.top().m_attributes = element[xml_attributes];

                        if (element.size()==1)
                        {
                            write_empty_element();
                            break;
                        }
                    }

                    m_os << start_tag();

                    bool prev_is_text = false;
                    variant::const_iterator it, end(element.end());
                    for (it=element.begin(); it!=end; ++it)
                    {
                        if (it.key()==xml_attributes)
                        {
                            continue;
                        }
                        else if (it.key()==xml_text)
                        {
                            write_text(it.value());
                            prev_is_text = true;
                        }
                        else if (it.key()==xml_instruction)
                        {
                            push(it.key());

                            if (!prev_is_text)
                            {
                                m_os << indent();
                            }

                            write_instruction(it.value());

                            prev_is_text = false;

                            pop();
                        }
                        else if (it.key()==xml_comment)
                        {
                            push(it.key());

                            if (!prev_is_text)
                            {
                                m_os << indent();
                            }

                            write_comment(it.value());

                            prev_is_text = false;
//.........这里部分代码省略.........
开发者ID:proteanic,项目名称:protean,代码行数:101,代码来源:xml_writer_impl.cpp

示例3: foo2

void foo2() {
    typedef int type;
    std::vector<type> types;
    // ...
    std::unique(types.begin(), types.end(), boost::bind(std::equal_to<type>(), _1, _2));
}
开发者ID:Sangil-Lee,项目名称:MyCode,代码行数:6,代码来源:main.cpp


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