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


C++ Istream::good方法代码示例

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


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

示例1: exit

bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
(
    Istream& is,
    MeshedSurface<Face>& surf
)
{
    surf.clear();

    if (!is.good())
    {
        FatalErrorIn
        (
            "fileFormats::OFSsurfaceFormat::read"
            "(Istream&, MeshedSurface<Face>&)"
        )
            << "read error "
            << exit(FatalError);
    }

    pointField pointLst;
    List<Face> faceLst;
    List<surfZone> zoneLst;

    read(is, pointLst, faceLst, zoneLst);

    surf.reset
    (
        xferMove(pointLst),
        xferMove(faceLst),
        xferMove(zoneLst)
    );

    return true;
}
开发者ID:AmaneShino,项目名称:OpenFOAM-2.0.x,代码行数:34,代码来源:OFSsurfaceFormat.C

示例2: sr

Foam::scalarRanges::scalarRanges(Istream& is)
:
    List<scalarRange>(0)
{
    DynamicList<scalarRange> lst;

    while (is.good())
    {
        scalarRange sr(is);
        if (sr.isDefined())
        {
            lst.append(sr);
        }
    }

    transfer(lst);
}
开发者ID:Brzous,项目名称:WindFOAM,代码行数:17,代码来源:scalarRanges.C

示例3: firstToken

