Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,72 @@ namespace ignite
template<typename T>
struct IGNITE_IMPORT_EXPORT BinaryType { };

/**
* Default implementations of BinaryType hashing functions.
*/
template<typename T>
struct IGNITE_IMPORT_EXPORT BinaryTypeDefaultHashing
{
/**
* Get binary object type ID.
*
* @return Type ID.
*/
static int32_t GetTypeId()
{
std::string typeName;
BinaryType<T>::GetTypeName(typeName);

return GetBinaryStringHashCode(typeName.c_str());
}

/**
* Get binary object field ID.
*
* @param name Field name.
* @return Field ID.
*/
static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}
};

/**
* Default implementations of BinaryType methods for non-null type.
*/
template<typename T>
struct IGNITE_IMPORT_EXPORT BinaryTypeNonNullableType
{
/**
* Check whether passed binary object should be interpreted as NULL.
*
* @return True if binary object should be interpreted as NULL.
*/
static bool IsNull(const T&)
{
return false;
}

/**
* Get NULL value for the given binary type.
*
* @param dst Null value for the type.
*/
static void GetNull(T& dst)
{
dst = T();
}
};

/**
* Default implementations of BinaryType hashing functions and non-null type behaviour.
*/
template<typename T>
struct IGNITE_IMPORT_EXPORT BinaryTypeDefaultAll :
BinaryTypeDefaultHashing<T>,
BinaryTypeNonNullableType<T> { };

/**
* Templated binary type specification for pointers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace ignite

static int32_t GetFieldId(const char* name);

static bool IsNull(const IgniteError& obj)
static bool IsNull(const IgniteError&)
{
return false;
}
Expand Down
88 changes: 14 additions & 74 deletions modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ namespace ignite_test
{
namespace core
{
namespace binary
namespace binary
{
class BinaryDummy
{
// No-op.
};

class BinaryInner
class BinaryInner
{
public:
BinaryInner();
Expand Down Expand Up @@ -76,13 +76,13 @@ namespace ignite_test
BinaryFields(int32_t val1, int32_t val2, int32_t rawVal1, int32_t rawVal2) :
val1(val1), val2(val2), rawVal1(rawVal1), rawVal2(rawVal2)
{
// No-op.
// No-op.
}

friend bool operator==(const BinaryFields& one, const BinaryFields& two)
{
return one.val1 == two.val1 && one.val2 == two.val2 &&
one.rawVal1 == two.rawVal1 &&one.rawVal2 == two.rawVal2;
return one.val1 == two.val1 && one.val2 == two.val2 &&
one.rawVal1 == two.rawVal1 && one.rawVal2 == two.rawVal2;
}
};

Expand Down Expand Up @@ -141,62 +141,32 @@ namespace ignite
namespace gt = ignite_test::core::binary;

template<>
struct BinaryType<gt::BinaryDummy>
struct BinaryType<gt::BinaryDummy> : BinaryTypeDefaultAll<gt::BinaryDummy>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("BinaryDummy");
}

static void GetTypeName(std::string& dst)
{
dst = "BinaryDummy";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const gt::BinaryInner& obj)
{
return false;
}

static void GetNull(gt::BinaryDummy& dst)
{
dst = gt::BinaryDummy();
}

static void Write(BinaryWriter& writer, const gt::BinaryDummy& obj)
{
// No-op.
}

static void Read(BinaryReader& reader, gt::BinaryDummy& dst)
static void Read(BinaryReader&, gt::BinaryDummy& dst)
{
dst = gt::BinaryDummy();
}
};

template<>
struct BinaryType<gt::BinaryInner>
template<>
struct BinaryType<gt::BinaryInner> : BinaryTypeDefaultHashing<gt::BinaryInner>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("BinaryInner");
}

static void GetTypeName(std::string& dst)
{
dst = "BinaryInner";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const gt::BinaryInner& obj)
{
return obj.GetValue() == 0;
Expand All @@ -221,23 +191,13 @@ namespace ignite
};

template<>
struct BinaryType<gt::BinaryOuter>
struct BinaryType<gt::BinaryOuter> : BinaryTypeDefaultHashing<gt::BinaryOuter>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("BinaryOuter");
}

static void GetTypeName(std::string& dst)
{
dst = "BinaryOuter";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const gt::BinaryOuter& obj)
{
return obj.GetValue() == 0 && obj.GetInner().GetValue();
Expand All @@ -251,7 +211,7 @@ namespace ignite
static void Write(BinaryWriter& writer, const gt::BinaryOuter& obj)
{
writer.WriteObject("inner", obj.GetInner());
writer.WriteInt32("val", obj.GetValue());
writer.WriteInt32("val", obj.GetValue());
}

static void Read(BinaryReader& reader, gt::BinaryOuter& dst)
Expand All @@ -264,23 +224,13 @@ namespace ignite
};

template<>
struct BinaryType<gt::BinaryFields>
struct BinaryType<gt::BinaryFields> : BinaryTypeDefaultHashing<gt::BinaryFields>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("BinaryFields");
}

static void GetTypeName(std::string& dst)
{
dst = "BinaryFields";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const gt::BinaryFields& obj)
{
return false;
Expand Down Expand Up @@ -317,23 +267,13 @@ namespace ignite
};

template<>
struct BinaryType<gt::PureRaw>
struct BinaryType<gt::PureRaw> : BinaryTypeDefaultHashing<gt::PureRaw>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("PureRaw");
}

static void GetTypeName(std::string& dst)
{
dst = "PureRaw";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const gt::PureRaw& obj)
{
return false;
Expand Down Expand Up @@ -363,4 +303,4 @@ namespace ignite
}
}

#endif
#endif
66 changes: 3 additions & 63 deletions modules/platforms/cpp/core-test/src/compute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,33 +190,13 @@ namespace ignite
namespace binary
{
template<>
struct BinaryType<Func1>
struct BinaryType<Func1> : BinaryTypeDefaultAll<Func1>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("Func1");
}

static void GetTypeName(std::string& dst)
{
dst = "Func1";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const Func1& obj)
{
return false;
}

static void GetNull(Func1& dst)
{
dst = Func1(0, 0);
}

static void Write(BinaryWriter& writer, const Func1& obj)
{
writer.WriteInt32("a", obj.a);
Expand All @@ -233,33 +213,13 @@ namespace ignite
};

template<>
struct BinaryType<Func2>
struct BinaryType<Func2> : BinaryTypeDefaultAll<Func2>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("Func2");
}

static void GetTypeName(std::string& dst)
{
dst = "Func2";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const Func2& obj)
{
return false;
}

static void GetNull(Func2& dst)
{
dst = Func2(0, 0);
}

static void Write(BinaryWriter& writer, const Func2& obj)
{
writer.WriteInt32("a", obj.a);
Expand All @@ -276,33 +236,13 @@ namespace ignite
};

template<>
struct BinaryType<Func3>
struct BinaryType<Func3> : BinaryTypeDefaultAll<Func3>
{
static int32_t GetTypeId()
{
return GetBinaryStringHashCode("Func3");
}

static void GetTypeName(std::string& dst)
{
dst = "Func3";
}

static int32_t GetFieldId(const char* name)
{
return GetBinaryStringHashCode(name);
}

static bool IsNull(const Func3& obj)
{
return false;
}

static void GetNull(Func3& dst)
{
dst = Func3(0, 0);
}

static void Write(BinaryWriter& writer, const Func3& obj)
{
writer.WriteInt32("a", obj.a);
Expand Down
Loading