Skip to content

Instantly share code, notes, and snippets.

@monyarm
Created May 13, 2020 05:50
Show Gist options
  • Select an option

  • Save monyarm/c3ddabb289dd79d43ddb8f04543620de to your computer and use it in GitHub Desktop.

Select an option

Save monyarm/c3ddabb289dd79d43ddb8f04543620de to your computer and use it in GitHub Desktop.
#ifndef CSHARPSHIM_H
#define CSHARPSHIM_H
#include "common/array.h"
#include "common/hashmap.h"
#include "common/hashmap.h"
#include "common/str.h"
#include "common/debug.h"
namespace CSharpShim
{
template <typename T>
using List = Common::Array<T>;
template <typename T1, typename T2>
using Dictionary = Common::HashMap<T1, T2, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualsTo>;
using string = Common::String;
class Debug{
public:
void Print(string s){debug(s.c_str());};
void Print(const char* c){debug(c);};
};
enum class Type
{
T_byte,
T_char,
T_string
};
union _objectunion {
byte b;
char c;
string s;
uint16 u16;
int16 i16;
uint32 u32;
int32 i32;
uint64 u64;
int64 i64;
float f;
List<byte> data;
_objectunion(){};
~_objectunion() {}
};
class objectClass
{
public:
bool is(Type t) { return type == t; };
objectClass(byte b) { getValue.b = b; };
objectClass(char c) { getValue.c = c; };
objectClass(string s) { getValue.s = s; };
objectClass(uint16 u16) { getValue.u16 = u16; };
objectClass(int16 i16) { getValue.i16 = i16; };
objectClass(uint32 u32) { getValue.u32 = u32; };
objectClass(int32 i32) { getValue.i32 = i32; };
objectClass(uint64 u64) { getValue.u64 = u64; };
objectClass(int64 i64) { getValue.i64 = i64; };
objectClass(float f) { getValue.f = f; };
objectClass(List<byte> data) { getValue.data = data; };
_objectunion getValue;
private:
Type type;
};
typedef objectClass object;
} // namespace CSharpShim
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment