-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
}
+bool
+ovsdb_atom_is_default(const union ovsdb_atom *atom,
+ enum ovsdb_atomic_type type)
+{
+ switch (type) {
+ case OVSDB_TYPE_VOID:
+ NOT_REACHED();
+
+ case OVSDB_TYPE_INTEGER:
+ return atom->integer == 0;
+
+ case OVSDB_TYPE_REAL:
+ return atom->real == 0.0;
+
+ case OVSDB_TYPE_BOOLEAN:
+ return atom->boolean == false;
+
+ case OVSDB_TYPE_STRING:
+ return atom->string[0] == '\0';
+
+ case OVSDB_TYPE_UUID:
+ return uuid_is_zero(&atom->uuid);
+
+ case OVSDB_N_TYPES:
+ default:
+ NOT_REACHED();
+ }
+}
+
void
ovsdb_atom_clone(union ovsdb_atom *new, const union ovsdb_atom *old,
enum ovsdb_atomic_type type)
datum->values = alloc_default_atoms(type->value_type, datum->n);
}
+bool
+ovsdb_datum_is_default(const struct ovsdb_datum *datum,
+ const struct ovsdb_type *type)
+{
+ size_t i;
+
+ if (datum->n != type->n_min) {
+ return false;
+ }
+ for (i = 0; i < datum->n; i++) {
+ if (!ovsdb_atom_is_default(&datum->keys[i], type->key_type)) {
+ return false;
+ }
+ if (type->value_type != OVSDB_TYPE_VOID
+ && !ovsdb_atom_is_default(&datum->values[i], type->value_type)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static union ovsdb_atom *
clone_atoms(const union ovsdb_atom *old, enum ovsdb_atomic_type type, size_t n)
{
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
};
void ovsdb_atom_init_default(union ovsdb_atom *, enum ovsdb_atomic_type);
+bool ovsdb_atom_is_default(const union ovsdb_atom *, enum ovsdb_atomic_type);
void ovsdb_atom_clone(union ovsdb_atom *, const union ovsdb_atom *,
enum ovsdb_atomic_type);
void ovsdb_atom_swap(union ovsdb_atom *, union ovsdb_atom *);
};
void ovsdb_datum_init_default(struct ovsdb_datum *, const struct ovsdb_type *);
+bool ovsdb_datum_is_default(const struct ovsdb_datum *,
+ const struct ovsdb_type *);
void ovsdb_datum_clone(struct ovsdb_datum *, const struct ovsdb_datum *,
const struct ovsdb_type *);
void ovsdb_datum_destroy(struct ovsdb_datum *, const struct ovsdb_type *);
-/* Copyright (c) 2008, 2009 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
uuid->parts[0] = uuid->parts[1] = uuid->parts[2] = uuid->parts[3] = 0;
}
+/* Returns true if 'uuid' is all zero, otherwise false. */
+bool
+uuid_is_zero(const struct uuid *uuid)
+{
+ return (!uuid->parts[0] && !uuid->parts[1]
+ && !uuid->parts[2] && !uuid->parts[3]);
+}
+
/* Compares 'a' and 'b'. Returns a negative value if 'a < b', zero if 'a ==
* b', or positive if 'a > b'. The ordering is lexicographical order of the
* conventional way of writing out UUIDs as strings. */
-/* Copyright (c) 2008, 2009 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void uuid_init(void);
void uuid_generate(struct uuid *);
void uuid_zero(struct uuid *);
+bool uuid_is_zero(const struct uuid *);
int uuid_compare_3way(const struct uuid *, const struct uuid *);
bool uuid_from_string(struct uuid *, const char *);
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
unsigned int idx = column->index;
if (idx != OVSDB_COL_UUID && column->persistent
- && (!old || !ovsdb_datum_equals(&old->fields[idx],
- &new->fields[idx], type)))
+ && (old
+ ? !ovsdb_datum_equals(&old->fields[idx], &new->fields[idx],
+ type)
+ : !ovsdb_datum_is_default(&new->fields[idx], type)))
{
if (!row) {
row = json_object_create();