e8eb99c742
Changes: - Added SharedMemory module for file-backed memory-mapped storage - Added MappingInfo, FileHeader, RecordState and TrackedRecord infrastructure - Added serialized record structures for all domain models - Replaced CSV-based serialization with binary struct serialization - Updated model serialize/deserialize implementations to use serialized records - Added DataStore initialization and shutdown lifecycle management - Added datastore mutex synchronization for multi-process access - Added shared-memory mapping configuration for all datastore entities - Added generic loadRecords and saveRecords template infrastructure - Added automatic datastore directory creation and .dat file storage - Updated configuration to use binary datastore files and initial capacities - Added enum underlying types for serialization compatibility - Added password masking support for login, registration and password change flows - Added Visual Studio project configuration for shared-memory components - Prepared datastore for multi-process shared-memory persistence
308 lines
8.6 KiB
C++
308 lines
8.6 KiB
C++
/*
|
|
File: ComboPackage.cpp
|
|
Description: Implements the ComboPackage class which represents a bundled set of services in the Vehicle Service Management System.
|
|
Provides constructors, accessors, and mutators for package details such as ID, name, discount percentage, state,
|
|
and associated services.
|
|
Author: Trenser
|
|
Date: 19-May-2026
|
|
*/
|
|
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
#include "SerializedRecords.h"
|
|
#include "ComboPackage.h"
|
|
#include "Service.h"
|
|
#include "Factory.h"
|
|
#include "StringHelper.h"
|
|
|
|
int ComboPackage::m_uid = 0;
|
|
|
|
/*
|
|
Function: ComboPackage
|
|
Description: Default constructor that initializes a new combo package with a unique ID,
|
|
active state, and zero discount percentage.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- A new ComboPackage object.
|
|
*/
|
|
ComboPackage::ComboPackage()
|
|
: m_id("CMP" + std::to_string(++m_uid)),
|
|
m_status(util::State::ACTIVE),
|
|
m_discountPercentage(0.0) {}
|
|
|
|
/*
|
|
Function: ComboPackage
|
|
Description: Parameterized constructor that initializes a new combo package with a unique ID,
|
|
specified package name, discount percentage, active state, and associated services.
|
|
Parameters:
|
|
- packageName: Name of the combo package.
|
|
- discountPercentage: Discount percentage applied to the package.
|
|
- services: Map of services included in the package.
|
|
Returns:
|
|
- A new ComboPackage object.
|
|
*/
|
|
ComboPackage::ComboPackage(const std::string& packageName, double discountPercentage, const util::Map<std::string, Service*>& services)
|
|
: m_id("CMP" + std::to_string(++m_uid)),
|
|
m_packageName(packageName),
|
|
m_discountPercentage(discountPercentage),
|
|
m_status(util::State::ACTIVE),
|
|
m_services(services)
|
|
{
|
|
int numberOfServices = m_services.getSize();
|
|
auto servicePointers = m_services.getValues();
|
|
for (int index = 0; index < numberOfServices; index++)
|
|
{
|
|
m_serviceIDs.push_back(servicePointers[index]->getId());
|
|
}
|
|
}
|
|
|
|
/*
|
|
Function: ComboPackage (parameterized constructor with ID)
|
|
Description: Initializes a combo package with an existing ID, name, discount percentage,
|
|
service IDs, and state. Updates UID tracking based on ID.
|
|
Parameters:
|
|
- id: const std::string&, unique ID of the package
|
|
- packageName: const std::string&, name of the package
|
|
- discountPercentage: double, discount percentage applied
|
|
- serviceIDs: const util::Vector<std::string>&, IDs of services included
|
|
- status: util::State, state of the package (ACTIVE/INACTIVE)
|
|
Returns:
|
|
- A new ComboPackage object
|
|
*/
|
|
ComboPackage::ComboPackage(const std::string& id, const std::string& packageName, double discountPercentage, const util::Vector<std::string>& serviceIDs, util::State status)
|
|
: m_id(id),
|
|
m_packageName(packageName),
|
|
m_discountPercentage(discountPercentage),
|
|
m_serviceIDs(serviceIDs),
|
|
m_status(status)
|
|
{
|
|
int idNumber = util::extractNumber(m_id);
|
|
if (idNumber > m_uid)
|
|
{
|
|
m_uid = idNumber;
|
|
}
|
|
}
|
|
|
|
/*
|
|
Function: getId
|
|
Description: Retrieves the unique ID of the combo package.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- const std::string& representing the package ID.
|
|
*/
|
|
const std::string& ComboPackage::getId() const
|
|
{
|
|
return m_id;
|
|
}
|
|
|
|
/*
|
|
Function: getPackageName
|
|
Description: Retrieves the name of the combo package.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- const std::string& representing the package name.
|
|
*/
|
|
const std::string& ComboPackage::getPackageName() const
|
|
{
|
|
return m_packageName;
|
|
}
|
|
|
|
/*
|
|
Function: getDiscountPercentage
|
|
Description: Retrieves the discount percentage applied to the combo package.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- double representing the discount percentage.
|
|
*/
|
|
double ComboPackage::getDiscountPercentage() const
|
|
{
|
|
return m_discountPercentage;
|
|
}
|
|
|
|
/*
|
|
Function: getState
|
|
Description: Retrieves the current state (ACTIVE/INACTIVE) of the combo package.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- util::State representing the package state.
|
|
*/
|
|
util::State ComboPackage::getState() const
|
|
{
|
|
return m_status;
|
|
}
|
|
|
|
const util::Vector<std::string>& ComboPackage::getServiceIDs() const
|
|
{
|
|
return m_serviceIDs;
|
|
}
|
|
|
|
/*
|
|
Function: getServices
|
|
Description: Retrieves the map of services included in the combo package.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- const util::Map<std::string, Service*>& representing the services.
|
|
*/
|
|
const util::Map<std::string, Service*>& ComboPackage::getServices() const
|
|
{
|
|
return m_services;
|
|
}
|
|
|
|
/*
|
|
Function: setId
|
|
Description: Sets the unique ID of the combo package.
|
|
Parameters:
|
|
- id: New ID string.
|
|
Returns:
|
|
- void
|
|
*/
|
|
void ComboPackage::setId(const std::string& id)
|
|
{
|
|
m_id = id;
|
|
}
|
|
|
|
/*
|
|
Function: setPackageName
|
|
Description: Sets the name of the combo package.
|
|
Parameters:
|
|
- packageName: New package name string.
|
|
Returns:
|
|
- void
|
|
*/
|
|
void ComboPackage::setPackageName(const std::string& packageName)
|
|
{
|
|
m_packageName = packageName;
|
|
}
|
|
|
|
/*
|
|
Function: setDiscountPercentage
|
|
Description: Sets the discount percentage for the combo package.
|
|
Parameters:
|
|
- discountPercentage: New discount percentage value.
|
|
Returns:
|
|
- void
|
|
*/
|
|
void ComboPackage::setDiscountPercentage(double discountPercentage)
|
|
{
|
|
m_discountPercentage = discountPercentage;
|
|
}
|
|
|
|
/*
|
|
Function: setServices
|
|
Description: Sets the services included in the combo package.
|
|
Parameters:
|
|
- services: Map of services to be associated with the package.
|
|
Returns:
|
|
- void
|
|
*/
|
|
void ComboPackage::setServices(const util::Map<std::string, Service*>& services)
|
|
{
|
|
m_services = services;
|
|
m_serviceIDs.clear();
|
|
int numberOfServices = m_services.getSize();
|
|
auto servicePointers = m_services.getValues();
|
|
for (int index = 0; index < numberOfServices; index++)
|
|
{
|
|
m_serviceIDs.push_back(servicePointers[index]->getId());
|
|
}
|
|
}
|
|
|
|
/*
|
|
Function: setState
|
|
Description: Sets the state (ACTIVE/INACTIVE) of the combo package.
|
|
Parameters:
|
|
- status: New state value.
|
|
Returns:
|
|
- void
|
|
*/
|
|
void ComboPackage::setState(util::State status)
|
|
{
|
|
m_status = status;
|
|
}
|
|
|
|
/*
|
|
Function: getServiceIDsAsString (static helper)
|
|
Description: Converts a vector of service IDs into a single string separated by '|'.
|
|
Parameters:
|
|
- serviceIDs: const util::Vector<std::string>&, vector of service IDs
|
|
Returns:
|
|
- std::string: Concatenated service IDs string
|
|
*/
|
|
static std::string getServiceIDsAsString(const util::Vector<std::string>& serviceIDs)
|
|
{
|
|
int numberOfServices = serviceIDs.getSize();
|
|
std::string serviceIDsString;
|
|
for (int index = 0; index < numberOfServices; index++)
|
|
{
|
|
serviceIDsString += serviceIDs[index];
|
|
if (index < numberOfServices - 1)
|
|
{
|
|
serviceIDsString += '|';
|
|
}
|
|
}
|
|
return serviceIDsString;
|
|
}
|
|
|
|
/*
|
|
Function: getServiceIDsAsVector (static helper)
|
|
Description: Converts a string of service IDs separated by '|' into a vector.
|
|
Parameters:
|
|
- serviceIDsString: const std::string&, concatenated service IDs string
|
|
Returns:
|
|
- util::Vector<std::string>: Vector of service IDs
|
|
*/
|
|
static util::Vector<std::string> getServiceIDsAsVector(const std::string& serviceIDsString)
|
|
{
|
|
util::Vector<std::string> serviceIDs;
|
|
std::string serviceID;
|
|
std::istringstream serializedServiceIDs(serviceIDsString);
|
|
while (getline(serializedServiceIDs, serviceID, '|'))
|
|
{
|
|
serviceIDs.push_back(serviceID);
|
|
}
|
|
return serviceIDs;
|
|
}
|
|
|
|
/*
|
|
Function: serialize
|
|
Description: Serializes the ComboPackage object into a SerializedComboPackage record.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- SerializedComboPackage: Serialized representation of the combo package
|
|
*/
|
|
SerializedComboPackage ComboPackage::serialize() const
|
|
{
|
|
SerializedComboPackage serialized = {};
|
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
|
strcpy_s(serialized.packageName, sizeof(serialized.packageName), m_packageName.c_str());
|
|
strcpy_s(serialized.serviceIDs, sizeof(serialized.serviceIDs), getServiceIDsAsString(m_serviceIDs).c_str());
|
|
serialized.discountPercentage = m_discountPercentage;
|
|
serialized.status = m_status;
|
|
return serialized;
|
|
}
|
|
|
|
/*
|
|
Function: deserialize
|
|
Description: Deserializes a SerializedComboPackage record into a ComboPackage object.
|
|
Parameters:
|
|
- serializedComboPackage: const SerializedComboPackage&, serialized combo package record
|
|
Returns:
|
|
- ComboPackage*: Pointer to the deserialized ComboPackage object
|
|
*/
|
|
ComboPackage* ComboPackage::deserialize(const SerializedComboPackage& serializedComboPackage)
|
|
{
|
|
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serializedComboPackage.serviceIDs);
|
|
return Factory::getObject<ComboPackage>(
|
|
serializedComboPackage.id,
|
|
serializedComboPackage.packageName,
|
|
serializedComboPackage.discountPercentage,
|
|
serviceIDs,
|
|
serializedComboPackage.status);
|
|
} |