2021-10-03 00:44:38 +00:00
|
|
|
#ifndef _ID32_H
|
|
|
|
#define _ID32_H
|
2021-10-01 22:55:22 +00:00
|
|
|
|
2023-04-22 06:37:22 +00:00
|
|
|
#include "PowerPC_EABI_Support/Runtime/runtime.h"
|
2022-01-04 11:42:37 +00:00
|
|
|
#include "types.h"
|
2021-10-04 00:10:11 +00:00
|
|
|
#include "stream.h"
|
|
|
|
|
2023-12-16 21:11:27 +00:00
|
|
|
/**
|
|
|
|
* @class ID32
|
|
|
|
*
|
|
|
|
* @brief The ID32 class represents a 32-bit identifier.
|
|
|
|
*
|
|
|
|
* This class provides functionality to store and manipulate 32-bit identifiers.
|
|
|
|
* The identifier can be represented as a string or an integer.
|
|
|
|
*
|
|
|
|
* The class also provides methods to read and write the identifier from/to a stream,
|
|
|
|
* as well as printing and formatting operations.
|
|
|
|
*
|
|
|
|
* @note The maximum length of the string representation is 4 characters.
|
|
|
|
*/
|
2021-10-04 10:42:01 +00:00
|
|
|
class ID32 {
|
2022-01-04 11:59:11 +00:00
|
|
|
private:
|
2023-12-16 21:11:27 +00:00
|
|
|
char mStringID[5]; // _00
|
|
|
|
|
2021-10-11 02:05:19 +00:00
|
|
|
union {
|
2023-12-16 21:11:27 +00:00
|
|
|
char mStrView[4];
|
|
|
|
u32 mIntView;
|
2023-01-25 21:50:15 +00:00
|
|
|
} mId; // _08
|
2021-10-03 00:44:38 +00:00
|
|
|
|
2022-01-04 11:59:11 +00:00
|
|
|
void updateString();
|
|
|
|
|
|
|
|
public:
|
2023-12-16 21:11:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
|
|
|
*
|
|
|
|
* Initializes the ID32 object with an empty identifier.
|
|
|
|
*/
|
2022-01-04 11:42:37 +00:00
|
|
|
ID32();
|
2022-01-04 13:08:03 +00:00
|
|
|
|
2023-12-16 21:11:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Constructor with integer parameter.
|
|
|
|
*
|
|
|
|
* Initializes the ID32 object with the specified integer identifier.
|
|
|
|
*
|
|
|
|
* @param id The integer identifier.
|
|
|
|
*/
|
|
|
|
ID32(u32 id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Assignment operator.
|
|
|
|
*
|
|
|
|
* Assigns the identifier from another ID32 object.
|
|
|
|
*
|
|
|
|
* @param other The ID32 object to assign from.
|
|
|
|
* @return A reference to the assigned ID32 object.
|
|
|
|
*/
|
2022-01-30 22:21:06 +00:00
|
|
|
inline ID32& operator=(const ID32& other)
|
|
|
|
{
|
2023-12-16 21:11:27 +00:00
|
|
|
__copy(mStringID, const_cast<char*>(other.mStringID), 5);
|
2023-01-25 21:50:15 +00:00
|
|
|
mId = other.mId;
|
2022-01-30 22:21:06 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2022-01-04 13:08:03 +00:00
|
|
|
|
2023-12-16 21:11:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Assignment operator with integer parameter.
|
|
|
|
*
|
|
|
|
* Assigns the specified integer identifier to the ID32 object.
|
|
|
|
*
|
|
|
|
* @param id The integer identifier to assign.
|
|
|
|
*/
|
|
|
|
void operator=(u32 id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Equality comparison operator with integer parameter.
|
|
|
|
*
|
|
|
|
* Checks if the ID32 object is equal to the specified integer identifier.
|
|
|
|
*
|
|
|
|
* @param id The integer identifier to compare.
|
|
|
|
* @return True if the ID32 object is equal to the specified identifier, false otherwise.
|
|
|
|
*/
|
|
|
|
bool operator==(u32 id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Inequality comparison operator with integer parameter.
|
|
|
|
*
|
|
|
|
* Checks if the ID32 object is not equal to the specified integer identifier.
|
|
|
|
*
|
|
|
|
* @param id The integer identifier to compare.
|
|
|
|
* @return True if the ID32 object is not equal to the specified identifier, false otherwise.
|
|
|
|
*/
|
|
|
|
bool operator!=(u32 id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Matches the ID32 object against an integer identifier with an exception.
|
|
|
|
*
|
|
|
|
* Checks if the ID32 object matches the specified integer identifier,
|
|
|
|
* except for a specific character position.
|
|
|
|
*
|
|
|
|
* @param id The integer identifier to match.
|
|
|
|
* @param exception The character position to exclude from the matching.
|
|
|
|
* @return True if the ID32 object matches the specified identifier, false otherwise.
|
|
|
|
*/
|
|
|
|
bool match(u32 id, char exception);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Checks if the ID32 object represents the end-of-file identifier.
|
|
|
|
*
|
|
|
|
* @return True if the ID32 object represents the end-of-file identifier, false otherwise.
|
|
|
|
*/
|
2022-01-04 13:08:03 +00:00
|
|
|
bool isEof();
|
2023-12-16 21:11:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the ID32 object to the specified integer identifier.
|
|
|
|
*
|
|
|
|
* @param id The integer identifier to set.
|
|
|
|
*/
|
|
|
|
void setID(u32 id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the string representation of the ID32 object.
|
|
|
|
*
|
|
|
|
* This method updates the string representation of the ID32 object
|
|
|
|
* based on the current integer identifier.
|
|
|
|
*/
|
2022-01-04 11:42:37 +00:00
|
|
|
void updateID();
|
2023-12-16 21:11:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reads the ID32 object from a stream.
|
|
|
|
*
|
|
|
|
* @param stream The stream to read from.
|
|
|
|
*/
|
|
|
|
void read(Stream& stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Writes the ID32 object to a stream.
|
|
|
|
*
|
|
|
|
* @param stream The stream to write to.
|
|
|
|
*/
|
|
|
|
void write(Stream& stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Formats the ID32 object as a string.
|
|
|
|
*
|
|
|
|
* @param str The buffer to store the formatted string.
|
|
|
|
*/
|
|
|
|
void sprint(char* str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Prints the ID32 object to the standard output.
|
|
|
|
*/
|
2022-01-04 11:42:37 +00:00
|
|
|
void print();
|
2021-10-04 17:51:29 +00:00
|
|
|
|
2023-12-16 21:11:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Gets the string representation of the ID32 object.
|
|
|
|
*
|
|
|
|
* @return The string representation of the ID32 object.
|
|
|
|
*/
|
|
|
|
inline char* getStrID() { return mId.mStrView; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the integer representation of the ID32 object.
|
|
|
|
*
|
|
|
|
* @return The integer representation of the ID32 object.
|
|
|
|
*/
|
|
|
|
inline u32 getID() { return mId.mIntView; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the string identifier of the ID32 object.
|
|
|
|
*
|
|
|
|
* @return The string identifier of the ID32 object.
|
|
|
|
*/
|
|
|
|
inline char* getStr() { return mStringID; }
|
2021-10-04 17:51:29 +00:00
|
|
|
|
2023-12-16 21:11:27 +00:00
|
|
|
/**
|
|
|
|
* @brief End-of-file identifier.
|
|
|
|
*
|
|
|
|
* This static member represents the end-of-file identifier.
|
|
|
|
*/
|
2022-06-25 01:08:27 +00:00
|
|
|
static ID32 eof; // BSS
|
2021-10-01 22:55:22 +00:00
|
|
|
};
|
2021-10-03 00:44:38 +00:00
|
|
|
|
2021-10-14 19:43:06 +00:00
|
|
|
#endif
|