head	1.5;
access;
symbols
	RELENG_9_1_0_RELEASE:1.2.2.2
	RELENG_9_1:1.2.2.2.0.2
	RELENG_9_1_BP:1.2.2.2
	RELENG_9:1.2.0.2;
locks; strict;
comment	@# @;


1.5
date	2013.04.28.00.41.54;	author svnexp;	state Exp;
branches;
next	1.4;

1.4
date	2012.11.17.03.36.33;	author svnexp;	state Exp;
branches;
next	1.3;

1.3
date	2012.10.22.18.25.04;	author dim;	state Exp;
branches;
next	1.2;

1.2
date	2012.03.14.00.09.36;	author theraven;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2011.11.25.20.59.04;	author theraven;	state Exp;
branches;
next	;

1.2.2.1
date	2012.05.22.18.30.14;	author theraven;	state dead;
branches;
next	1.2.2.2;

1.2.2.2
date	2012.05.22.18.30.14;	author theraven;	state Exp;
branches;
next	1.2.2.3;

1.2.2.3
date	2012.11.21.18.41.40;	author svnexp;	state Exp;
branches;
next	1.2.2.4;

1.2.2.4
date	2012.11.29.21.29.14;	author svnexp;	state Exp;
branches;
next	1.2.2.5;

1.2.2.5
date	2013.05.11.17.01.44;	author svnexp;	state Exp;
branches;
next	1.2.2.6;

1.2.2.6
date	2014.03.05.20.01.45;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.5
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/249998
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@// -*- C++ -*-
//===---------------------------- ios -------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_IOS
#define _LIBCPP_IOS

/*
    ios synopsis

#include <iosfwd>

namespace std
{

typedef OFF_T streamoff;
typedef SZ_T streamsize;
template <class stateT> class fpos;

class ios_base
{
public:
    class failure;

    typedef T1 fmtflags;
    static constexpr fmtflags boolalpha;
    static constexpr fmtflags dec;
    static constexpr fmtflags fixed;
    static constexpr fmtflags hex;
    static constexpr fmtflags internal;
    static constexpr fmtflags left;
    static constexpr fmtflags oct;
    static constexpr fmtflags right;
    static constexpr fmtflags scientific;
    static constexpr fmtflags showbase;
    static constexpr fmtflags showpoint;
    static constexpr fmtflags showpos;
    static constexpr fmtflags skipws;
    static constexpr fmtflags unitbuf;
    static constexpr fmtflags uppercase;
    static constexpr fmtflags adjustfield;
    static constexpr fmtflags basefield;
    static constexpr fmtflags floatfield;

    typedef T2 iostate;
    static constexpr iostate badbit;
    static constexpr iostate eofbit;
    static constexpr iostate failbit;
    static constexpr iostate goodbit;

    typedef T3 openmode;
    static constexpr openmode app;
    static constexpr openmode ate;
    static constexpr openmode binary;
    static constexpr openmode in;
    static constexpr openmode out;
    static constexpr openmode trunc;

    typedef T4 seekdir;
    static constexpr seekdir beg;
    static constexpr seekdir cur;
    static constexpr seekdir end;

    class Init;

    // 27.5.2.2 fmtflags state:
    fmtflags flags() const;
    fmtflags flags(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl, fmtflags mask);
    void unsetf(fmtflags mask);

    streamsize precision() const;
    streamsize precision(streamsize prec);
    streamsize width() const;
    streamsize width(streamsize wide);

    // 27.5.2.3 locales:
    locale imbue(const locale& loc);
    locale getloc() const;

    // 27.5.2.5 storage:
    static int xalloc();
    long& iword(int index);
    void*& pword(int index);

    // destructor
    virtual ~ios_base();

    // 27.5.2.6 callbacks;
    enum event { erase_event, imbue_event, copyfmt_event };
    typedef void (*event_callback)(event, ios_base&, int index);
    void register_callback(event_callback fn, int index);

    ios_base(const ios_base&) = delete;
    ios_base& operator=(const ios_base&) = delete;

    static bool sync_with_stdio(bool sync = true);

protected:
    ios_base();
};

template <class charT, class traits = char_traits<charT> >
class basic_ios
    : public ios_base
{
public:
    // types:
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;

    operator unspecified-bool-type() const;
    bool operator!() const;
    iostate rdstate() const;
    void clear(iostate state = goodbit);
    void setstate(iostate state);
    bool good() const;
    bool eof() const;
    bool fail() const;
    bool bad() const;

    iostate exceptions() const;
    void exceptions(iostate except);

    // 27.5.4.1 Constructor/destructor:
    explicit basic_ios(basic_streambuf<charT,traits>* sb);
    virtual ~basic_ios();

    // 27.5.4.2 Members:
    basic_ostream<charT,traits>* tie() const;
    basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);

    basic_streambuf<charT,traits>* rdbuf() const;
    basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);

    basic_ios& copyfmt(const basic_ios& rhs);

    char_type fill() const;
    char_type fill(char_type ch);

    locale imbue(const locale& loc);

    char narrow(char_type c, char dfault) const;
    char_type widen(char c) const;

    basic_ios(const basic_ios& ) = delete;
    basic_ios& operator=(const basic_ios&) = delete;

protected:
    basic_ios();
    void init(basic_streambuf<charT,traits>* sb);
    void move(basic_ios& rhs);
    void swap(basic_ios& rhs) noexcept;
    void set_rdbuf(basic_streambuf<charT, traits>* sb);
};

// 27.5.5, manipulators:
ios_base& boolalpha (ios_base& str);
ios_base& noboolalpha(ios_base& str);
ios_base& showbase (ios_base& str);
ios_base& noshowbase (ios_base& str);
ios_base& showpoint (ios_base& str);
ios_base& noshowpoint(ios_base& str);
ios_base& showpos (ios_base& str);
ios_base& noshowpos (ios_base& str);
ios_base& skipws (ios_base& str);
ios_base& noskipws (ios_base& str);
ios_base& uppercase (ios_base& str);
ios_base& nouppercase(ios_base& str);
ios_base& unitbuf (ios_base& str);
ios_base& nounitbuf (ios_base& str);

// 27.5.5.2 adjustfield:
ios_base& internal (ios_base& str);
ios_base& left (ios_base& str);
ios_base& right (ios_base& str);

// 27.5.5.3 basefield:
ios_base& dec (ios_base& str);
ios_base& hex (ios_base& str);
ios_base& oct (ios_base& str);

// 27.5.5.4 floatfield:
ios_base& fixed (ios_base& str);
ios_base& scientific (ios_base& str);
ios_base& hexfloat (ios_base& str);
ios_base& defaultfloat(ios_base& str);

// 27.5.5.5 error reporting:
enum class io_errc
{
    stream = 1
};

concept_map ErrorCodeEnum<io_errc> { };
error_code make_error_code(io_errc e);
error_condition make_error_condition(io_errc e);
storage-class-specifier const error_category& iostream_category;

}  // std

*/

