-#ifndef _BABELTRACE_TYPES_H
-#define _BABELTRACE_TYPES_H
+#ifndef BABELTRACE_TYPES_H
+#define BABELTRACE_TYPES_H
/*
- * BabelTrace
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
*
- * Type Header
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
*
- * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
*/
-#include <babeltrace/format.h>
-#include <babeltrace/align.h>
-#include <string.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
-/*
- * Always update stream_pos with move_pos and init_pos.
- */
-struct stream_pos {
- unsigned char *base; /* Base address */
- size_t offset; /* Offset from base, in bits */
- int dummy; /* Dummy position, for length calculation */
-};
-
-static inline
-void init_pos(struct stream_pos *pos, unsigned char *base)
-{
- pos->base = base; /* initial base, page-aligned */
- pos->offset = 0;
- pos->dummy = false;
-}
+/**
+@defgroup ctypes Babeltrace C types
+@ingroup apiref
+@brief Babeltrace C types.
-/*
- * move_pos - move position of a relative bit offset
- *
- * TODO: allow larger files by updating base too.
- */
-static inline
-void move_pos(struct stream_pos *pos, size_t offset)
-{
- pos->offset = pos->offset + offset;
-}
+@code
+#include <babeltrace/types.h>
+@endcode
-/*
- * align_pos - align position on a bit offset (> 0)
- *
- * TODO: allow larger files by updating base too.
- */
-static inline
-void align_pos(struct stream_pos *pos, size_t offset)
-{
- pos->offset += offset_align(pos->offset, offset);
-}
+This header contains custom type definitions used across the library.
-static inline
-void copy_pos(struct stream_pos *dest, struct stream_pos *src)
-{
- memcpy(dest, src, sizeof(struct stream_pos));
-}
+@file
+@brief Babeltrace C types.
+@sa ctypes
-static inline
-unsigned char *get_pos_addr(struct stream_pos *pos)
-{
- /* Only makes sense to get the address after aligning on CHAR_BIT */
- assert(!(pos->alignment % CHAR_BIT));
- return pos->base + (pos->offset / CHAR_BIT);
-}
+@addtogroup ctypes
+@{
+*/
-struct type_class {
- GQuark name; /* type name */
- size_t alignment; /* type alignment, in bits */
- /*
- * Type copy function. Knows how to find the child type_class from the
- * parent type_class.
- */
- size_t (*copy)(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- const struct type_class *type_class);
- void (*free)(struct type_class *type_class);
-};
+/// False boolean value for the #bt_bool type.
+#define BT_FALSE 0
-/*
- * Because we address in bits, bitfields end up being exactly the same as
- * integers, except that their read/write functions must be able to deal with
- * read/write non aligned on CHAR_BIT.
- */
-struct type_class_integer {
- struct type_class p;
- size_t len; /* length, in bits. */
- int byte_order; /* byte order */
- int signedness;
-};
-
-struct type_class_float {
- struct type_class p;
- struct int_class *sign;
- struct int_class *mantissa;
- struct int_class *exp;
- int byte_order;
- /* TODO: we might want to express more info about NaN, +inf and -inf */
-};
-
-struct enum_table {
- GHashTable *value_to_quark; /* Tuples (value, GQuark) */
- GHashTable *quark_to_value; /* Tuples (GQuark, value) */
-};
-
-struct type_class_enum {
- struct type_class_int p; /* inherit from integer */
- struct enum_table table;
-};
-
-struct type_class_string {
- struct type_class p;
-};
-
-struct type_class_struct {
- struct type_class p;
- /* TODO */
-};
-
-struct type_class *ctf_lookup_type(GQuark qname);
-int ctf_register_type(struct type_class *type_class);
-
-/* Nameless types can be created by passing a NULL name */
-
-struct type_class_integer *integer_type_new(const char *name,
- size_t len, int byte_order,
- int signedness,
- size_t alignment);
-void integer_type_free(struct type_class_integer *int_class);
+/// True boolean value for the #bt_bool type.
+#define BT_TRUE 1
-/*
- * mantissa_len is the length of the number of bytes represented by the mantissa
- * (e.g. result of DBL_MANT_DIG). It includes the leading 1.
- */
-struct type_class_float *float_type_new(const char *name,
- size_t mantissa_len,
- size_t exp_len, int byte_order,
- size_t alignment);
-void float_type_free(struct type_class_float *float_class);
+/**
+@brief Babeltrace's boolean type.
-/*
- * A GQuark can be translated to/from strings with g_quark_from_string() and
- * g_quark_to_string().
- */
-GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v);
-GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v);
-uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
- size_t len, int byte_order, GQuark q);
-int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
- size_t len, int byte_order, GQuark q);
-void enum_signed_insert(struct type_class_enum *enum_class,
- int64_t v, GQuark q);
-void enum_unsigned_insert(struct type_class_enum *enum_class,
- uint64_t v, GQuark q);
-
-struct type_class_enum *enum_type_new(const char *name,
- size_t len, int byte_order,
- int signedness,
- size_t alignment);
-void enum_type_free(struct type_class_enum *enum_class);
-
-#endif /* _BABELTRACE_TYPES_H */
+Use only the #BT_FALSE and #BT_TRUE definitions for #bt_bool parameters.
+It is guaranteed that the library functions which return a #bt_bool
+value return either #BT_FALSE or #BT_TRUE.
+
+You can always test the truthness of a #bt_bool value directly, without
+comparing it to #BT_TRUE directly:
+
+@code
+bt_bool ret = bt_some_function(...);
+
+if (ret) {
+ // ret is true
+}
+@endcode
+*/
+typedef int bt_bool;
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_TYPES_H */