From aad572fe389eac2ac8a55c504609069366af6a52 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sun, 15 Sep 2019 15:32:39 +0000 Subject: [PATCH] Feature: Added igloo_instance_validate() --- include/igloo/igloo.h | 13 +++++++++++++ src/libigloo.c | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/include/igloo/igloo.h b/include/igloo/igloo.h index 01f151e..67d7dc4 100644 --- a/include/igloo/igloo.h +++ b/include/igloo/igloo.h @@ -113,6 +113,19 @@ igloo_objecthandler_t * igloo_instance_get_logger(igloo_ro_t self); */ igloo_error_t igloo_instance_log(igloo_ro_t self, igloo_ro_t msg); +/* Validate an instance. + * + * Note: This is very useful when a instance is passed from a user to a library. + * + * Parameters: + * self + * An instance to validate. + * Returns: + * igloo_ERROR_NONE if self is a valid instance, or error code otherwise. + */ +igloo_error_t igloo_instance_validate_raw(igloo_ro_t self); +#define igloo_instance_validate(x) igloo_instance_validate_raw((x)) + #ifdef __cplusplus } #endif diff --git a/src/libigloo.c b/src/libigloo.c index d82f38c..79f5a6a 100644 --- a/src/libigloo.c +++ b/src/libigloo.c @@ -241,3 +241,12 @@ igloo_error_t igloo_instance_log(igloo_ro_t self, igloo_ro_t msg) return ret; } + +igloo_error_t igloo_instance_validate_raw(igloo_ro_t self) +{ + if (igloo_RO_IS_VALID(self, igloo_instance_t)) { + return igloo_ERROR_NONE; + } else { + return igloo_ERROR_GENERIC; + } +}