3b1f3301d6
Changes: - Added SharedMemory module for file-backed memory-mapped storage - Added MappingInfo, FileHeader, RecordState and TrackedRecord infrastructure - Replaced CSV-based serialization with binary struct serialization - 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 - Added datastore-owned record caches for runtime object management - Updated datastore APIs to return cached tracked-record collections by reference - Added generic cache refresh and cleanup infrastructure - Updated save operations to persist datastore caches directly - Added automatic cache cleanup during datastore destruction - Prepared datastore for multi-process shared-memory persistence
299 lines
7.7 KiB
C++
299 lines
7.7 KiB
C++
/*
|
|
File: Enums.h
|
|
Description: Declares enumerations and utility functions for user types, payment modes, payment status,
|
|
service job status, and state management in the Vehicle Service Management System.
|
|
Provides string conversion and parsing functions for each enum type.
|
|
Author: Trenser
|
|
Date: 19-May-2026
|
|
*/
|
|
|
|
#pragma once
|
|
#include <stdexcept>
|
|
|
|
namespace util
|
|
{
|
|
enum class UserType : int
|
|
{
|
|
ADMIN,
|
|
TECHNICIAN,
|
|
CUSTOMER
|
|
};
|
|
|
|
enum class PaymentMode : int
|
|
{
|
|
ONLINE,
|
|
OFFLINE,
|
|
NOTSET
|
|
};
|
|
|
|
enum class PaymentStatus : int
|
|
{
|
|
PENDING,
|
|
COMPLETED,
|
|
PAID
|
|
};
|
|
|
|
enum class ServiceJobStatus : int
|
|
{
|
|
PENDING,
|
|
STARTED,
|
|
COMPLETED,
|
|
IN_PROGRESS,
|
|
CANCELLED
|
|
};
|
|
|
|
enum class State : int
|
|
{
|
|
ACTIVE,
|
|
INACTIVE
|
|
};
|
|
|
|
/*
|
|
Function: getUserTypeString
|
|
Description: Converts a UserType enum value to its corresponding string representation.
|
|
Parameters:
|
|
- type: UserType enum value.
|
|
Returns:
|
|
- std::string representing the UserType.
|
|
*/
|
|
inline std::string getUserTypeString(UserType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case UserType::ADMIN:
|
|
return "ADMIN";
|
|
case UserType::TECHNICIAN:
|
|
return "TECHNICIAN";
|
|
case UserType::CUSTOMER:
|
|
return "CUSTOMER";
|
|
}
|
|
throw std::invalid_argument("Invalid UserType");
|
|
}
|
|
|
|
/*
|
|
Function: getUserType
|
|
Description: Converts a string value to its corresponding UserType enum.
|
|
Parameters:
|
|
- value: std::string representing the UserType.
|
|
Returns:
|
|
- UserType enum value.
|
|
Throws:
|
|
- std::invalid_argument if the string does not match a valid UserType.
|
|
*/
|
|
inline UserType getUserType(const std::string& value)
|
|
{
|
|
if (value == "ADMIN")
|
|
{
|
|
return UserType::ADMIN;
|
|
}
|
|
if (value == "TECHNICIAN")
|
|
{
|
|
return UserType::TECHNICIAN;
|
|
}
|
|
if (value == "CUSTOMER")
|
|
{
|
|
return UserType::CUSTOMER;
|
|
}
|
|
throw std::invalid_argument("Invalid UserType string");
|
|
}
|
|
|
|
/*
|
|
Function: getPaymentModeString
|
|
Description: Converts a PaymentMode enum value to its corresponding string representation.
|
|
Parameters:
|
|
- mode: PaymentMode enum value.
|
|
Returns:
|
|
- std::string representing the PaymentMode.
|
|
*/
|
|
inline std::string getPaymentModeString(PaymentMode mode)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case PaymentMode::ONLINE:
|
|
return "ONLINE";
|
|
case PaymentMode::OFFLINE:
|
|
return "OFFLINE";
|
|
case PaymentMode::NOTSET:
|
|
return "NOTSET";
|
|
}
|
|
throw std::invalid_argument("Invalid PaymentMode");
|
|
}
|
|
|
|
/*
|
|
Function: getPaymentMode
|
|
Description: Converts a string value to its corresponding PaymentMode enum.
|
|
Parameters:
|
|
- value: std::string representing the PaymentMode.
|
|
Returns:
|
|
- PaymentMode enum value.
|
|
Throws:
|
|
- std::invalid_argument if the string does not match a valid PaymentMode.
|
|
*/
|
|
inline PaymentMode getPaymentMode(const std::string& value)
|
|
{
|
|
if (value == "ONLINE")
|
|
{
|
|
return PaymentMode::ONLINE;
|
|
}
|
|
if (value == "OFFLINE")
|
|
{
|
|
return PaymentMode::OFFLINE;
|
|
}
|
|
if (value == "NOTSET")
|
|
{
|
|
return PaymentMode::NOTSET;
|
|
}
|
|
throw std::invalid_argument("Invalid PaymentMode string");
|
|
}
|
|
|
|
/*
|
|
Function: getPaymentStatusString
|
|
Description: Converts a PaymentStatus enum value to its corresponding string representation.
|
|
Parameters:
|
|
- status: PaymentStatus enum value.
|
|
Returns:
|
|
- std::string representing the PaymentStatus.
|
|
*/
|
|
inline std::string getPaymentStatusString(PaymentStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case PaymentStatus::PENDING:
|
|
return "PENDING";
|
|
case PaymentStatus::COMPLETED:
|
|
return "COMPLETED";
|
|
case PaymentStatus::PAID:
|
|
return "PAID";
|
|
}
|
|
throw std::invalid_argument("Invalid PaymentStatus");
|
|
}
|
|
|
|
/*
|
|
Function: getPaymentStatus
|
|
Description: Converts a string value to its corresponding PaymentStatus enum.
|
|
Parameters:
|
|
- value: std::string representing the PaymentStatus.
|
|
Returns:
|
|
- PaymentStatus enum value.
|
|
Throws:
|
|
- std::invalid_argument if the string does not match a valid PaymentStatus.
|
|
*/
|
|
inline PaymentStatus getPaymentStatus(const std::string& value)
|
|
{
|
|
if (value == "PENDING")
|
|
{
|
|
return PaymentStatus::PENDING;
|
|
}
|
|
|
|
if (value == "COMPLETED")
|
|
{
|
|
return PaymentStatus::COMPLETED;
|
|
}
|
|
|
|
throw std::invalid_argument("Invalid PaymentStatus string");
|
|
}
|
|
|
|
/*
|
|
Function: getServiceJobStatusString
|
|
Description: Converts a ServiceJobStatus enum value to its corresponding string representation.
|
|
Parameters:
|
|
- status: ServiceJobStatus enum value.
|
|
Returns:
|
|
- std::string representing the ServiceJobStatus.
|
|
*/
|
|
inline std::string getServiceJobStatusString(ServiceJobStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case ServiceJobStatus::PENDING:
|
|
return "PENDING";
|
|
case ServiceJobStatus::STARTED:
|
|
return "STARTED";
|
|
case ServiceJobStatus::COMPLETED:
|
|
return "COMPLETED";
|
|
case ServiceJobStatus::CANCELLED:
|
|
return "CANCELLED";
|
|
case ServiceJobStatus::IN_PROGRESS:
|
|
return "IN_PROGRESS";
|
|
}
|
|
throw std::invalid_argument("Invalid ServiceJobStatus");
|
|
}
|
|
|
|
/*
|
|
Function: getServiceJobStatus
|
|
Description: Converts a string value to its corresponding ServiceJobStatus enum.
|
|
Parameters:
|
|
- value: std::string representing the ServiceJobStatus.
|
|
Returns:
|
|
- ServiceJobStatus enum value.
|
|
Throws:
|
|
- std::invalid_argument if the string does not match a valid ServiceJobStatus.
|
|
*/
|
|
inline ServiceJobStatus getServiceJobStatus(const std::string& value)
|
|
{
|
|
if (value == "STARTED")
|
|
{
|
|
return ServiceJobStatus::STARTED;
|
|
}
|
|
if (value == "COMPLETED")
|
|
{
|
|
return ServiceJobStatus::COMPLETED;
|
|
}
|
|
if (value == "PENDING")
|
|
{
|
|
return ServiceJobStatus::PENDING;
|
|
}
|
|
if (value == "CANCELLED")
|
|
{
|
|
return ServiceJobStatus::CANCELLED;
|
|
}
|
|
if (value == "IN_PROGRESS")
|
|
{
|
|
return ServiceJobStatus::IN_PROGRESS;
|
|
}
|
|
throw std::invalid_argument("Invalid ServiceJobStatus string");
|
|
}
|
|
|
|
/*
|
|
Function: getStateString
|
|
Description: Converts a State enum value to its corresponding string representation.
|
|
Parameters:
|
|
- status: State enum value.
|
|
Returns:
|
|
- std::string representing the State.
|
|
*/
|
|
inline std::string getStateString(State status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case State::ACTIVE:
|
|
return "ACTIVE";
|
|
case State::INACTIVE:
|
|
return "INACTIVE";
|
|
}
|
|
throw std::invalid_argument("Invalid State");
|
|
}
|
|
|
|
/*
|
|
Function: getState
|
|
Description: Converts a string value to its corresponding State enum.
|
|
Parameters:
|
|
- value: std::string representing the State.
|
|
Returns:
|
|
- State enum value.
|
|
Throws:
|
|
- std::invalid_argument if the string does not match a valid State.
|
|
*/
|
|
inline State getState(const std::string& value)
|
|
{
|
|
if (value == "ACTIVE")
|
|
{
|
|
return State::ACTIVE;
|
|
}
|
|
if (value == "INACTIVE")
|
|
{
|
|
return State::INACTIVE;
|
|
}
|
|
throw std::invalid_argument("Invalid State string");
|
|
}
|
|
} |