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


C++ basic_ostream::getloc方法代码示例

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


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

示例1: write_json_helper

    void write_json_helper(std::basic_ostream<typename Ptree::char_type> &stream, 
                           const Ptree &pt, 
                           int indent)
    {

        typedef typename Ptree::char_type Ch;
        typedef typename std::basic_string<Ch> Str;
        
        // Value or object or array
        if (indent > 0 && pt.empty())
        {
            
            // Write value
            Str data = create_escapes(pt.template get_own<Str>(), stream.getloc());
            stream << Ch('"') << data << Ch('"');

        }
        else if (indent > 0 && pt.count(Str()) == pt.size())
        {
                
            // Write array
            stream << Ch('[') << Ch('\n');
            typename Ptree::const_iterator it = pt.begin();
            for (; it != pt.end(); ++it)
            {
                stream << Str(4 * (indent + 1), Ch(' '));
                write_json_helper(stream, it->second, indent + 1);
                if (boost::next(it) != pt.end())
                    stream << Ch(',');
                stream << Ch('\n');
            }
            stream << Str(4 * indent, Ch(' ')) << Ch(']');

        }
        else
        {
        
            // Write object
            stream << Ch('{') << Ch('\n');
            typename Ptree::const_iterator it = pt.begin();
            for (; it != pt.end(); ++it)
            {
                stream << Str(4 * (indent + 1), Ch(' '));
                stream << Ch('"') << create_escapes(it->first, stream.getloc()) << Ch('"') << Ch(':');
                if (it->second.empty())
                    stream << Ch(' ');
                else
                    stream << Ch('\n') << Str(4 * (indent + 1), Ch(' '));
                write_json_helper(stream, it->second, indent + 1);
                if (boost::next(it) != pt.end())
                    stream << Ch(',');
                stream << Ch('\n');
            }
            stream << Str(4 * indent, Ch(' ')) << Ch('}');

        }

    }
开发者ID:craton-,项目名称:php_mapnik,代码行数:58,代码来源:json_parser_write.hpp

示例2: write

 ///
 /// Translate message and write to stream \a out, using imbued locale and domain set to the 
 /// stream
 ///
 void write(std::basic_ostream<char_type> &out) const
 {
     std::locale const &loc = out.getloc();
     int id = ios_info::get(out).domain_id();
     string_type buffer;
     out << write(loc,id,buffer);
 }
开发者ID:imos,项目名称:icfpc2015,代码行数:11,代码来源:message.hpp

示例3: fprint

inline void fprint(std::basic_ostream<Char, Trait>& out, const Char* str, Args&&... arguments) {
    // %[parameter][flags][width][.precision]verb
    // if it's *n$ instead of %n$ then it'll use the specific parameter number
    // n starts at 1 to sizeof...(Args)
    // at the moment I'm too lazy to do * at all.
    auto&& args = std::make_tuple(std::forward<Args>(arguments)...);
    stream_state<Char, Trait> original{out};
    stream_state<Char, Trait> changed;
    printer<Char, Trait> func(out);
    const Char percent = out.widen('%');
    const Char zero    = out.widen('0');
    auto&& loc = out.getloc();
    size_t index = 0;
    size_t position = 0;
    bool has_positional = false;

    while(*str != 0) {
        // not a %
        if(!Trait::eq(*str, percent)) {
            out << *str++;
            continue;
        }

        // at this point -- *str == '%'
        // so just increment it to get to the format-spec
        ++str;

        // escaped %
        if(*str && Trait::eq(*str, percent)) {
            out << percent;
            ++str;
            continue;
        }

        // beginning of format-spec
        changed = original;

        // check for [parameter], i.e. n$
        // or a numeric value for [width]
        position = parse_integer(str, zero, loc);

        // check if it's [parameter] rather than [width]
        if(Trait::eq(*str, out.widen('$'))) {
            has_positional = true;
            ++str;
        }

        // check for [flags]
        // they are as follows:
        // +       - equivalent to std::showpos
        // -       - left aligns instead of right align, i.e. std::left
        // 0       - pad with 0s instead of spaces
        // '[char] - pad with [char] instead of spaces
        while(*str) {
            if(Trait::eq(*str, out.widen('+'))) {
                changed.flags |= out.showpos;
            }
            else if(Trait::eq(*str, out.widen('-'))) {
                changed.flags |= out.left;
            }
            else if(Trait::eq(*str, out.widen('0'))) {
                changed.fill = out.widen('0');
            }
            else if(Trait::eq(*str, out.widen('\''))) {
                // the next character is unconditionally the fill character
                changed.fill = *(++str);
            }
            else {
                // unknown flag, so just exit
                break;
            }
            ++str;
        }

        // check for [width]
        changed.width = parse_integer(str, zero, loc);

        // check for [precision]
        if(Trait::eq(*str, out.widen('.'))) {
            changed.precision = parse_integer(++str, zero, loc);
        }


        size_t final_index = has_positional ? position - 1 : index++;

        // check for verb
        if(Trait::eq(*str, out.widen('s')) || Trait::eq(*str, out.widen('c'))) {
            // do nothing since these don't add any extra format specifiers.
            // many of these are provided as a thin compatibility layer for
            // the original printf -- albeit strict compatibility is not a requirement here.
        }
        else if(Trait::eq(*str, out.widen('f')) || Trait::eq(*str, out.widen('F'))) {
            changed.flags |= out.fixed;
        }
        else if(Trait::eq(*str, out.widen('e'))) {
            changed.flags |= out.scientific;
        }
        else if(Trait::eq(*str, out.widen('E'))) {
            changed.flags |= out.scientific;
            changed.flags |= out.uppercase;
//.........这里部分代码省略.........
开发者ID:CCJY,项目名称:coliru,代码行数:101,代码来源:main.cpp


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