74 lines
2.9 KiB
C++
74 lines
2.9 KiB
C++
/*
|
|
File: DataStore.h
|
|
Description: Declares the DataStore singleton class responsible for managing collections of users, services, combo packages, service bookings, job cards, inventory items, invoices, and payments in the Vehicle Service Management System.
|
|
Author: Trenser
|
|
Date: 19-May-2026
|
|
*/
|
|
|
|
#pragma once
|
|
#include <windows.h>
|
|
#include <string>
|
|
#include "Map.h"
|
|
#include "MappingInfo.h"
|
|
#include "TrackedRecord.h"
|
|
#include "SharedMemory.h"
|
|
class User;
|
|
class Notification;
|
|
class Service;
|
|
class ComboPackage;
|
|
class InventoryItem;
|
|
class ServiceBooking;
|
|
class JobCard;
|
|
class Invoice;
|
|
class Payment;
|
|
|
|
class DataStore
|
|
{
|
|
private:
|
|
DataStore();
|
|
DataStore(const DataStore&) = delete;
|
|
DataStore& operator=(const DataStore&) = delete;
|
|
DataStore(DataStore&&) = delete;
|
|
DataStore& operator=(DataStore&&) = delete;
|
|
bool unlockMutex();
|
|
HANDLE m_globalMutex;
|
|
MappingInfo m_users;
|
|
MappingInfo m_notifications;
|
|
MappingInfo m_services;
|
|
MappingInfo m_comboPackages;
|
|
MappingInfo m_inventoryItems;
|
|
MappingInfo m_serviceBookings;
|
|
MappingInfo m_jobCards;
|
|
MappingInfo m_invoices;
|
|
MappingInfo m_payments;
|
|
public:
|
|
static DataStore& getInstance();
|
|
bool initialize();
|
|
void shutdown();
|
|
util::Map<std::string, TrackedRecord<User>> getUsers();
|
|
util::Map<std::string, TrackedRecord<Notification>> getNotifications();
|
|
util::Map<std::string, TrackedRecord<Service>> getServices();
|
|
util::Map<std::string, TrackedRecord<ComboPackage>> getComboPackages();
|
|
util::Map<std::string, TrackedRecord<InventoryItem>> getInventoryItems();
|
|
util::Map<std::string, TrackedRecord<ServiceBooking>> getServiceBookings();
|
|
util::Map<std::string, TrackedRecord<JobCard>> getJobCards();
|
|
util::Map<std::string, TrackedRecord<Invoice>> getInvoices();
|
|
util::Map<std::string, TrackedRecord<Payment>> getPayments();
|
|
void saveUsers(util::Map<std::string, TrackedRecord<User>>& users);
|
|
void saveNotifications(util::Map<std::string, TrackedRecord<Notification>>& notifications);
|
|
void saveServices(util::Map<std::string, TrackedRecord<Service>>& services);
|
|
void saveComboPackages(util::Map<std::string, TrackedRecord<ComboPackage>>& comboPackages);
|
|
void saveInventoryItems(util::Map<std::string, TrackedRecord<InventoryItem>>& inventoryItems);
|
|
void saveServiceBookings(util::Map<std::string, TrackedRecord<ServiceBooking>>& bookings);
|
|
void saveJobCards(util::Map<std::string, TrackedRecord<JobCard>>& jobCards);
|
|
void saveInvoices(util::Map<std::string, TrackedRecord<Invoice>>& invoices);
|
|
void savePayments(util::Map<std::string, TrackedRecord<Payment>>& payments);
|
|
bool lockDataStore();
|
|
bool unlockDataStore();
|
|
private:
|
|
template<typename TObject, typename TSerialized>
|
|
util::Map<std::string, TrackedRecord<TObject>> loadRecords(MappingInfo& mapping);
|
|
template<typename TObject, typename TSerialized>
|
|
void saveRecords(MappingInfo& mapping, util::Map<std::string, TrackedRecord<TObject>>& records);
|
|
};
|