本文整理汇总了C++中std::ios_base类的典型用法代码示例。如果您正苦于以下问题:C++ ios_base类的具体用法?C++ ios_base怎么用?C++ ios_base使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ios_base类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: callback
void callback(std::ios_base::event ev, std::ios_base& strm, int idx)
{
if (ev == std::ios_base::erase_event)
{
try
{
delete static_cast<NewFormat*>(strm.pword(idx));
strm.pword(idx) = 0;
}
catch (...)
{ }
}
else if (ev == std::ios_base::copyfmt_event)
{
NewFormat* old(static_cast<NewFormat*>(strm.pword(idx)));
if (old != 0)
{
try
{
strm.pword(idx) = new NewFormat(*old);
}
catch (std::bad_alloc&)
{ }
}
}
}
示例2: replace_pword
void replace_pword(std::ios_base& iob, int idx, const T& x) {
iob.register_callback(callback<NewFormat>, idx);
NewFormat* new_format(new NewFormat(x));
OldFormat* old_format(static_cast<OldFormat*>(iob.pword(idx)));
iob.pword(idx) = new_format;
delete old_format;
}
示例3: my_ios_callback
// Stream format gets copied or destroyed
static void my_ios_callback(std::ios_base::event ev, std::ios_base & s, int i)
{
print_context *p = static_cast<print_context *>(s.pword(i));
if (ev == std::ios_base::erase_event) {
delete p;
s.pword(i) = nullptr;
} else if (ev == std::ios_base::copyfmt_event && p != nullptr)
s.pword(i) = p->duplicate();
}
示例4: cleanup
void cleanup(std::ios_base::event evt, std::ios_base& str, int idx)
{
if (str.iword(separatorEnabled()) && evt == std::ios_base::erase_event)
{
void*& p = str.pword(idx);
delete static_cast<std::string*>(p);
str.iword(separatorEnabled()) = false;
}
}
示例5: put
OutItrT put(OutItrT a_next,
std::ios_base& a_ios,
char_type a_fill,
const time_type& a_time) const
{
if (a_time.is_special()) {
return do_put_special(a_next, a_ios, a_fill,
a_time.date().as_special());
}
string_type format(m_format);
string_type frac_str;
if (format.find(seconds_with_fractional_seconds_format)) {
// replace %s with %S.nnn
frac_str =
fractional_seconds_as_string(a_time.time_of_day(), false);
char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point();
string_type replace_string(seconds_format);
replace_string += sep;
replace_string += frac_str;
boost::algorithm::replace_all(format,
seconds_with_fractional_seconds_format,
replace_string);
}
if (format.find(fractional_seconds_format)) {
// replace %f with nnnnnnn
if (!frac_str.size()) {
frac_str = fractional_seconds_as_string(a_time.time_of_day(), false);
}
boost::algorithm::replace_all(format,
fractional_seconds_format,
frac_str);
}
if (format.find(fractional_seconds_or_none_format)) {
// replace %F with nnnnnnn or nothing if fs == 0
frac_str =
fractional_seconds_as_string(a_time.time_of_day(), true);
if (frac_str.size()) {
char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point();
string_type replace_string;
replace_string += sep;
replace_string += frac_str;
boost::algorithm::replace_all(format,
fractional_seconds_or_none_format,
replace_string);
}
else {
boost::algorithm::erase_all(format,
fractional_seconds_or_none_format);
}
}
return do_put_tm(a_next, a_ios, a_fill,
to_tm(a_time), format);
}
示例6: d
format_parser::format_parser(std::ios_base &ios,void *cookie,void (*imbuer)(void *,std::locale const &)) :
ios_(ios),
d(new data)
{
d->position=std::numeric_limits<unsigned>::max();
d->precision=ios.precision();
d->flags = ios.flags();
d->info=ios_info::get(ios);
d->saved_locale = ios.getloc();
d->restore_locale=false;
d->cookie = cookie;
d->imbuer = imbuer;
}
示例7: put_duration
iter_type put_duration(iter_type i, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const
{
if (std::has_facet<duration_put<CharT> >(ios.getloc()))
{
duration_put<CharT> const &facet = std::use_facet<duration_put<CharT> >(ios.getloc());
return facet.put(i, ios, fill, d);
}
else
{
duration_put<CharT> facet;
return facet.put(i, ios, fill, d);
}
}
示例8: set_stream_state
bool logstream_base::set_stream_state(std::ios_base& dest, int& dstchar) {
std::ios_base::fmtflags setval = initset.flags();
std::ios_base::fmtflags clrval = initclear.flags();
std::ios_base::fmtflags mask = setval ^ (~clrval);
dest.setf(clrval, mask);
if (initset.precision() == initclear.precision()) {
dest.precision(initset.precision());
}
if (initset.width() == initclear.width()) {
dest.width(initset.width());
}
dstchar = fillchar;
return fillset;
}
示例9: get_duration
iter_type get_duration(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
duration<Rep, Period>& d) const
{
if (std::has_facet<duration_get<CharT> >(is.getloc()))
{
duration_get<CharT> const &facet = std::use_facet<duration_get<CharT> >(is.getloc());
return get_duration(facet, i, e, is, err, d);
}
else
{
duration_get<CharT> facet;
return get_duration(facet, i, e, is, err, d);
}
}
示例10: put_unit
iter_type put_unit(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const
{
if (std::has_facet<duration_units<CharT> >(ios.getloc()))
{
duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >(
ios.getloc());
return put_unit(facet, s, ios, fill, d);
}
else
{
duration_units_default<CharT> facet;
return put_unit(facet, s, ios, fill, d);
}
}
示例11: put
iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp, const CharT* pattern,
const CharT* pat_end) const
{
if (std::has_facet<time_point_units<CharT> >(ios.getloc()))
{
time_point_units<CharT> const &facet =
std::use_facet<time_point_units<CharT> >(ios.getloc());
return put(facet, i, ios, fill, tp, pattern, pat_end);
}
else
{
time_point_units_default<CharT> facet;
return put(facet, i, ios, fill, tp, pattern, pat_end);
}
}
示例12: set_print_context
// Set print_context associated with stream, retain options
static void set_print_context(std::ios_base & s, const print_context & c)
{
int i = my_ios_index();
long flags = s.iword(i);
if (!(flags & callback_registered)) {
s.register_callback(my_ios_callback, i);
s.iword(i) = flags | callback_registered;
}
print_context *p = static_cast<print_context *>(s.pword(i));
unsigned options = p ? p->options : c.options;
delete p;
p = c.duplicate();
p->options = options;
s.pword(i) = p;
}
示例13: new
void LocaleUtils::CLocaleScope::set(std::ios_base &baseStream) {
assert(orgLocale_ == NULL);
orgLocale_ = new (static_cast<void*>(&orgLocaleStorage_)) std::locale(
baseStream.imbue(getCLocale()));
baseStream_ = &baseStream;
}
示例14: put
iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const
{
if (std::has_facet<duration_units<CharT> >(ios.getloc()))
{
duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >(
ios.getloc());
std::basic_string<CharT> str = facet.get_pattern();
return put(facet, s, ios, fill, d, str.data(), str.data() + str.size());
}
else
{
duration_units_default<CharT> facet;
std::basic_string<CharT> str = facet.get_pattern();
return put(facet, s, ios, fill, d, str.data(), str.data() + str.size());
}
}
示例15: get
InItrT get(InItrT& from,
InItrT& to,
std::ios_base& a_ios,
duration_type& dd) const
{
// skip leading whitespace
while(std::isspace(*from) && from != to) {
++from;
}
/* num_get.get() will always consume the first character if it
* is a sign indicator (+/-). Special value strings may begin
* with one of these signs so we'll need a copy of it
* in case num_get.get() fails. */
char_type c = '\0';
// TODO Are these characters somewhere in the locale?
if(*from == '-' || *from == '+') {
c = *from;
}
typedef std::num_get<CharT, InItrT> num_get;
typename duration_type::duration_rep_type val = 0;
std::ios_base::iostate err = std::ios_base::goodbit;
if (std::has_facet<num_get>(a_ios.getloc())) {
from = std::use_facet<num_get>(a_ios.getloc()).get(from, to, a_ios, err, val);
}
else {
num_get* ng = new num_get();
std::locale l = std::locale(a_ios.getloc(), ng);
a_ios.imbue(l);
from = ng->get(from, to, a_ios, err, val);
}
if(err & std::ios_base::failbit) {
typedef typename special_values_parser_type::match_results match_results;
match_results mr;
if(c == '-' || c == '+') { // was the first character consumed?
mr.cache += c;
}
m_sv_parser.match(from, to, mr);
if(mr.current_match == match_results::PARSE_ERROR) {
boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return from); // should never reach
}
dd = duration_type(static_cast<special_values>(mr.current_match));
}