Skip to content

Commit

Permalink
refactor: allow better access to object meta value
Browse files Browse the repository at this point in the history
  • Loading branch information
aiq committed Oct 18, 2024
1 parent 80e688a commit 270da16
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
14 changes: 11 additions & 3 deletions doc/clingo/lang/CObject.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ Calls retain_c and release_c on obj.
//***************************************************************** object info
=== object info
==== get_object_desc_c
==== get_meta_c
[source,c]
----
char const* get_object_desc_c( CObject const* obj );
char const* get_meta_c( CObject const* obj );
----
Util function to access the desc attribute of the linked cMeta instance.
Util function to access the linked cMeta instance.
==== get_object_info_c
[source,c]
Expand All @@ -242,6 +242,14 @@ cObjectInfo const* get_object_info_c( CObject const* obj );
Returns the cObjectInfo of the CObject instance obj.
==== meta_is_c
[source,c]
----
bool meta_is_c( CObject const* obj, cMeta const exp[static 1] );
----
Util function that check if the object has the expected meta.
==== sizeof_object_c_
[source,c]
----
Expand Down
5 changes: 4 additions & 1 deletion inc/clingo/lang/CObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ CObject* touch_c( CObject* obj );
object info
*******************************************************************************/
CLINGO_API
char const* get_object_desc_c( CObject const* obj );
cMeta const* get_meta_c( CObject const* obj );

CLINGO_API
cObjectInfo const* get_object_info_c( CObject const* obj );

CLINGO_API
bool meta_is_c( CObject const* obj, cMeta const exp[static 1] );

#define sizeof_object_c_( Type ) \
( \
sizeof_c_( cObjectInfo ) + sizeof_c_( Type ) \
Expand Down
11 changes: 9 additions & 2 deletions src/clingo/lang/CObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ CObject* touch_c( CObject* obj )
*******************************************************************************/

char const* get_object_desc_c( CObject const* obj )
cMeta const* get_meta_c( CObject const* obj )
{
must_exist_c_( obj );

cObjectInfo const* info = get_object_info_c( obj );
return info->meta->desc;
return info->meta;
}

cObjectInfo const* get_object_info_c( CObject const* obj )
Expand All @@ -137,3 +137,10 @@ cObjectInfo const* get_object_info_c( CObject const* obj )
return obj - sizeof( cObjectInfo );
}

bool meta_is_c( CObject const* obj, cMeta const exp[static 1] )
{
must_exist_c_( obj );

cMeta const* meta = get_meta_c( obj );
return meta == exp;
}

0 comments on commit 270da16

Please sign in to comment.