WolfHybrid23
WolfHybrid23

Reputation: 79

Specific Parameter Input

I am fairly new to C++ so forgive me for being all over the place with my code but here is whats going on, I am creating a Dynamic Link Library that will handle the decompression of my games assets. I am very familiar with lossless binary compression but here's whats happening, I need to know how I can have an argument either be "Type A" or "Type B" and nothing else, I am using visual studio so I would like the autocomplete hint to tell me I can either use "A" or "B" as the argument, How would I do this?

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

Upvotes: 0

Views: 70

Answers (2)

WolfHybrid23
WolfHybrid23

Reputation: 79

Does this look appropriate?

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

Upvotes: 0

NuPagadi
NuPagadi

Reputation: 1440

Like this?

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

Then you call it this way:

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

Upvotes: 2

Related Questions