#include <__config>
#include <iosfwd>
#include <__locale>
#include <system_error>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

typedef ptrdiff_t streamsize;

class _LIBCPP_TYPE_VIS ios_base
{
public:
    class _LIBCPP_TYPE_VIS failure;

    typedef unsigned int fmtflags;
    static const fmtflags boolalpha   = 0x0001;
    static const fmtflags dec         = 0x0002;
    static const fmtflags fixed       = 0x0004;
    static const fmtflags hex         = 0x0008;
    static const fmtflags internal    = 0x0010;
    static const fmtflags left        = 0x0020;
    static const fmtflags oct         = 0x0040;
    static const fmtflags right       = 0x0080;
    static const fmtflags scientific  = 0x0100;
    static const fmtflags showbase    = 0x0200;
    static const fmtflags showpoint   = 0x0400;
    static const fmtflags showpos     = 0x0800;
    static const fmtflags skipws      = 0x1000;
    static const fmtflags unitbuf     = 0x2000;
    static const fmtflags uppercase   = 0x4000;
    static const fmtflags adjustfield = left | right | internal;
    static const fmtflags basefield   = dec | oct | hex;
    static const fmtflags floatfield  = scientific | fixed;

    typedef unsigned int iostate;
    typedef iostate      io_state;
    static const iostate badbit  = 0x1;
    static const iostate eofbit  = 0x2;
    static const iostate failbit = 0x4;
    static const iostate goodbit = 0x0;

    typedef unsigned int openmode;
    typedef openmode     open_mode;
    static const openmode app    = 0x01;
    static const openmode ate    = 0x02;
    static const openmode binary = 0x04;
    static const openmode in     = 0x08;
    static const openmode out    = 0x10;
    static const openmode trunc  = 0x20;

    enum seekdir {beg, cur, end};
    typedef seekdir seek_dir;

    typedef _VSTD::streamoff streamoff;
    typedef _VSTD::streampos streampos;

    class _LIBCPP_TYPE_VIS Init;

    // 27.5.2.2 fmtflags state:
    _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
    _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
    _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);

    _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
    _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
    _LIBCPP_INLINE_VISIBILITY streamsize width() const;
    _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);

    // 27.5.2.3 locales:
    locale imbue(const locale& __loc);
    locale getloc() const;

    // 27.5.2.5 storage:
    static int xalloc();
    long& iword(int __index);
    void*& pword(int __index);

    // destructor
    virtual ~ios_base();

    // 27.5.2.6 callbacks;
    enum event { erase_event, imbue_event, copyfmt_event };
    typedef void (*event_callback)(event, ios_base&, int __index);
    void register_callback(event_callback __fn, int __index);

private:
    ios_base(const ios_base&); // = delete;
    ios_base& operator=(const ios_base&); // = delete;

public:
    static bool sync_with_stdio(bool __sync = true);

    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
    void clear(iostate __state = goodbit);
    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);

    _LIBCPP_INLINE_VISIBILITY bool good() const;
    _LIBCPP_INLINE_VISIBILITY bool eof() const;
    _LIBCPP_INLINE_VISIBILITY bool fail() const;
    _LIBCPP_INLINE_VISIBILITY bool bad() const;

    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __except);

    void __set_badbit_and_consider_rethrow();
    void __set_failbit_and_consider_rethrow();

protected:
    _LIBCPP_INLINE_VISIBILITY
    ios_base() {// purposefully does no initialization
               }

    void init(void* __sb);
    _LIBCPP_ALWAYS_INLINE void* rdbuf() const {return __rdbuf_;}

    _LIBCPP_ALWAYS_INLINE
    void rdbuf(void* __sb)
    {
        __rdbuf_ = __sb;
        clear();
    }

    void __call_callbacks(event);
    void copyfmt(const ios_base&);
    void move(ios_base&);
    void swap(ios_base&) _NOEXCEPT;

    _LIBCPP_ALWAYS_INLINE
    void set_rdbuf(void* __sb)
    {
        __rdbuf_ = __sb;
    }

private:
    // All data members must be scalars
    fmtflags        __fmtflags_;
    streamsize      __precision_;
    streamsize      __width_;
    iostate         __rdstate_;
    iostate         __exceptions_;
    void*           __rdbuf_;
    void*           __loc_;
    event_callback* __fn_;
    int*            __index_;
    size_t          __event_size_;
    size_t          __event_cap_;
    static int      __xindex_;
    long*           __iarray_;
    size_t          __iarray_size_;
    size_t          __iarray_cap_;
    void**          __parray_;
    size_t          __parray_size_;
    size_t          __parray_cap_;
};

//enum class io_errc
_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
{
    stream = 1
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)

template <>
struct _LIBCPP_TYPE_VIS is_error_code_enum<io_errc> : public true_type { };

#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
template <>
struct _LIBCPP_TYPE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
#endif

_LIBCPP_FUNC_VIS
const error_category& iostream_category();

inline _LIBCPP_INLINE_VISIBILITY
error_code
make_error_code(io_errc __e)
{
    return error_code(static_cast<int>(__e), iostream_category());
}

inline _LIBCPP_INLINE_VISIBILITY
error_condition
make_error_condition(io_errc __e)
{
    return error_condition(static_cast<int>(__e), iostream_category());
}

class _LIBCPP_EXCEPTION_ABI ios_base::failure
    : public system_error
{
public:
    explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
    explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
    virtual ~failure() throw();
};

class _LIBCPP_TYPE_VIS ios_base::Init
{
public:
    Init();
    ~Init();
};

