#ifndef INCLUDED_BOBCAT_EOIBUF_
#define INCLUDED_BOBCAT_EOIBUF_

#include <bobcat/eoi>

namespace FBB
{

class EoiBuf: public Eoi
{
    std::string d_buffer;
    
    protected:
        EoiBuf() = default;
        EoiBuf(size_t size);                                        // 2.f

        void resize(size_t size);

        void setp();
        void setg(unsigned next, unsigned beyond); // begin is fixed

        std::string &buffer();
        size_t bufSize() const;

        unsigned char *ucharPtr();                                  // 1.f
        unsigned char const *ucharPtr() const;                      // 2.f

        static unsigned char *ucharPtr(std::string &str);           // 3.f
        static unsigned char const *ucharPtr(                       // 4.f
                                       std::string const &str);
};

inline EoiBuf::EoiBuf(size_t size)
:
    d_buffer(size, 0)    
{}
inline std::string &EoiBuf::buffer()
{
    return d_buffer;
}
inline size_t EoiBuf::bufSize() const
{
    return d_buffer.length();
}
inline void EoiBuf::resize(size_t size)
{
    d_buffer.resize(size);
}

inline unsigned char *EoiBuf::ucharPtr()
{
    return reinterpret_cast<unsigned char *>(&d_buffer[0]);
}
inline unsigned char const *EoiBuf::ucharPtr() const
{
    return reinterpret_cast<unsigned char const *>(&d_buffer[0]);
}

// static
inline unsigned char *EoiBuf::ucharPtr(std::string &str)
{
    return reinterpret_cast<unsigned char *>(&str[0]);
}
// static
inline unsigned char const *EoiBuf::ucharPtr(std::string const &str)
{
    return reinterpret_cast<unsigned char const *>(&str[0]);
}


} // FBB        

#endif
