2015-06-21 21:02:10 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2015-06-25 23:12:49 -07:00
|
|
|
#include "Value.h"
|
2015-06-21 21:02:10 -07:00
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
#include "ntcore.h"
|
|
|
|
|
|
2015-06-28 21:52:06 -07:00
|
|
|
bool ntimpl::operator==(const Value& lhs, const Value& rhs) {
|
|
|
|
|
if (lhs.type() != rhs.type()) return false;
|
|
|
|
|
switch (lhs.type()) {
|
2015-06-21 21:02:10 -07:00
|
|
|
case NT_UNASSIGNED:
|
2015-06-25 22:57:43 -07:00
|
|
|
return true; // XXX: is this better being false instead?
|
2015-06-21 21:02:10 -07:00
|
|
|
case NT_BOOLEAN:
|
2015-06-25 22:57:43 -07:00
|
|
|
return lhs.data.v_boolean == rhs.data.v_boolean;
|
2015-06-21 21:02:10 -07:00
|
|
|
case NT_DOUBLE:
|
2015-06-25 22:57:43 -07:00
|
|
|
return lhs.data.v_double == rhs.data.v_double;
|
2015-06-21 21:02:10 -07:00
|
|
|
case NT_STRING:
|
|
|
|
|
case NT_RAW:
|
|
|
|
|
case NT_RPC:
|
2015-06-25 22:57:43 -07:00
|
|
|
if (lhs.data.v_string.len != rhs.data.v_string.len) return false;
|
|
|
|
|
return std::memcmp(lhs.data.v_string.str, rhs.data.v_string.str,
|
|
|
|
|
lhs.data.v_string.len) == 0;
|
2015-06-21 21:02:10 -07:00
|
|
|
case NT_BOOLEAN_ARRAY:
|
2015-06-25 22:57:43 -07:00
|
|
|
if (lhs.data.arr_boolean.size != rhs.data.arr_boolean.size) return false;
|
|
|
|
|
return std::memcmp(lhs.data.arr_boolean.arr, rhs.data.arr_boolean.arr,
|
|
|
|
|
lhs.data.arr_boolean.size *
|
|
|
|
|
sizeof(lhs.data.arr_boolean.arr[0])) == 0;
|
2015-06-21 21:02:10 -07:00
|
|
|
case NT_DOUBLE_ARRAY:
|
2015-06-25 22:57:43 -07:00
|
|
|
if (lhs.data.arr_double.size != rhs.data.arr_double.size) return false;
|
|
|
|
|
return std::memcmp(lhs.data.arr_double.arr, rhs.data.arr_double.arr,
|
|
|
|
|
lhs.data.arr_double.size *
|
|
|
|
|
sizeof(lhs.data.arr_double.arr[0])) == 0;
|
|
|
|
|
case NT_STRING_ARRAY: {
|
|
|
|
|
if (lhs.data.arr_string.size != rhs.data.arr_string.size) return false;
|
|
|
|
|
for (size_t i = 0; i < lhs.data.arr_string.size; i++) {
|
|
|
|
|
if (lhs.data.arr_string.arr[i].len != rhs.data.arr_string.arr[i].len)
|
|
|
|
|
return false;
|
|
|
|
|
if (std::memcmp(lhs.data.arr_string.arr[i].str,
|
|
|
|
|
rhs.data.arr_string.arr[i].str,
|
|
|
|
|
lhs.data.arr_string.arr[i].len) != 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2015-06-21 21:02:10 -07:00
|
|
|
}
|
|
|
|
|
default:
|
2015-06-25 22:57:43 -07:00
|
|
|
// assert(false && "unknown value type");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-06-21 21:02:10 -07:00
|
|
|
}
|