bool Foam::IOobject::readHeader(Istream& is)
{
    if (IOobject::debug)
    {
        Info<< "IOobject::readHeader(Istream&) : reading header for file "
            << is.name() << endl;
    }

    // Check Istream not already bad
    if (!is.good())
    {
        if (rOpt_ == MUST_READ || rOpt_ == MUST_READ_IF_MODIFIED)
        {
            FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
                << " stream not open for reading essential object from file "
                << is.name()
                << exit(FatalIOError);
        }

        if (IOobject::debug)
        {
            SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
                << " stream not open for reading from file "
                << is.name() << endl;
        }

        return false;
    }

    token firstToken(is);

    if
    (
        is.good()
     && firstToken.isWord()
     && firstToken.wordToken() == "FoamFile"
    )
    {
        dictionary headerDict(is);

        is.version(headerDict.lookup("version"));
        is.format(headerDict.lookup("format"));
        headerClassName_ = word(headerDict.lookup("class"));

        const word headerObject(headerDict.lookup("object"));
        if (IOobject::debug && headerObject != name())
        {
            IOWarningIn("IOobject::readHeader(Istream&)", is)
                << " object renamed from "
                << name() << " to " << headerObject
                << " for file " << is.name() << endl;
        }

        // The note entry is optional
        headerDict.readIfPresent("note", note_);
    }
    else
    {
        SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
            << "First token could not be read or is not the keyword 'FoamFile'"
            << nl << nl << "Check header is of the form:" << nl << endl;

        writeHeader(Info);

        return false;
    }

    // Check stream is still OK
    if (is.good())
    {
        objState_ = GOOD;
    }
    else
    {
        if (rOpt_ == MUST_READ || rOpt_ == MUST_READ_IF_MODIFIED)
        {
            FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
                << " stream failure while reading header"
                << " on line " << is.lineNumber()
                << " of file " << is.name()
                << " for essential object" << name()
                << exit(FatalIOError);
        }

        if (IOobject::debug)
        {
            Info<< "IOobject::readHeader(Istream&) :"
                << " stream failure while reading header"
                << " on line " << is.lineNumber()
                << " of file " << is.name() << endl;
        }

        objState_ = BAD;

        return false;
    }

    if (IOobject::debug)
    {
        Info<< " .... read" << endl;
//.........这里部分代码省略.........
开发者ID:000861,项目名称:OpenFOAM-2.1.x,代码行数:101,代码来源:IOobjectReadHeader.C

示例4: test_ok

void test_ok (const charT*, const Traits*,
              const char *cname, const char *tname)
{
    typedef std::basic_istream<charT, Traits>   Istream;
    typedef typename Istream::sentry            Sentry;

    memfun_info (__LINE__, cname, tname, "operator bool () const");

    const charT cbuf[] = { 'a', 'b', 'c', 'd', 'e', ' ', 'f', '\0' };

    const std::ios_base::iostate states[] = {
        std::ios_base::badbit,
        std::ios_base::eofbit,
        std::ios_base::failbit,
        std::ios_base::goodbit,
        std::ios_base::badbit | std::ios_base::eofbit,
        std::ios_base::badbit | std::ios_base::failbit,
        std::ios_base::eofbit | std::ios_base::failbit,
        std::ios_base::badbit | std::ios_base::eofbit | std::ios_base::failbit
    };

    //////////////////////////////////////////////////////////////
    // exercise 27.6.1.1.2, p5:
    //     -  is.good() is true
    //     -  noskipws is zero
    //     -  is.flags() & ios_base::skipws
    //     -  the function extracts and discards each character as long
    //        as the next available input character c is a whitespace
    //        character
    //     =  if, after any preparation is completed, is.good() is true,
    //        ok_ != false otherwise, ok_ == false.

    unsigned iter = 0;     // iteration counter

    for (unsigned i = 0; i != sizeof states / sizeof *states; ++i) {
        for (unsigned j = 0; j != 2; ++j /* noskipws */) {
            for (unsigned k = 0; k != 2; ++k /* ios_base::skipws */) {
                for (charT wc = charT ('a'); wc != charT ('c'); ++wc) {

                    const Ctype<charT> ctp (1, wc);

                    Streambuf<charT, Traits>
                        sb (cbuf, cbuf + sizeof cbuf / sizeof *cbuf);

                    Istream is (&sb);

                    is.setstate (states [i]);

                    if (k)
                        is.setf (std::ios_base::skipws);
                    else
                        is.unsetf (std::ios_base::skipws);

                    const std::locale loc = 
                        is.imbue (std::locale (is.getloc (), &ctp));

                    // imbue the previous locale into the stream
                    // buffer to verify that the sentry ctor uses
                    // the locale imbued in the stream object and
                    // not the one in the stream buffer
                    sb.pubimbue (loc);

                    const Sentry guard (is, 0 != j);

                    _RWSTD_UNUSED (guard);

                    const bool success =
                           is.good () && guard
                        || !is.good () && !guard;

                    rw_assert (success, 0, __LINE__,
                               "%u. %{$SENTRY}"
                               "(%{$ISTREAM} &is, bool noskipws "
                               "= %d).operator bool() == %d; initial "
                               "is.state() = %{Is}, is.flags() & "
                               "ios::skipws = %d",
                               iter, j, is.good (),
                               states [i], k);

                    ++iter;
                }
            }
        }
    }
}
开发者ID:Quna,项目名称:mspdev,代码行数:85,代码来源:27.istream.sentry.cpp

示例5: test_ctor

void test_ctor (const charT*, const Traits*,
                const char *cname, const char *tname)
{
    typedef std::basic_istream<charT, Traits>   Istream;
    typedef typename Istream::sentry            Sentry;

    memfun_info (__LINE__, cname, tname, "sentry (%{$ISTREAM}&, bool)");

    const charT cbuf[] = { 'a', 'b', 'c', 'd', 'e', ' ', 'f', '\0' };

    const std::ios_base::iostate states[] = {
        std::ios_base::badbit,
        std::ios_base::eofbit,
        std::ios_base::failbit,
        std::ios_base::goodbit,
        std::ios_base::badbit | std::ios_base::eofbit,
        std::ios_base::badbit | std::ios_base::failbit,
        std::ios_base::eofbit | std::ios_base::failbit,
        std::ios_base::badbit | std::ios_base::eofbit | std::ios_base::failbit
    };

    //////////////////////////////////////////////////////////////
    // exercise 27.6.1.1.2, p1:
    //     -  is.good() is true
    //     -  is.tie() is not null
    //     =  the function calls is.tie().flush()

    unsigned iter = 0;     // iteration counter

    for (unsigned i = 0; i != sizeof states / sizeof *states; ++i) {
        for (unsigned j = 0; j != 2; ++j /* noskipws */) {
            Streambuf<charT, Traits>
                sb (cbuf, cbuf + sizeof cbuf / sizeof *cbuf);

            Istream is (&sb);

            // flush() is called iff
            // all of the following conditions hold
            const bool flush_called = is.good () && 0 != is.tie ();

            const Sentry guard (is, 0 != j);

            _RWSTD_UNUSED (guard);

            rw_assert (flush_called == sb.nsyncs_, 0, __LINE__,
                       "%u. basic_istream<%s, %s>::sentry::sentry"
                       "(basic_istream &is, bool noskipws = %d); "
                       "expected to call is.flush () %d times, got %d"
                       "initial is.state () = %{Is}, is.flags() & "
                       "ios::skipws = %d",
                       iter, cname, tname, 0 != j, flush_called, sb.nsyncs_,
                       states [i], is.flags () & std::ios_base::skipws);

            ++iter;
        }
    }

    //////////////////////////////////////////////////////////////
    // exercise 27.6.1.1.2, p1:
    //     -  is.good() is true
    //     -  noskipws is zero
    //     -  is.flags() & ios_base::skipws
    //     =  the function extracts and discards each character as long
    //        as the next available input character c is a whitespace
    //        character.

    for (unsigned i = 0; i != sizeof states / sizeof *states; ++i) {
        for (unsigned j = 0; j != 2; ++j /* noskipws */) {
            for (unsigned k = 0; k != 2; ++k /* ios_base::skipws */) {
                for (charT wc = charT ('a'); wc != charT ('c'); ++wc) {

                    const Ctype<charT> ctp (1, wc);

                    Streambuf<charT, Traits>
                        sb (cbuf, cbuf + sizeof cbuf / sizeof *cbuf);

                    Istream is (&sb);

                    is.setstate (states [i]);

                    if (k)
                        is.setf (std::ios_base::skipws);
                    else
                        is.unsetf (std::ios_base::skipws);

                    const std::locale loc = 
                        is.imbue (std::locale (is.getloc (), &ctp));

                    // imbue the previous locale into the stream
                    // buffer to verify that the sentry ctor uses
                    // the locale imbued in the stream object and
                    // not the one in the stream buffer
                    sb.pubimbue (loc);

                    // a whitespace character is extracted iff
                    // all of the following conditions hold
                    const bool extract =
                           is.good ()
                        && 0 == j
                        && is.flags () & std::ios_base::skipws
//.........这里部分代码省略.........
开发者ID:Quna,项目名称:mspdev,代码行数:101,代码来源:27.istream.sentry.cpp

示例6: test_readsome

void test_readsome (const charT *cbuf, const Traits*,
                    unsigned cbuf_size,
                    unsigned i,   // index into states
                    unsigned j,   // number of chars to read
                    unsigned k,   // when underflow() will fail
                    int      l,   // value returned from showmanyc()
                    unsigned m)   // how underflow should fail()
{
    typedef std::basic_istream<charT, Traits> Istream;

    static unsigned iter = 0;   // iteration counter

    // construct a stream buffer object and initialize its read
    // sequence with the character buffer
    Streambuf<charT, Traits> sb (cbuf, cbuf + cbuf_size - 1);

    sb.showmanyc_ = l;

    const char* err_type = 0;

    if (m < 1) {
        // have the stream buffer object's underflow() fail (by
        // throwing an exception if possible) after k characters
        // have been extracted (this object calls underflow() for
        // every char)
        sb.throw_after_ = k;
        err_type        = "threw";
    }
    else {
        // have the stream buffer object's underflow() fail by
        // returning eof after k characters have been extracted
        // (this object calls underflow() for every char)
        sb.fail_after_ = k;
        err_type       = "returned EOF";
    }

    // construct an istream object and initialize it with the user
    // defined streambuf object
    Istream is (&sb);

    // set the stream object's initial state
    is.setstate (states [i]);

    // the number of extracted whitespace characters expected to
    // be reported by gcount() must equal the number of successful
    // extractions computed by the the stream buffer overridden
    // underflow member function
    const int extract =
        is.good () ? j < k ? int (j) < l ? j
                                         : l < 0 ? 0 : l
                           : int (k) < l ? k
                                         : l < 0 ? 0 : l
                   : 0;

    charT buf [256] = { 0 };

    std::streamsize nread = -1;

    // format the FCALL environment variable so that it can be
    // conveniently used in diagnostics below
    rw_fprintf (0, "%u. %{$FCALL!:@}",
                iter,
                "%{$ISTREAM}(%{*Ac}).readsome(%p, %d)",
                int (sizeof *cbuf), cbuf, buf, j);

#ifndef _RWSTD_NO_EXCEPTIONS

    const char *caught = 0;

    // on every other iteration set badbit in exceptions to check
    // that the thrown object is propagated by the function
    if (k % 2 && !is.bad ())
        is.exceptions (std::ios_base::badbit);

    try {
        nread = is.readsome (buf, j);
    }
    catch (const char *s) {
        caught = s;
    }
    catch (...) {

        caught = "...";

        rw_assert (0, 0, __LINE__,
                   "%{$FCALL} threw an exception of unexpected type");
    }

    //////////////////////////////////////////////////////////////////
    // verify that the function propagates exceptions thrown from the
    // streambuf object only when badbit is set in the stream object's
    // exceptions()

    rw_assert (!caught || (k % 2), 0, __LINE__,
               "%{$FCALL} unexpectedly propagated an exception");

#else   // if defined (_RWSTD_NO_EXCEPTIONS)

    nread = is.readsome (buf, j);

//.........这里部分代码省略.........
开发者ID:Flameeyes,项目名称:stdcxx,代码行数:101,代码来源:27.istream.readsome.cpp


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