#include <except.h>

#include <cstring>
#include <cstdio> //vsnprintf
#include <iostream>

using namespace std;

BaseError::~BaseError()
{
    delete[] module;
    delete[] description;
    delete[] severity;
}

BaseError::BaseError()
{
}

void BaseError::Init(const char* sev, const char* mod, const char* f, int l, const char* desc, va_list va)
{
    file=f;
    line=l;
    module=new char[strlen(mod)+1];
    strcpy(module, mod);
    severity=new char[strlen(sev)+1];
    strcpy(severity, sev);
    description=new char[strlen(desc)+256];
    vsnprintf(description, strlen(desc)+256, desc, va);
}

BaseError::BaseError(const BaseError& f)
{
    module=new char[strlen(f.module)+1];
    strcpy(module, f.module);
    description=new char[strlen(f.description)+1];
    strcpy(description, f.description);
    severity=new char[strlen(f.severity)+1];
    strcpy(severity, f.severity);
    file=f.file;
    line=f.line;
}

void BaseError::Print()
{
    std::cerr<<module<<": ";
    std::cerr<<severity;
    std::cerr<<": "<<description<<std::endl;
}

void BaseError::PrintAll()
{
    std::cerr<<module<<": ";
    std::cerr<<severity;
    std::cerr<<": "<<description;
    if(file)std::cerr<<" at "<<file;
    if(line)std::cerr<<":"<<line;
    std::cerr<<std::endl;
}

const char* BaseError::GetModule() const
{
    return module;
}

const char* BaseError::GetDesc() const
{
    return description;
}
