Home | About | Partners | Contact Us
VA Linux Systems

yakbase: Basic services for C development

Yakbase is a microlibrary (currently only a few tiny headers!) which provides very, very basic services for C and C++ development. Currently, it only provides two services:
  • yak_contract: Flexible support for assertion handling
  • yak_log: flexible support for in-program log messages
Both yak_contract and yak_log provide user-definable "disciplines" by which the behaviour of the library can be changed dynamically by the end-user; for example, yak_contract allows the user to define a discipline containing handlers for printing assertion failure messages and assertion failure behaviour. If the developer does not like the default behaviour (print a message to stdout and then call assert()), they can redefine it to their liking (such as, say, writing a message to a file and then throwing a C++ exception) simply by setting handler hooks.

Yak_log provides basic "log a debug message" features using macros and standard printf() formatting conventions. Other macros support adding "levels" of messages or a 32-bit mask, which gives the developer a bit of flexibility.

Both yak_contract and yak_log use macros which can be entirely disabled in production code, allowing the developer to throw in a lot of scaffolding and strip it away easily for the final build.

While none of this is groundbreaking, I wanted a library that was extremely small and lightweight, and did not find anything immediately that called out to me. Hopefully others will find this as useful as I do.

Sample

Here's a totally totally facetious sample of code using yak_contract and yak_log:

double
mock_square_root( double x )
{
  REQUIRE( x >= 0 );
  YAK_MLOG( MASK_FILE_MATH_C | MASK_LOG_FUNCTION_ENTRY, 
    ( "mock_square_root entered with argument: %f", x ) );
  double result = sqrt( x );
  ENSURE( result * result = x );
  YAK_MLOG( MASK_FILE_MATH_C | MASK_LOG_FUNCTION_EXIT,
    ( "mock_square_root exited with result: %f", result ) );
  return result;
}

Downloadables

Yakbase is currently not released in any sort of packaged form as it is in wee alpha stages. Feel free to examine the cvs tree at the sourceforge prokect page at http://sourceforge.net/projects/yakbase.

Hosted by Sourceforge

This project is hosted by the kind folks at SourceForge Logo
All trademarks and copyrights on this page are properties of their respective owners. Forum comments are owned by the poster. The rest is copyright ©1999-2000 VA Linux Systems, Inc.