#include <stdlib.h>
#include <stdio.h>

#include "DataContainers.h"
#include "Exceptions.h"

MATRIX::MATRIX(int r, int c) {
    rows = r;
    cols = c;
    data = (double**)calloc(r, sizeof(double*));
    for (int i = 0; i < r; i++) {
        data[i] = (double*)calloc(c, sizeof(double));
    }
    isEmpty = true;
}

void MATRIX::printMatrix(void) {
    printf("MATRIX:\n");
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            printf("%15.2f", data[i][j]);
        }
        printf("\n");
    }
    printf("\n");
}

VECTOR::VECTOR(int s) {
    size = s;
    data = (double*)calloc(s, sizeof(double));
    for (int i = 0; i < size; i++) {
        data[i] = 0;
    }
    isEmpty = true;
}

void VECTOR::printVector(void) {
    printf("\n");
    for (int i = 0; i < size; i++) {
        printf("%15.10f\n", data[i]);
    }
    printf("\n");
}

SCALAR::SCALAR(double s) {
    data = s;
    isEmpty = true;
}

void SCALAR::printScalar() {
    printf("OBJECTIVE VALUE: %15.2f\n\n", data);
}

MATRIX::~MATRIX() {
    for (int i = 0; i < rows; i++) {
        free(data[i]);
    }
    free(data);
    data = NULL;
}

VECTOR::~VECTOR() {
    free(data);
    data = NULL;
}