// fmtflags

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::flags() const
{
    return __fmtflags_;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::flags(fmtflags __fmtfl)
{
    fmtflags __r = __fmtflags_;
    __fmtflags_ = __fmtfl;
    return __r;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::setf(fmtflags __fmtfl)
{
    fmtflags __r = __fmtflags_;
    __fmtflags_ |= __fmtfl;
    return __r;
}

inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::unsetf(fmtflags __mask)
{
    __fmtflags_ &= ~__mask;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
{
    fmtflags __r = __fmtflags_;
    unsetf(__mask);
    __fmtflags_ |= __fmtfl & __mask;
    return __r;
}

// precision

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::precision() const
{
    return __precision_;
}

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::precision(streamsize __prec)
{
    streamsize __r = __precision_;
    __precision_ = __prec;
    return __r;
}

// width

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::width() const
{
    return __width_;
}

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::width(streamsize __wide)
{
    streamsize __r = __width_;
    __width_ = __wide;
    return __r;
}

// iostate

inline _LIBCPP_INLINE_VISIBILITY
ios_base::iostate
ios_base::rdstate() const
{
    return __rdstate_;
}

inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::setstate(iostate __state)
{
    clear(__rdstate_ | __state);
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::good() const
{
    return __rdstate_ == 0;
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::eof() const
{
    return __rdstate_ & eofbit;
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::fail() const
{
    return __rdstate_ & (failbit | badbit);
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::bad() const
{
    return __rdstate_ & badbit;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::iostate
ios_base::exceptions() const
{
    return __exceptions_;
}

inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::exceptions(iostate __except)
{
    __exceptions_ = __except;
    clear(__rdstate_);
}

template <class _CharT, class _Traits>
class _LIBCPP_TYPE_VIS basic_ios
    : public ios_base
{
public:
    // types:
    typedef _CharT char_type;
    typedef _Traits traits_type;

    typedef typename traits_type::int_type int_type;
    typedef typename traits_type::pos_type pos_type;
    typedef typename traits_type::off_type off_type;

    _LIBCPP_ALWAYS_INLINE
        _LIBCPP_EXPLICIT
        operator bool() const {return !fail();}
    _LIBCPP_ALWAYS_INLINE bool operator!() const    {return  fail();}
    _LIBCPP_ALWAYS_INLINE iostate rdstate() const   {return ios_base::rdstate();}
    _LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);}
    _LIBCPP_ALWAYS_INLINE void setstate(iostate __state) {ios_base::setstate(__state);}
    _LIBCPP_ALWAYS_INLINE bool good() const {return ios_base::good();}
    _LIBCPP_ALWAYS_INLINE bool eof() const  {return ios_base::eof();}
    _LIBCPP_ALWAYS_INLINE bool fail() const {return ios_base::fail();}
    _LIBCPP_ALWAYS_INLINE bool bad() const  {return ios_base::bad();}

    _LIBCPP_ALWAYS_INLINE iostate exceptions() const {return ios_base::exceptions();}
    _LIBCPP_ALWAYS_INLINE void exceptions(iostate __except) {ios_base::exceptions(__except);}

    // 27.5.4.1 Constructor/destructor:
    _LIBCPP_INLINE_VISIBILITY
    explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
    virtual ~basic_ios();

    // 27.5.4.2 Members:
    _LIBCPP_INLINE_VISIBILITY 
    basic_ostream<char_type, traits_type>* tie() const;
    _LIBCPP_INLINE_VISIBILITY 
    basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);

    _LIBCPP_INLINE_VISIBILITY 
    basic_streambuf<char_type, traits_type>* rdbuf() const;
    _LIBCPP_INLINE_VISIBILITY 
    basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);

    basic_ios& copyfmt(const basic_ios& __rhs);

    _LIBCPP_INLINE_VISIBILITY 
    char_type fill() const;
    _LIBCPP_INLINE_VISIBILITY 
    char_type fill(char_type __ch);

    _LIBCPP_INLINE_VISIBILITY 
    locale imbue(const locale& __loc);

    _LIBCPP_INLINE_VISIBILITY 
    char narrow(char_type __c, char __dfault) const;
    _LIBCPP_INLINE_VISIBILITY 
    char_type widen(char __c) const;

protected:
    _LIBCPP_ALWAYS_INLINE
    basic_ios() {// purposefully does no initialization
                }
    _LIBCPP_INLINE_VISIBILITY 
    void init(basic_streambuf<char_type, traits_type>* __sb);

    _LIBCPP_INLINE_VISIBILITY 
    void move(basic_ios& __rhs);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    _LIBCPP_ALWAYS_INLINE
    void move(basic_ios&& __rhs) {move(__rhs);}
#endif
    _LIBCPP_INLINE_VISIBILITY 
    void swap(basic_ios& __rhs) _NOEXCEPT;
    _LIBCPP_INLINE_VISIBILITY 
    void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
private:
    basic_ostream<char_type, traits_type>* __tie_;
     mutable int_type __fill_;
};

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
{
    init(__sb);
}

template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>::~basic_ios()
{
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
{
    ios_base::init(__sb);
    __tie_ = 0;
    __fill_ = traits_type::eof();
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::tie() const
{
    return __tie_;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
{
    basic_ostream<char_type, traits_type>* __r = __tie_;
    __tie_ = __tiestr;
    return __r;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf() const
{
    return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
{
    basic_streambuf<char_type, traits_type>* __r = rdbuf();
    ios_base::rdbuf(__sb);
    return __r;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
locale
basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
{
    locale __r = getloc();
    ios_base::imbue(__loc);
    if (rdbuf())
        rdbuf()->pubimbue(__loc);
    return __r;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
char
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
{
    return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
    return use_facet<ctype<char_type> >(getloc()).widen(__c);
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill() const
{
    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
        __fill_ = widen(' ');
    return __fill_;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill(char_type __ch)
{
    char_type __r = __fill_;
    __fill_ = __ch;
    return __r;
}

template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>&
basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
{
    if (this != &__rhs)
    {
        __call_callbacks(erase_event);
        ios_base::copyfmt(__rhs);
        __tie_ = __rhs.__tie_;
        __fill_ = __rhs.__fill_;
        __call_callbacks(copyfmt_event);
        exceptions(__rhs.exceptions());
    }
    return *this;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
{
    ios_base::move(__rhs);
    __tie_ = __rhs.__tie_;
    __rhs.__tie_ = 0;
    __fill_ = __rhs.__fill_;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
{
    ios_base::swap(__rhs);
    _VSTD::swap(__tie_, __rhs.__tie_);
    _VSTD::swap(__fill_, __rhs.__fill_);
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
{
    ios_base::set_rdbuf(__sb);
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
boolalpha(ios_base& __str)
{
    __str.setf(ios_base::boolalpha);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noboolalpha(ios_base& __str)
{
    __str.unsetf(ios_base::boolalpha);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showbase(ios_base& __str)
{
    __str.setf(ios_base::showbase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowbase(ios_base& __str)
{
    __str.unsetf(ios_base::showbase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showpoint(ios_base& __str)
{
    __str.setf(ios_base::showpoint);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowpoint(ios_base& __str)
{
    __str.unsetf(ios_base::showpoint);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showpos(ios_base& __str)
{
    __str.setf(ios_base::showpos);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowpos(ios_base& __str)
{
    __str.unsetf(ios_base::showpos);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
skipws(ios_base& __str)
{
    __str.setf(ios_base::skipws);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noskipws(ios_base& __str)
{
    __str.unsetf(ios_base::skipws);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
uppercase(ios_base& __str)
{
    __str.setf(ios_base::uppercase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
nouppercase(ios_base& __str)
{
    __str.unsetf(ios_base::uppercase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
unitbuf(ios_base& __str)
{
    __str.setf(ios_base::unitbuf);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
nounitbuf(ios_base& __str)
{
    __str.unsetf(ios_base::unitbuf);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
internal(ios_base& __str)
{
    __str.setf(ios_base::internal, ios_base::adjustfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
left(ios_base& __str)
{
    __str.setf(ios_base::left, ios_base::adjustfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
right(ios_base& __str)
{
    __str.setf(ios_base::right, ios_base::adjustfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
dec(ios_base& __str)
{
    __str.setf(ios_base::dec, ios_base::basefield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
hex(ios_base& __str)
{
    __str.setf(ios_base::hex, ios_base::basefield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
oct(ios_base& __str)
{
    __str.setf(ios_base::oct, ios_base::basefield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
fixed(ios_base& __str)
{
    __str.setf(ios_base::fixed, ios_base::floatfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
scientific(ios_base& __str)
{
    __str.setf(ios_base::scientific, ios_base::floatfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
hexfloat(ios_base& __str)
{
    __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
defaultfloat(ios_base& __str)
{
    __str.unsetf(ios_base::floatfield);
    return __str;
}

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP_IOS
@


1.4
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/242945
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242945 | theraven | 2012-11-13 03:27:43 +0000 (Tue, 13 Nov 2012) | 2 lines
## SVN ##
## SVN ## Import new version of libc++ into base.
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d227 1
a227 1
class _LIBCPP_VISIBLE ios_base
d230 1
a230 1
    class _LIBCPP_VISIBLE failure;
d274 1
a274 1
    class _LIBCPP_VISIBLE Init;
d383 1
a383 1
struct _LIBCPP_VISIBLE is_error_code_enum<io_errc> : public true_type { };
d387 1
a387 1
struct _LIBCPP_VISIBLE is_error_code_enum<io_errc::__lx> : public true_type { };
d390 1
a390 1
_LIBCPP_VISIBLE
d416 1
a416 1
class _LIBCPP_VISIBLE ios_base::Init
d563 1
a563 1
class _LIBCPP_VISIBLE basic_ios
@


1.3
log
@SVN rev 241903 on 2012-10-22 18:25:04Z by dim

Import libc++ trunk r165949.  Among other improvements and bug fixes,
this has many visibility problems fixed, which should help with
compiling certain ports that exercise C++11 mode (i.e. Firefox).

Also, belatedly add the LICENSE.TXT and accompanying CREDITS.TXT files,
which are referred to in all the source files.

MFC after:	1 month
@
text
@d387 1
a387 1
struct _LIBCPP_VISIBLE is_error_code_enum<io_errc::_> : public true_type { };
@


1.2
log
@SVN rev 232950 on 2012-03-14 00:09:36Z by theraven

Import new versions of libcxxrt and libc++.
Please tests any C++ code you care about with -stdlib=libc++!

Approved by:	dim (mentor)
@
text
@d32 18
a49 18
    static const fmtflags boolalpha;
    static const fmtflags dec;
    static const fmtflags fixed;
    static const fmtflags hex;
    static const fmtflags internal;
    static const fmtflags left;
    static const fmtflags oct;
    static const fmtflags right;
    static const fmtflags scientific;
    static const fmtflags showbase;
    static const fmtflags showpoint;
    static const fmtflags showpos;
    static const fmtflags skipws;
    static const fmtflags unitbuf;
    static const fmtflags uppercase;
    static const fmtflags adjustfield;
    static const fmtflags basefield;
    static const fmtflags floatfield;
d52 4
a55 4
    static const iostate badbit;
    static const iostate eofbit;
    static const iostate failbit;
    static const iostate goodbit;
d58 6
a63 6
    static const openmode app;
    static const openmode ate;
    static const openmode binary;
    static const openmode in;
    static const openmode out;
    static const openmode trunc;
d66 3
a68 3
    static const seekdir beg;
    static const seekdir cur;
    static const seekdir end;
d163 1
a163 1
    void swap(basic_ios& rhs);
d230 1
a230 1
    class failure;
d274 1
a274 1
    class Init;
d345 1
a345 1
    void swap(ios_base&);
d635 1
a635 1
    void swap(basic_ios& __rhs);
d640 1
a640 1
    char_type __fill_;
d662 1
a662 1
    __fill_ = widen(' ');
d734 2
d779 1
a779 1
basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs)
@


1.2.2.1
log
@file ios was added on branch RELENG_9 on 2012-05-22 18:32:26 +0000
@
text
@d1 986
@


1.2.2.2
log
@SVN rev 235798 on 2012-05-22 18:30:14Z by theraven

Merged libcxxrt and libc++.  Now available for testing on 9-stable with
-stdlib=libc++.  Changes to libstdc++ not yet merged, so it is not yet possible
to mix libstdc++ and libc++ in the same program.

Merged revisions: 226702,226785,227006,227755,227983,227987,228531,228630,228761,229067,230127,232950,233098,234715-234716,234772
@
text
@a0 986
// -*- C++ -*-
//===---------------------------- ios -------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_IOS
#define _LIBCPP_IOS

/*
    ios synopsis

#include <iosfwd>

namespace std
{

typedef OFF_T streamoff;
typedef SZ_T streamsize;
template <class stateT> class fpos;

class ios_base
{
public:
    class failure;

    typedef T1 fmtflags;
    static const fmtflags boolalpha;
    static const fmtflags dec;
    static const fmtflags fixed;
    static const fmtflags hex;
    static const fmtflags internal;
    static const fmtflags left;
    static const fmtflags oct;
    static const fmtflags right;
    static const fmtflags scientific;
    static const fmtflags showbase;
    static const fmtflags showpoint;
    static const fmtflags showpos;
    static const fmtflags skipws;
    static const fmtflags unitbuf;
    static const fmtflags uppercase;
    static const fmtflags adjustfield;
    static const fmtflags basefield;
    static const fmtflags floatfield;

    typedef T2 iostate;
    static const iostate badbit;
    static const iostate eofbit;
    static const iostate failbit;
    static const iostate goodbit;

    typedef T3 openmode;
    static const openmode app;
    static const openmode ate;
    static const openmode binary;
    static const openmode in;
    static const openmode out;
    static const openmode trunc;

    typedef T4 seekdir;
    static const seekdir beg;
    static const seekdir cur;
    static const seekdir end;

    class Init;

    // 27.5.2.2 fmtflags state:
    fmtflags flags() const;
    fmtflags flags(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl, fmtflags mask);
    void unsetf(fmtflags mask);

    streamsize precision() const;
    streamsize precision(streamsize prec);
    streamsize width() const;
    streamsize width(streamsize wide);

    // 27.5.2.3 locales:
    locale imbue(const locale& loc);
    locale getloc() const;

    // 27.5.2.5 storage:
    static int xalloc();
    long& iword(int index);
    void*& pword(int index);

    // destructor
    virtual ~ios_base();

    // 27.5.2.6 callbacks;
    enum event { erase_event, imbue_event, copyfmt_event };
    typedef void (*event_callback)(event, ios_base&, int index);
    void register_callback(event_callback fn, int index);

    ios_base(const ios_base&) = delete;
    ios_base& operator=(const ios_base&) = delete;

    static bool sync_with_stdio(bool sync = true);

protected:
    ios_base();
};

template <class charT, class traits = char_traits<charT> >
class basic_ios
    : public ios_base
{
public:
    // types:
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;

    operator unspecified-bool-type() const;
    bool operator!() const;
    iostate rdstate() const;
    void clear(iostate state = goodbit);
    void setstate(iostate state);
    bool good() const;
    bool eof() const;
    bool fail() const;
    bool bad() const;

    iostate exceptions() const;
    void exceptions(iostate except);

    // 27.5.4.1 Constructor/destructor:
    explicit basic_ios(basic_streambuf<charT,traits>* sb);
    virtual ~basic_ios();

    // 27.5.4.2 Members:
    basic_ostream<charT,traits>* tie() const;
    basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);

    basic_streambuf<charT,traits>* rdbuf() const;
    basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);

    basic_ios& copyfmt(const basic_ios& rhs);

    char_type fill() const;
    char_type fill(char_type ch);

    locale imbue(const locale& loc);

    char narrow(char_type c, char dfault) const;
    char_type widen(char c) const;

    basic_ios(const basic_ios& ) = delete;
    basic_ios& operator=(const basic_ios&) = delete;

protected:
    basic_ios();
    void init(basic_streambuf<charT,traits>* sb);
    void move(basic_ios& rhs);
    void swap(basic_ios& rhs);
    void set_rdbuf(basic_streambuf<charT, traits>* sb);
};

// 27.5.5, manipulators:
ios_base& boolalpha (ios_base& str);
ios_base& noboolalpha(ios_base& str);
ios_base& showbase (ios_base& str);
ios_base& noshowbase (ios_base& str);
ios_base& showpoint (ios_base& str);
ios_base& noshowpoint(ios_base& str);
ios_base& showpos (ios_base& str);
ios_base& noshowpos (ios_base& str);
ios_base& skipws (ios_base& str);
ios_base& noskipws (ios_base& str);
ios_base& uppercase (ios_base& str);
ios_base& nouppercase(ios_base& str);
ios_base& unitbuf (ios_base& str);
ios_base& nounitbuf (ios_base& str);

// 27.5.5.2 adjustfield:
ios_base& internal (ios_base& str);
ios_base& left (ios_base& str);
ios_base& right (ios_base& str);

// 27.5.5.3 basefield:
ios_base& dec (ios_base& str);
ios_base& hex (ios_base& str);
ios_base& oct (ios_base& str);

// 27.5.5.4 floatfield:
ios_base& fixed (ios_base& str);
ios_base& scientific (ios_base& str);
ios_base& hexfloat (ios_base& str);
ios_base& defaultfloat(ios_base& str);

// 27.5.5.5 error reporting:
enum class io_errc
{
    stream = 1
};

concept_map ErrorCodeEnum<io_errc> { };
error_code make_error_code(io_errc e);
error_condition make_error_condition(io_errc e);
storage-class-specifier const error_category& iostream_category;

}  // std

*/

#include <__config>
#include <iosfwd>
#include <__locale>
#include <system_error>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

typedef ptrdiff_t streamsize;

class _LIBCPP_VISIBLE ios_base
{
public:
    class failure;

    typedef unsigned int fmtflags;
    static const fmtflags boolalpha   = 0x0001;
    static const fmtflags dec         = 0x0002;
    static const fmtflags fixed       = 0x0004;
    static const fmtflags hex         = 0x0008;
    static const fmtflags internal    = 0x0010;
    static const fmtflags left        = 0x0020;
    static const fmtflags oct         = 0x0040;
    static const fmtflags right       = 0x0080;
    static const fmtflags scientific  = 0x0100;
    static const fmtflags showbase    = 0x0200;
    static const fmtflags showpoint   = 0x0400;
    static const fmtflags showpos     = 0x0800;
    static const fmtflags skipws      = 0x1000;
    static const fmtflags unitbuf     = 0x2000;
    static const fmtflags uppercase   = 0x4000;
    static const fmtflags adjustfield = left | right | internal;
    static const fmtflags basefield   = dec | oct | hex;
    static const fmtflags floatfield  = scientific | fixed;

    typedef unsigned int iostate;
    typedef iostate      io_state;
    static const iostate badbit  = 0x1;
    static const iostate eofbit  = 0x2;
    static const iostate failbit = 0x4;
    static const iostate goodbit = 0x0;

    typedef unsigned int openmode;
    typedef openmode     open_mode;
    static const openmode app    = 0x01;
    static const openmode ate    = 0x02;
    static const openmode binary = 0x04;
    static const openmode in     = 0x08;
    static const openmode out    = 0x10;
    static const openmode trunc  = 0x20;

    enum seekdir {beg, cur, end};
    typedef seekdir seek_dir;

    typedef _VSTD::streamoff streamoff;
    typedef _VSTD::streampos streampos;

    class Init;

    // 27.5.2.2 fmtflags state:
    _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
    _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
    _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);

    _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
    _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
    _LIBCPP_INLINE_VISIBILITY streamsize width() const;
    _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);

    // 27.5.2.3 locales:
    locale imbue(const locale& __loc);
    locale getloc() const;

    // 27.5.2.5 storage:
    static int xalloc();
    long& iword(int __index);
    void*& pword(int __index);

    // destructor
    virtual ~ios_base();

    // 27.5.2.6 callbacks;
    enum event { erase_event, imbue_event, copyfmt_event };
    typedef void (*event_callback)(event, ios_base&, int __index);
    void register_callback(event_callback __fn, int __index);

private:
    ios_base(const ios_base&); // = delete;
    ios_base& operator=(const ios_base&); // = delete;

public:
    static bool sync_with_stdio(bool __sync = true);

    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
    void clear(iostate __state = goodbit);
    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);

    _LIBCPP_INLINE_VISIBILITY bool good() const;
    _LIBCPP_INLINE_VISIBILITY bool eof() const;
    _LIBCPP_INLINE_VISIBILITY bool fail() const;
    _LIBCPP_INLINE_VISIBILITY bool bad() const;

    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __except);

    void __set_badbit_and_consider_rethrow();
    void __set_failbit_and_consider_rethrow();

protected:
    _LIBCPP_INLINE_VISIBILITY
    ios_base() {// purposefully does no initialization
               }

    void init(void* __sb);
    _LIBCPP_ALWAYS_INLINE void* rdbuf() const {return __rdbuf_;}

    _LIBCPP_ALWAYS_INLINE
    void rdbuf(void* __sb)
    {
        __rdbuf_ = __sb;
        clear();
    }

    void __call_callbacks(event);
    void copyfmt(const ios_base&);
    void move(ios_base&);
    void swap(ios_base&);

    _LIBCPP_ALWAYS_INLINE
    void set_rdbuf(void* __sb)
    {
        __rdbuf_ = __sb;
    }

private:
    // All data members must be scalars
    fmtflags        __fmtflags_;
    streamsize      __precision_;
    streamsize      __width_;
    iostate         __rdstate_;
    iostate         __exceptions_;
    void*           __rdbuf_;
    void*           __loc_;
    event_callback* __fn_;
    int*            __index_;
    size_t          __event_size_;
    size_t          __event_cap_;
    static int      __xindex_;
    long*           __iarray_;
    size_t          __iarray_size_;
    size_t          __iarray_cap_;
    void**          __parray_;
    size_t          __parray_size_;
    size_t          __parray_cap_;
};

//enum class io_errc
_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
{
    stream = 1
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)

template <>
struct _LIBCPP_VISIBLE is_error_code_enum<io_errc> : public true_type { };

#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
template <>
struct _LIBCPP_VISIBLE is_error_code_enum<io_errc::_> : public true_type { };
#endif

_LIBCPP_VISIBLE
const error_category& iostream_category();

inline _LIBCPP_INLINE_VISIBILITY
error_code
make_error_code(io_errc __e)
{
    return error_code(static_cast<int>(__e), iostream_category());
}

inline _LIBCPP_INLINE_VISIBILITY
error_condition
make_error_condition(io_errc __e)
{
    return error_condition(static_cast<int>(__e), iostream_category());
}

class _LIBCPP_EXCEPTION_ABI ios_base::failure
    : public system_error
{
public:
    explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
    explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
    virtual ~failure() throw();
};

class _LIBCPP_VISIBLE ios_base::Init
{
public:
    Init();
    ~Init();
};

// fmtflags

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::flags() const
{
    return __fmtflags_;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::flags(fmtflags __fmtfl)
{
    fmtflags __r = __fmtflags_;
    __fmtflags_ = __fmtfl;
    return __r;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::setf(fmtflags __fmtfl)
{
    fmtflags __r = __fmtflags_;
    __fmtflags_ |= __fmtfl;
    return __r;
}

inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::unsetf(fmtflags __mask)
{
    __fmtflags_ &= ~__mask;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
{
    fmtflags __r = __fmtflags_;
    unsetf(__mask);
    __fmtflags_ |= __fmtfl & __mask;
    return __r;
}

// precision

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::precision() const
{
    return __precision_;
}

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::precision(streamsize __prec)
{
    streamsize __r = __precision_;
    __precision_ = __prec;
    return __r;
}

// width

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::width() const
{
    return __width_;
}

inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::width(streamsize __wide)
{
    streamsize __r = __width_;
    __width_ = __wide;
    return __r;
}

// iostate

inline _LIBCPP_INLINE_VISIBILITY
ios_base::iostate
ios_base::rdstate() const
{
    return __rdstate_;
}

inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::setstate(iostate __state)
{
    clear(__rdstate_ | __state);
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::good() const
{
    return __rdstate_ == 0;
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::eof() const
{
    return __rdstate_ & eofbit;
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::fail() const
{
    return __rdstate_ & (failbit | badbit);
}

inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::bad() const
{
    return __rdstate_ & badbit;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base::iostate
ios_base::exceptions() const
{
    return __exceptions_;
}

inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::exceptions(iostate __except)
{
    __exceptions_ = __except;
    clear(__rdstate_);
}

template <class _CharT, class _Traits>
class _LIBCPP_VISIBLE basic_ios
    : public ios_base
{
public:
    // types:
    typedef _CharT char_type;
    typedef _Traits traits_type;

    typedef typename traits_type::int_type int_type;
    typedef typename traits_type::pos_type pos_type;
    typedef typename traits_type::off_type off_type;

    _LIBCPP_ALWAYS_INLINE
        _LIBCPP_EXPLICIT
        operator bool() const {return !fail();}
    _LIBCPP_ALWAYS_INLINE bool operator!() const    {return  fail();}
    _LIBCPP_ALWAYS_INLINE iostate rdstate() const   {return ios_base::rdstate();}
    _LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);}
    _LIBCPP_ALWAYS_INLINE void setstate(iostate __state) {ios_base::setstate(__state);}
    _LIBCPP_ALWAYS_INLINE bool good() const {return ios_base::good();}
    _LIBCPP_ALWAYS_INLINE bool eof() const  {return ios_base::eof();}
    _LIBCPP_ALWAYS_INLINE bool fail() const {return ios_base::fail();}
    _LIBCPP_ALWAYS_INLINE bool bad() const  {return ios_base::bad();}

    _LIBCPP_ALWAYS_INLINE iostate exceptions() const {return ios_base::exceptions();}
    _LIBCPP_ALWAYS_INLINE void exceptions(iostate __except) {ios_base::exceptions(__except);}

    // 27.5.4.1 Constructor/destructor:
    _LIBCPP_INLINE_VISIBILITY
    explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
    virtual ~basic_ios();

    // 27.5.4.2 Members:
    _LIBCPP_INLINE_VISIBILITY 
    basic_ostream<char_type, traits_type>* tie() const;
    _LIBCPP_INLINE_VISIBILITY 
    basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);

    _LIBCPP_INLINE_VISIBILITY 
    basic_streambuf<char_type, traits_type>* rdbuf() const;
    _LIBCPP_INLINE_VISIBILITY 
    basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);

    basic_ios& copyfmt(const basic_ios& __rhs);

    _LIBCPP_INLINE_VISIBILITY 
    char_type fill() const;
    _LIBCPP_INLINE_VISIBILITY 
    char_type fill(char_type __ch);

    _LIBCPP_INLINE_VISIBILITY 
    locale imbue(const locale& __loc);

    _LIBCPP_INLINE_VISIBILITY 
    char narrow(char_type __c, char __dfault) const;
    _LIBCPP_INLINE_VISIBILITY 
    char_type widen(char __c) const;

protected:
    _LIBCPP_ALWAYS_INLINE
    basic_ios() {// purposefully does no initialization
                }
    _LIBCPP_INLINE_VISIBILITY 
    void init(basic_streambuf<char_type, traits_type>* __sb);

    _LIBCPP_INLINE_VISIBILITY 
    void move(basic_ios& __rhs);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    _LIBCPP_ALWAYS_INLINE
    void move(basic_ios&& __rhs) {move(__rhs);}
#endif
    _LIBCPP_INLINE_VISIBILITY 
    void swap(basic_ios& __rhs);
    _LIBCPP_INLINE_VISIBILITY 
    void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
private:
    basic_ostream<char_type, traits_type>* __tie_;
    char_type __fill_;
};

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
{
    init(__sb);
}

template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>::~basic_ios()
{
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
{
    ios_base::init(__sb);
    __tie_ = 0;
    __fill_ = widen(' ');
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::tie() const
{
    return __tie_;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
{
    basic_ostream<char_type, traits_type>* __r = __tie_;
    __tie_ = __tiestr;
    return __r;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf() const
{
    return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
{
    basic_streambuf<char_type, traits_type>* __r = rdbuf();
    ios_base::rdbuf(__sb);
    return __r;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
locale
basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
{
    locale __r = getloc();
    ios_base::imbue(__loc);
    if (rdbuf())
        rdbuf()->pubimbue(__loc);
    return __r;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
char
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
{
    return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
    return use_facet<ctype<char_type> >(getloc()).widen(__c);
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill() const
{
    return __fill_;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill(char_type __ch)
{
    char_type __r = __fill_;
    __fill_ = __ch;
    return __r;
}

template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>&
basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
{
    if (this != &__rhs)
    {
        __call_callbacks(erase_event);
        ios_base::copyfmt(__rhs);
        __tie_ = __rhs.__tie_;
        __fill_ = __rhs.__fill_;
        __call_callbacks(copyfmt_event);
        exceptions(__rhs.exceptions());
    }
    return *this;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
{
    ios_base::move(__rhs);
    __tie_ = __rhs.__tie_;
    __rhs.__tie_ = 0;
    __fill_ = __rhs.__fill_;
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs)
{
    ios_base::swap(__rhs);
    _VSTD::swap(__tie_, __rhs.__tie_);
    _VSTD::swap(__fill_, __rhs.__fill_);
}

template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
{
    ios_base::set_rdbuf(__sb);
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
boolalpha(ios_base& __str)
{
    __str.setf(ios_base::boolalpha);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noboolalpha(ios_base& __str)
{
    __str.unsetf(ios_base::boolalpha);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showbase(ios_base& __str)
{
    __str.setf(ios_base::showbase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowbase(ios_base& __str)
{
    __str.unsetf(ios_base::showbase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showpoint(ios_base& __str)
{
    __str.setf(ios_base::showpoint);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowpoint(ios_base& __str)
{
    __str.unsetf(ios_base::showpoint);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showpos(ios_base& __str)
{
    __str.setf(ios_base::showpos);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowpos(ios_base& __str)
{
    __str.unsetf(ios_base::showpos);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
skipws(ios_base& __str)
{
    __str.setf(ios_base::skipws);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noskipws(ios_base& __str)
{
    __str.unsetf(ios_base::skipws);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
uppercase(ios_base& __str)
{
    __str.setf(ios_base::uppercase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
nouppercase(ios_base& __str)
{
    __str.unsetf(ios_base::uppercase);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
unitbuf(ios_base& __str)
{
    __str.setf(ios_base::unitbuf);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
nounitbuf(ios_base& __str)
{
    __str.unsetf(ios_base::unitbuf);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
internal(ios_base& __str)
{
    __str.setf(ios_base::internal, ios_base::adjustfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
left(ios_base& __str)
{
    __str.setf(ios_base::left, ios_base::adjustfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
right(ios_base& __str)
{
    __str.setf(ios_base::right, ios_base::adjustfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
dec(ios_base& __str)
{
    __str.setf(ios_base::dec, ios_base::basefield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
hex(ios_base& __str)
{
    __str.setf(ios_base::hex, ios_base::basefield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
oct(ios_base& __str)
{
    __str.setf(ios_base::oct, ios_base::basefield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
fixed(ios_base& __str)
{
    __str.setf(ios_base::fixed, ios_base::floatfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
scientific(ios_base& __str)
{
    __str.setf(ios_base::scientific, ios_base::floatfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
hexfloat(ios_base& __str)
{
    __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
    return __str;
}

inline _LIBCPP_INLINE_VISIBILITY
ios_base&
defaultfloat(ios_base& __str)
{
    __str.unsetf(ios_base::floatfield);
    return __str;
}

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP_IOS
@


1.2.2.3
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 243376
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r243376 | dim | 2012-11-21 18:38:56 +0000 (Wed, 21 Nov 2012) | 14 lines
## SVN ##
## SVN ## MFC r241903:
## SVN ##
## SVN ##   Import libc++ trunk r165949.  Among other improvements and bug fixes,
## SVN ##   this has many visibility problems fixed, which should help with
## SVN ##   compiling certain ports that exercise C++11 mode (i.e. Firefox).
## SVN ##
## SVN ##   Also, belatedly add the LICENSE.TXT and accompanying CREDITS.TXT files,
## SVN ##   which are referred to in all the source files.
## SVN ##
## SVN ## MFC r241907:
## SVN ##
## SVN ##   Fix two -Wsystem-header warnings in libc++ that were exposed by the new
## SVN ##   ATF import.  These have also been sent upstream.
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d32 18
a49 18
    static constexpr fmtflags boolalpha;
    static constexpr fmtflags dec;
    static constexpr fmtflags fixed;
    static constexpr fmtflags hex;
    static constexpr fmtflags internal;
    static constexpr fmtflags left;
    static constexpr fmtflags oct;
    static constexpr fmtflags right;
    static constexpr fmtflags scientific;
    static constexpr fmtflags showbase;
    static constexpr fmtflags showpoint;
    static constexpr fmtflags showpos;
    static constexpr fmtflags skipws;
    static constexpr fmtflags unitbuf;
    static constexpr fmtflags uppercase;
    static constexpr fmtflags adjustfield;
    static constexpr fmtflags basefield;
    static constexpr fmtflags floatfield;
d52 4
a55 4
    static constexpr iostate badbit;
    static constexpr iostate eofbit;
    static constexpr iostate failbit;
    static constexpr iostate goodbit;
d58 6
a63 6
    static constexpr openmode app;
    static constexpr openmode ate;
    static constexpr openmode binary;
    static constexpr openmode in;
    static constexpr openmode out;
    static constexpr openmode trunc;
d66 3
a68 3
    static constexpr seekdir beg;
    static constexpr seekdir cur;
    static constexpr seekdir end;
d163 1
a163 1
    void swap(basic_ios& rhs) noexcept;
d230 1
a230 1
    class _LIBCPP_VISIBLE failure;
d274 1
a274 1
    class _LIBCPP_VISIBLE Init;
d345 1
a345 1
    void swap(ios_base&) _NOEXCEPT;
d635 1
a635 1
    void swap(basic_ios& __rhs) _NOEXCEPT;
d640 1
a640 1
     mutable int_type __fill_;
d662 1
a662 1
    __fill_ = traits_type::eof();
a733 2
    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
        __fill_ = widen(' ');
d777 1
a777 1
basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
@


1.2.2.4
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/243683
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r243683 | dim | 2012-11-29 21:26:57 +0000 (Thu, 29 Nov 2012) | 4 lines
## SVN ##
## SVN ## MFC r242945 (by theraven):
## SVN ##
## SVN ##   Import new version of libc++ into base.
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d387 1
a387 1
struct _LIBCPP_VISIBLE is_error_code_enum<io_errc::__lx> : public true_type { };
@


1.2.2.5
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/250514
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d227 1
a227 1
class _LIBCPP_TYPE_VIS ios_base
d230 1
a230 1
    class _LIBCPP_TYPE_VIS failure;
d274 1
a274 1
    class _LIBCPP_TYPE_VIS Init;
d383 1
a383 1
struct _LIBCPP_TYPE_VIS is_error_code_enum<io_errc> : public true_type { };
d387 1
a387 1
struct _LIBCPP_TYPE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
d390 1
a390 1
_LIBCPP_FUNC_VIS
d416 1
a416 1
class _LIBCPP_TYPE_VIS ios_base::Init
d563 1
a563 1
class _LIBCPP_TYPE_VIS basic_ios
@


1.2.2.6
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/262801
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d206 3
a208 3
error_code make_error_code(io_errc e) noexcept; 
error_condition make_error_condition(io_errc e) noexcept; 
storage-class-specifier const error_category& iostream_category() noexcept;
a218 4
#if __has_feature(cxx_atomic)
#include <atomic>     // for __xindex_
#endif

d322 1
a322 1
    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
a365 3
#if __has_feature(cxx_atomic)
    static atomic<int> __xindex_;
#else
a366 1
#endif
d383 1
a383 1
struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<io_errc> : public true_type { };
d387 1
a387 1
struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<io_errc::__lx> : public true_type { };
d391 1
a391 1
const error_category& iostream_category() _NOEXCEPT;
d395 1
a395 1
make_error_code(io_errc __e) _NOEXCEPT
d402 1
a402 1
make_error_condition(io_errc __e) _NOEXCEPT
d530 1
a530 1
    return (__rdstate_ & eofbit) != 0;
d537 1
a537 1
    return (__rdstate_ & (failbit | badbit)) != 0;
d544 1
a544 1
    return (__rdstate_ & badbit) != 0;
d556 1
a556 1
ios_base::exceptions(iostate __iostate)
d558 1
a558 1
    __exceptions_ = __iostate;
d563 1
a563 1
class _LIBCPP_TYPE_VIS_ONLY basic_ios
d588 1
a588 1
    _LIBCPP_ALWAYS_INLINE void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);}
a985 27
template <class _CharT, class _Traits>
class __save_flags
{
    typedef basic_ios<_CharT, _Traits> __stream_type;
    typedef typename __stream_type::fmtflags fmtflags;

    __stream_type& __stream_;
    fmtflags       __fmtflags_;
    _CharT         __fill_;

    __save_flags(const __save_flags&);
    __save_flags& operator=(const __save_flags&);
public:
    _LIBCPP_INLINE_VISIBILITY
    explicit __save_flags(__stream_type& __stream)
        : __stream_(__stream),
          __fmtflags_(__stream.flags()),
          __fill_(__stream.fill())
        {}
    _LIBCPP_INLINE_VISIBILITY
    ~__save_flags()
    {
        __stream_.flags(__fmtflags_);
        __stream_.fill(__fill_);
    }
};

@


1.1
log
@SVN rev 227983 on 2011-11-25 20:59:04Z by theraven

Import libc++ / libcxxrt into base.  Not build by default yet (use
MK_LIBCPLUSPLUS=yes to enable).  This is a work-in-progress.  It works for
me, but is not guaranteed to work for anyone else and may eat your dog.

To build C++ using libc++, add -stdlib=libc++ to your CXX and LD flags.

Bug reports welcome, bug fixes even more welcome...

Approved by:	dim (mentor)
@
text
@d376 1
a376 1
struct _LIBCPP_VISIBLE io_errc
a377 1
enum _ {
d380 1
a380 5
    _ __v_;

    _LIBCPP_ALWAYS_INLINE io_errc(_ __v) : __v_(__v) {}
    _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;}
};
d384 2
d388 1
d575 2
a576 1
    _LIBCPP_ALWAYS_INLINE // explicit
@

