pikmin2/include/id32.h

183 lines
4.3 KiB
C
Raw Normal View History

2021-10-03 00:44:38 +00:00
#ifndef _ID32_H
#define _ID32_H
#include "PowerPC_EABI_Support/Runtime/runtime.h"
2022-01-04 11:42:37 +00:00
#include "types.h"
#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
union {
2023-12-16 21:11:27 +00:00
char mStrView[4];
u32 mIntView;
} 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.
*/
Squashed commit of the following: commit 1aebcc3b566ea2937375f32b1a8bcaec483ad086 Author: SodiumChlorideLogic <19625889+SodiumChlorideLogic@users.noreply.github.com> Date: Sun Jan 30 17:18:58 2022 -0500 Fix build commit 557102b1dc6bc352a1c0c473fba1cb9010eeb4ff Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Sun Jan 30 13:04:20 2022 -0500 tab alignment in makefile minor edit commit 6fad05508ed56656dc3305c5f0920df58aede94a Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Thu Jan 27 22:30:48 2022 -0500 Create .gitattributes commit 0276b2dd5ff4043a2c70d86be92d5d7e6de7f1a3 Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Wed Jan 26 14:45:06 2022 -0500 undo naïve change of mine commit 77c4f5183d192bec4ad7f3126fef361a418bc15f Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Wed Jan 26 14:25:15 2022 -0500 correct fakepiki and associates repair @intns mistake from d0e0ebe4e4632d74e51663b286bd364bfa5991dc properly toss in motionlistener commit cf1e8fab44e0802db35acf05c92deda48fe916e0 Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Mon Jan 24 18:35:11 2022 -0500 formatting commit e2182b5352cf056cca84020f8c820cf69e73f03a Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Fri Jan 21 21:35:01 2022 -0500 Rename LICENSE to LICENSE.MD commit 99d42518c02a22380ae068690bc063a38501859b Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Fri Jan 21 21:34:44 2022 -0500 Create LICENSE commit 8fd5812f2cc1a8340586468737454a2993dfb57e Author: SodiumChlorideLogic <19625889+SodiumChlorideLogic@users.noreply.github.com> Date: Thu Jan 20 20:00:20 2022 -0500 Massive collinfo.cpp progress. Also everything else I had.
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);
mId = other.mId;
Squashed commit of the following: commit 1aebcc3b566ea2937375f32b1a8bcaec483ad086 Author: SodiumChlorideLogic <19625889+SodiumChlorideLogic@users.noreply.github.com> Date: Sun Jan 30 17:18:58 2022 -0500 Fix build commit 557102b1dc6bc352a1c0c473fba1cb9010eeb4ff Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Sun Jan 30 13:04:20 2022 -0500 tab alignment in makefile minor edit commit 6fad05508ed56656dc3305c5f0920df58aede94a Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Thu Jan 27 22:30:48 2022 -0500 Create .gitattributes commit 0276b2dd5ff4043a2c70d86be92d5d7e6de7f1a3 Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Wed Jan 26 14:45:06 2022 -0500 undo naïve change of mine commit 77c4f5183d192bec4ad7f3126fef361a418bc15f Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Wed Jan 26 14:25:15 2022 -0500 correct fakepiki and associates repair @intns mistake from d0e0ebe4e4632d74e51663b286bd364bfa5991dc properly toss in motionlistener commit cf1e8fab44e0802db35acf05c92deda48fe916e0 Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Mon Jan 24 18:35:11 2022 -0500 formatting commit e2182b5352cf056cca84020f8c820cf69e73f03a Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Fri Jan 21 21:35:01 2022 -0500 Rename LICENSE to LICENSE.MD commit 99d42518c02a22380ae068690bc063a38501859b Author: EpochFlame <82550703+EpochFlame@users.noreply.github.com> Date: Fri Jan 21 21:34:44 2022 -0500 Create LICENSE commit 8fd5812f2cc1a8340586468737454a2993dfb57e Author: SodiumChlorideLogic <19625889+SodiumChlorideLogic@users.noreply.github.com> Date: Thu Jan 20 20:00:20 2022 -0500 Massive collinfo.cpp progress. Also everything else I had.
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();
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; }
2023-12-16 21:11:27 +00:00
/**
* @brief End-of-file identifier.
*
* This static member represents the end-of-file identifier.
*/
static ID32 eof; // BSS
};
2021-10-03 00:44:38 +00:00
2021-10-14 19:43:06 +00:00
#endif