#ifndef INCLUDED_BOBCAT_X2A_
#define INCLUDED_BOBCAT_X2A_

#include <sstream>
#include <string>

namespace FBB
{
class X2a: public std::ostringstream
{
    static bool s_lastFail;

    public:
        template <typename T>                   // initialize from 
        X2a(T const &x);                        // (insertable) type

        X2a(X2a const &other);

        X2a(double x, size_t behind);
        X2a(double x, size_t width, size_t behind);

        X2a &operator=(X2a const &rhs);
        operator std::string const() const;

        bool lastFail();
};

template <typename T>                   // initialize from 
inline X2a::X2a(T const &x)             // (insertable) type
{
    s_lastFail = (*this << x).fail();
}

inline X2a::X2a(X2a const &other)
:
    std::ostringstream(other.str())
{}

inline X2a::operator std::string const() const
{
    return str();
}

inline X2a &X2a::operator=(X2a const &rhs)
{
    str(rhs.str());
    return *this;
}

inline bool X2a::lastFail()
{
    return s_lastFail;
}

inline std::ostream &operator<<(std::ostream &ostr, X2a const &x2a)
{
    return ostr << x2a.str();
}

} // FBB

#endif
