具体参数输入

Specific Parameter Input

本文关键字:输入 参数      更新时间:2023-10-16

我对C++相当陌生,所以请原谅我到处都是我的代码,但这是怎么回事,我正在创建一个动态链接库来处理我的游戏资产的解压缩。我非常熟悉无损二进制压缩,但这是正在发生的事情,我需要知道如何让参数是"A 型"或"B 型",仅此而已,我正在使用 Visual Studio,所以我希望自动完成提示告诉我我可以使用"A"或"B"作为参数, 我该怎么做?

cpp
//People where telling me to add code for visual so here
static __declspec(dllexport) char* compress(char* buffer, "8bit Int" | "16bit Int" | "32bit Int", int Value)
{
char* bytes;
//Enter code to convert integer to bytes
strcat_s(bytes, sizeof(bytes) + sizeof(buffer), buffer);
return buffer;
}

像这样?

enum class Integer
{
UNKNOWN = 0,
Bit8 = 1,
Bit16 = 2,
Bit32 = 3,
};
static __declspec(dllexport) char* compress(
char* buffer, Integer intType, int Value)
{
char* bytes;
switch (intType)
{
case Integer::Bit8:
// 8-bits processing.
break;
case Integer::Bit16:
// 16-bits processing.
break;
case Integer::Bit32:
// 32-bits processing.
break;
}
//Enter code to convert integer to bytes
strcat_s(bytes, sizeof(bytes) + sizeof(buffer), buffer);
return buffer;
}

然后你这样称呼它:

compress(buf, Integer::Bit8, 42);

这看起来合适吗?

__declspec(dllexport) enum intType {
_8bit, _16bit, _32bit
};
class COMPRESS
{
public:
char* CreateBuffer(int Size)
{
char* buffer = new char[Size];
return buffer;
}
char* BufferWrite(char* Buffer, intType Type, int Value)
{
char* bytes;
switch (Type)
{
_8bit:
{
bytes = (char*)Value;
}
_16bit:
{
bytes[0] = Value & 0xff;
bytes[1] = (Value >> 8) & 0xff;
}
_32bit:
{
bytes[0] = Value & 0xff;
bytes[1] = (Value >> 8) & 0xff;
bytes[2] = (Value >> 16) & 0xff;
bytes[3] = (Value >> 24) & 0xff;
}
}
strcat_s(Buffer, sizeof(bytes) + sizeof(Buffer), bytes);
return Buffer;
}