示例#1
0
void collection_get_primitive(Collection* collection, size_t ndx, PrimitiveValue& value, NativeException::Marshallable& ex)
{
    handle_errors(ex, [&]() {
        const size_t count = collection->size();
        if (ndx >= count)
            throw IndexOutOfRangeException("Get from Collection", ndx, count);
        
        value.has_value = true;
        switch (value.type) {
            case realm::PropertyType::Bool:
                value.value.bool_value = collection->template
                get<bool>(ndx);
                break;
            case realm::PropertyType::Bool | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<bool>>(ndx);
                value.has_value = !!result;
                value.value.bool_value = result.value_or(false);
                break;
            }
            case realm::PropertyType::Int:
                value.value.int_value = collection->template get<int64_t>(ndx);
                break;
            case realm::PropertyType::Int | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<int64_t>>(ndx);
                value.has_value = !!result;
                value.value.int_value = result.value_or(0);
                break;
            }
            case realm::PropertyType::Float:
                value.value.float_value = collection->template get<float>(ndx);
                break;
            case realm::PropertyType::Float | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<float>>(ndx);
                value.has_value = !!result;
                value.value.float_value = result.value_or((float)0);
                break;
            }
            case realm::PropertyType::Double:
                value.value.double_value = collection->template get<double>(ndx);
                break;
            case realm::PropertyType::Double | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<double>>(ndx);
                value.has_value = !!result;
                value.value.double_value = result.value_or((double)0);
                break;
            }
            case realm::PropertyType::Date:
                value.value.int_value = to_ticks(collection->template get<Timestamp>(ndx));
                break;
            case realm::PropertyType::Date | realm::PropertyType::Nullable: {
                auto result = collection->template get<Timestamp>(ndx);
                value.has_value = !result.is_null();
                value.value.int_value = result.is_null() ? 0 : to_ticks(result);
                break;
            }
            default:
                REALM_UNREACHABLE();
        }
    });
}
示例#2
0
int64_t util_thread::current_time_ticks(int64_t ticks_per_sec) {
  int64_t result;
  struct timeval now;
  int ret = GETTIMEOFDAY(&now, NULL);
  //assert(ret == 0);
  BASE_UNUSED_VARIABLE(ret); //squelching "unused variable" warning
  to_ticks(result, now, ticks_per_sec);
  return result;
}
示例#3
0
int64_t Util::current_time_ticks(int64_t ticks_per_sec)
{
	int64_t result;

#if defined(HAVE_CLOCK_GETTIME)
	struct timespec now;
	int ret = clock_gettime(CLOCK_REALTIME, &now);
	assert(ret == 0);
	to_ticks(result, now, ticks_per_sec);
#elif defined(HAVE_GETTIMEOFDAY)
	struct timeval now;
	int ret = gettimeofday(&now, NULL);
	assert(ret == 0);
	to_ticks(result, now, ticks_per_sec);
#else
	result = time(NULL);
#endif // defined(HAVE_CLOCK_GETTIME)
	return result;
}
示例#4
0
bool DateTime::operator !=(const DateTime &other) const
{
	byte64 a = is_null() ? 0 : to_ticks();
	byte64 b = other.is_null() ? 0 : other.to_ticks();
	return a != b;
}
示例#5
0
 /**
  * Converts the hmst to a ticks offset from midnight.
  */
 int64_t to_ticks() const {
     return to_ticks(hour, minute, second, tick);
 }
示例#6
0
	bool DateTime::operator !=(const DateTime &other) const
	{
		int64_t a = is_null() ? 0 : to_ticks();
		int64_t b = other.is_null() ? 0 : other.to_ticks();
		return a != b;
	}