Truxton artifact type destroy

From truxwiki.com
Jump to navigation Jump to search

This destroys an object created by the truxton_artifact_type_create() call.

Syntax

void truxton_artifact_type_destroy( uint64_t artifact_type_handle );

Parameters

artifact_type_handle

The handle to the object created by the truxton_artifact_type_create() call.

Sample

void create_artifact_type( void )
{
   uint64_t truxton = truxton_create();

   uint64_t artifact_type = truxton_artifact_type_create( truxton );

   truxton_artifact_type_set_id( artifact_type, 21212 );
   truxton_artifact_type_set_short_name( artifact_type, "VIN" );
   truxton_artifact_type_set_long_name( artifact_type, "Vehicle Identification Number" );

   if ( truxton_artifact_type_save( artifact_type ) == 0 )
   {
      printf("Cannot save artifact type to the database.\n" );
   }
   else
   {
      char type_name[ 128 ];
      char description[ 128 ];

      uint64_t new_id = truxton_artifact_type_get_id( artifact_type );

      truxton_artifact_type_get_short_name( artifact_type, type_name, sizeof( type_name ) );
      truxton_artifact_type_get_long_name( artifact_type, description, sizeof( description ) );

      printf( "Created artifact type id %" PRIu64 " for %s - %s\n", new_id, type_name, description );
   }

   truxton_artifact_type_destroy( artifact_type );
   truxton_destroy( truxton );
}

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.