// Copyright(c) 2021 to 2022 ZettaScale Technology and others
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
// v. 1.0 which is available at
// http://www.eclipse.org/org/documents/edl-v10.php.
//
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#if defined(__IDLC__)
union union_test;
@topic @final
union union_test switch (short) {
case 1:
@external union_test u1;
default:
char u2;
};
#else
#include <string.h>
#include "dds/dds.h"
#include "test_union_r.h"
#include "common.h"
const dds_topic_descriptor_t *desc = &union_test_desc;
void init_sample (void *s)
{
union_test *t = (union_test *) s;
t->_d = 1;
A (t->_u.u1);
t->_u.u1->_d = 1;
A (t->_u.u1->_u.u1);
t->_u.u1->_u.u1->_d = 2;
t->_u.u1->_u.u1->_u.u2 = 3;
}
int cmp_sample (const void *sa, const void *sb)
{
union_test *a = (union_test *) sa;
union_test *b = (union_test *) sb;
CMP(a, b, _d, 1);
CMP(a, b, _u.u1->_d, 1);
CMP(a, b, _u.u1->_u.u1->_d, 2);
CMP(a, b, _u.u1->_u.u1->_u.u2, 3);
return 0;
}
NO_KEY_CMP
#endif