特定参数输入

时间:2018-05-09 16:11:11

标签: c++

我是C ++的新手,所以请原谅我用我的代码到处都是这里但是这里有什么,我正在创建一个动态链接库来处理我的游戏资产的解压缩。我对无损二进制压缩非常熟悉,但是这里发生了什么,我需要知道我怎么能有一个参数要么是“Type A”还是“Type B”而没有别的,我正在使用visual studio所以我想要自动完成提示告诉我我可以使用“A”或“B”作为参数,我该怎么做?

func isPassedMoreThan(days: Int, fromDate date : Date, toDate date2 : Date) -> Bool {
    let unitFlags: Set<Calendar.Component> = [.day]
    let deltaD = Calendar.current.dateComponents( unitFlags, from: date, to: date2)
    return deltaD > days
}

2 个答案:

答案 0 :(得分:3)

喜欢这个吗?

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);

答案 1 :(得分:0)

这看起来合适吗?

__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;
    }