//
// bitwriters  --  bitwriter specializations
//
// Copyright (c) 2003 by Joergen Ibsen / Jibz
// All Rights Reserved
//
// http://www.ibsensoftware.com/
//

/// @file   bitwriters.hpp
/// @brief  bitwriter specializations.
/// @author Jibz
/// @date   2003.08.02

#ifndef BITWRITERS_HPP_INCLUDED
#define BITWRITERS_HPP_INCLUDED

#include <iostream>
#include <vector>
#include <string>

#include "bitwriter.hpp"

/// @addtogroup bitio
/// @{

/// Specialization without data.
class null_bitwriter : public bitwriter {

public:
    /// Constructor.
    null_bitwriter() { ; }

    ~null_bitwriter() { finalize(); }

protected:
    void write_next_byte(char c) { ; }
};

/// Specialization for streams.
class stream_bitwriter : public bitwriter {

public:
    /// Constructor.
    /// @param _s - the stream to use.
    stream_bitwriter(std::ostream &_s) : s(_s) { ; }

    ~stream_bitwriter() { finalize(); }

protected:
    void write_next_byte(char c) { s.put(c); }

    std::ostream &s;
};

/// Specialization for vector<char>.
class vector_bitwriter : public bitwriter {

public:
    /// Constructor.
    /// @param _s - the vector to use.
    vector_bitwriter(std::vector<char> &_s) : s(_s) { ; }

    ~vector_bitwriter() { finalize(); }

protected:
    void write_next_byte(char c) { s.push_back(c); }

    std::vector<char> &s;
};

/// Specialization for string.
class string_bitwriter : public bitwriter {

public:
    /// Constructor.
    /// @param _s - the string to use.
    string_bitwriter(std::string &_s) : s(_s) { ; }

    ~string_bitwriter() { finalize(); }

protected:
    void write_next_byte(char c) { s += c; }

    std::string &s;
};

/// Specialization for C pointer to char.
class array_bitwriter : public bitwriter {

public:
    /// Constructor.
    /// @param _s - the pointer to use.
    array_bitwriter(char *_s) : s(_s) { ; }

    ~array_bitwriter() { finalize(); }

protected:
    void write_next_byte(char c) { *s++ = c; }

    char *s;
};

/// @}

#endif // BITWRITERS_HPP_INCLUDED
