/*
 * lineshuffler.cpp
 *
 * Implementation of the BigInt class.  See header file for function
 * descriptions.
 *
 */

#include "bigint.hpp"

/* Constructor
 */

BigInt::BigInt(int value)
    : chunks_()
{
    while(value != 0) {
        chunks_.push_back(value % CHUNK_SIZE);
	value = value / CHUNK_SIZE;
    }
}


/* Arithmetic Operators
 */

BigInt& BigInt::operator+=(const BigInt& rhs)
{
    // This code is totally inadequate, but serves as a placeholder until
    // the correct code is written.
    chunks_[0] += rhs.chunks_[0];

    return *this;
}


BigInt& BigInt::operator-=(const BigInt& rhs)
{
    // This code is totally inadequate, but serves as a placeholder until
    // the correct code is written.
    chunks_[0] -= rhs.chunks_[0];

    return *this;
}


BigInt& BigInt::operator*=(const BigInt& rhs)
{
    // This code is totally inadequate, but serves as a placeholder until
    // the correct code is written.
    chunks_[0] *= rhs.chunks_[0];

    return *this;
}


BigInt& BigInt::operator/=(const BigInt& rhs)
{
    // This code is totally inadequate, but serves as a placeholder until
    // the correct code is written.
    chunks_[0] /= rhs.chunks_[0];

    return *this;
}

/*
 * Comparison operators.
 */

bool BigInt::operator== (const BigInt& rhs) const
{
    return chunks_ == rhs.chunks_;
}


bool BigInt::operator!= (const BigInt& rhs) const
{
    return chunks_ != rhs.chunks_;
}


/* Output functions
 */

ostream& BigInt::print(ostream& out) const
{
    out << chunks_[0];
    return out;
}


ostream& operator<<(ostream& out, const BigInt& value)
{
    return value.print(out);
}


/* Junk to make emacs use the right C++ style when editing this code:
 *   Local Variables:
 *   c-file-style: "stroustrup"
 *   End:
 */
