本文整理汇总了C++中Istream::gcount方法的典型用法代码示例。如果您正苦于以下问题:C++ Istream::gcount方法的具体用法?C++ Istream::gcount怎么用?C++ Istream::gcount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Istream
的用法示例。
在下文中一共展示了Istream::gcount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_data
static int load_data(Istream& fin, const gcstring& table)
{
int nrecs = 0;
int tran = theDB()->transaction(READWRITE);
for (;; ++nrecs)
{
int n;
fin.read((char*) &n, sizeof n);
if (fin.gcount() != sizeof n)
except("unexpected eof");
if (n == 0)
break ;
load_data_record(fin, table, tran, n);
if (nrecs % recsPerTran == recsPerTran - 1)
{
verify(theDB()->commit(tran));
tran = theDB()->transaction(READWRITE);
}
}
verify(theDB()->commit(tran));
return nrecs;
}
示例2: test_ctor
//.........这里部分代码省略.........
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
&& cbuf [0] == wc;
const Sentry guard (is, 0 != j);
_RWSTD_UNUSED (guard);
rw_assert (cbuf + extract == sb.pubgptr (), 0, __LINE__,
"%u. %{$SENTRY}::sentry"
"(%{$ISTREAM} &is, bool noskipws "
"= %b); expected to extract %d "
"whitespace chars ('%c') from %{*Ac}, "
"extracted %u; initial is.state () = "
"%{Is}, is.flags() & ios::skipws = %d",
iter, j, extract + 0, char (wc),
int (sizeof (*cbuf)), cbuf,
sb.pubgptr () - sb.pubeback (),
states [i], k);
// verify that the ctor doesn't affect gcount()
rw_assert (0 == is.gcount (), 0, __LINE__,
"%u. %{$SENTRY}::sentry"
"(%{$ISTREAM} &is = %{*Ac}, bool noskipws "
"= %b); changed is.gcount() from 0 to %i",
iter, int (sizeof (*cbuf)), cbuf, j,
is.gcount ());
++iter;
}
}
}
}
}
示例3: if
//.........这里部分代码省略.........
ArithmeticType value = init_value;
// format the FUNCALL environment variable w/o writing out any output
rw_fprintf (0,
"%{$FUNCALL!:@}",
"%{$CLASS}(%{*Ac}).operator>>(%s& = %{@}): "
"initial flags() = %{If}, rdstate() = %{Is}, "
"exceptions() = %{Is}, whitespace = %{#s}, numpunct = { "
".dp=%{#c}, .ts=%{#c}, .grp=%{#s}, .fn=%{#s}, .tn=%{#s} }",
int (sizeof *cbuf), cbuf, aname, valfmt, init_value,
flags, init_state,
exceptions, locale_data.whitespace,
locale_data.decimal_point, locale_data.thousands_sep,
locale_data.grouping, locale_data.falsename,
locale_data.truename);
#ifndef _RWSTD_NO_EXCEPTIONS
int caught = 0;
try {
is >> value;
}
catch (Exception&) {
caught = 1;
}
catch (std::ios_base::failure &ex) {
caught = 2;
rw_assert (caught == expect_exception, 0, line,
"line %d. %{$FUNCALL}: unexpectedly threw "
"ios_base::failure(%{#s})", __LINE__, ex.what ());
}
catch (...) {
caught = -1;
rw_assert (false, 0, line,
"line %d. %{$FUNCALL}: unexpectely threw an exception "
"of unknown type", __LINE__);
}
//////////////////////////////////////////////////////////////////
// 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 == expect_exception, 0, line,
"line %d. %{$FUNCALL}: "
"%{?}failed to throw"
"%{:}unexpectedly propagated"
"%{;} exception",
__LINE__, expect_exception);
#else // if defined (_RWSTD_NO_EXCEPTIONS)
is >> value;
#endif // _RWSTD_NO_EXCEPTIONS
// clear the text describing the type of failure when streambuf
// didn't actually fail (or throw)
if (sb.failed_ == None && sb.threw_ == None)
fail_desc = 0;
//////////////////////////////////////////////////////////////////
// verify that the expected number of characters have been
// extracted from the stream
const int extracted = int (sb.pubgptr () - sb.pubeback ());
rw_assert (expect_extract == extracted, 0, line,
"%d. %{$FUNCALL}: expected to extract %d characters, "
"got %d%{?} (underflow() %s at extraction %u)%{;}",
__LINE__, expect_extract,
extracted, 0 != fail_desc, fail_desc, fail_when);
//////////////////////////////////////////////////////////////////
// verify that gcount() is not affected
if (0 == opt_no_gcount)
rw_assert (0 == is.gcount (), 0, line,
"%d. %{$FUNCALL}: gcount() == 0, got %d "
"%{?} (underflow() %s at extraction %u)%{;}",
__LINE__, is.gcount (),
0 != fail_desc, fail_desc, fail_when);
//////////////////////////////////////////////////////////////////
// verify the state of the stream object after the function call
rw_assert (is.rdstate () == expect_state, 0, line,
"line %d. %{$FUNCALL}: rdstate() == %{Is}, got %{Is}"
"%{?} (underflow() %s at extraction %u)%{;}",
__LINE__, expect_state, is.rdstate(),
0 != fail_desc, fail_desc, fail_when);
//////////////////////////////////////////////////////////////////
// verify the extracted value matches the expected value
rw_assert (expect_value == value, 0, line,
"line %d. %{$FUNCALL}: expected value %{@}, got %{@}",
__LINE__, valfmt, expect_value, valfmt, value);
}
示例4: test_readsome
//.........这里部分代码省略.........
// exceptions()
rw_assert (!caught || (k % 2), 0, __LINE__,
"%{$FCALL} unexpectedly propagated an exception");
#else // if defined (_RWSTD_NO_EXCEPTIONS)
nread = is.readsome (buf, j);
#endif // _RWSTD_NO_EXCEPTIONS
//////////////////////////////////////////////////////////////////
// verify that the function returned the expected number of
// extracted characters
const std::streamsize extracted = sb.pubgptr () - sb.pubeback ();
rw_assert (extract == extracted, 0, __LINE__,
"%{$FCALL} expected to extract %d chars, got %u; "
"initial state = %{Is}, underflow %s at extraction %u",
extract, extracted, states [i],
err_type, k);
//////////////////////////////////////////////////////////////////
// verify that the expected number of characters have been
// extracted from the stream
rw_assert (cbuf + extract == sb.pubgptr (), 0, __LINE__,
"%{$FCALL} expected to extract %d chars, got %u; "
"initial state = %{Is}, underflow %s at extraction %u",
extract, extracted, states [i],
err_type, k);
//////////////////////////////////////////////////////////////////
// verify that the extracted characters match those in the buffer
rw_assert (0 == std::char_traits<charT>::compare (buf, cbuf, extract),
0, __LINE__,
"%{$FCALL} expected to extract the first %d chars, got %{*Ac}",
extract, int (sizeof *buf), buf);
//////////////////////////////////////////////////////////////////
// verify that gcount() correctly reflects the number of
// characters successfully extracted from the stream
rw_assert (extract == is.gcount (), 0, __LINE__,
"%{$FCALL}: gcount() == %d, got %d; initial state = %{Is}, "
"underflow %s at extraction %u",
extract, is.gcount (), states [i],
err_type, k);
//////////////////////////////////////////////////////////////////
// verify the state of the stream object after the function call
// expected stream state after the function call is unchanged
// (i.e., the initial stream state), except...
std::ios_base::iostate expect_state = states [i];
if (!states [i]) {
#ifndef _RWSTD_NO_EXCEPTIONS
// ...if an extraction is attempted, or even if the first
// character on the stream is peeked at, and an exception
// is thrown during input, badbit should be set, otherwise
// if in_avail() returned -1, eofbit should be set, else
// the state should be good
if (-2 == l)
expect_state = std::ios_base::badbit;
else if (l < 0)
expect_state = std::ios_base::eofbit;
else
expect_state = std::ios_base::goodbit;
#else // if defined (_RWSTD_NO_EXCEPTIONS)
if (l < 0)
expect_state = std::ios_base::eofbit;
else
expect_state = std::ios_base::goodbit;
#endif // _RWSTD_NO_EXCEPTIONS
}
else {
// ...if the initial stream state is not good, failbit
// must be set
expect_state = states [i] | std::ios_base::failbit;
}
rw_assert (is.rdstate () == expect_state, 0, __LINE__,
"%{$FCALL}: rdstate() == %{Is}, got %{Is}; "
"extracted %u characters; "
"initial state = %{Is}, underflow %s at extraction %u",
expect_state, is.rdstate (), extracted,
states [i], err_type, k);
++iter;
}