#include "StockData_Old.h"
#include <algorithm> // For std::copy

// Constructor: Allocate memory for the array
StockData_Old::StockData_Old(size_t size) : size_(size) {
    data_ = new double[size_];
}

// Destructor: Free the allocated memory
StockData_Old::~StockData_Old() {
    delete[] data_;
}

// Copy Constructor: Perform a deep copy
StockData_Old::StockData_Old(const StockData_Old& other) : size_(other.size_) {
    data_ = new double[size_];
    std::copy(other.data_, other.data_ + size_, data_);
}

// Copy Assignment Operator: Handle self-assignment and perform a deep copy
StockData_Old& StockData_Old::operator=(const StockData_Old& other) {
    if (this != &other) { // Protect against self-assignment
        // Free the old memory
        delete[] data_;

        // Allocate new memory and copy data
        size_ = other.size_;
        data_ = new double[size_];
        std::copy(other.data_, other.data_ + size_, data_);
    }
    return *this;
}

// Public method to access data (no bounds checking for simplicity)
double& StockData_Old::at(size_t index) {
    return data_[index];
}
