Truxton artifact type create

From truxwiki.com
Revision as of 16:36, 24 March 2021 by Sam (talk | contribs) (Created page with "This creates an artifact type object. You can use this to extend Truxton with new types of artifacts. =Syntax= <source lang="C"> uint64_t truxton_artifact_type_create( uint64...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This creates an artifact type object. You can use this to extend Truxton with new types of artifacts.

Syntax

uint64_t truxton_artifact_type_create( uint64_t truxton_handle );

Parameters

truxton_handle

The Truxton instance this artifact type will belong. This handle comes from calling truxton_create().

Return value

A handle to an artifact type object.

Remarks

This will create the object that will be written to the [EntityType] table in the database.

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.