Skip to content

Instantly share code, notes, and snippets.

@NocturnDragon
Created June 27, 2011 17:21
Show Gist options
  • Save NocturnDragon/1049309 to your computer and use it in GitHub Desktop.
Save NocturnDragon/1049309 to your computer and use it in GitHub Desktop.
Computable Include
////////////////////////////////////////////////////////////
// <License>
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Title: Computable Include
////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// Macro: computable_platform_include(className)
// ------------------
//
// A macro used to compute what .h to include based on the class
// name passed and to the SYSTEM_PLATFORM.
//
// (start example)
//
// #define SYSTEM_PLATFORM Win32
// #include "computable_include.h"
//
// #include computable_platform_include(MyClass)
//
// (end example)
//
// Will be translate by the C Preprocessor to
//
// (start example)
//
// #include "Win32/MyClassWin32.h"
//
// (end example)
//
// This permits to avoid all sorts of
//
// (start example)
//
// #if defined(SYSTEM_PLATFORM_Win32)
// #include "Win32/MyClassWin32.h"
// #elif defined(SYSTEM_PLATFORM_Cocoa)
// #include "Cocoa/MyClassCocoa.h"
// #else
// #error Platform not supported
// #endif
//
// (end example)
//
// This could be extended as needed as in computable_system_include, computable_graphic_api_include
//
// See Also:
//
// <SYSTEM_PLATFORM>
//
//////////////////////////////////////////////////////////////
#ifndef SYSTEM_PLATFORM
#error You must define the symbol SYSTEM_PLATFORM
#else
#define COMPUTABLE_PLATFORM_INCLUDE_QMAKESTR(x) #x
#define COMPUTABLE_PLATFORM_INCLUDE_MAKESTR(x) COMPUTABLE_PLATFORM_INCLUDE_QMAKESTR(x)
#define COMPUTABLE_PLATFORM_INCLUDE_MERGE(x, y) ./y/x.h
#define COMPUTABLE_PLATFORM_INCLUDE_IMP(x) COMPUTABLE_PLATFORM_INCLUDE_MERGE(x, SYSTEM_PLATFORM)
#define computable_platform_include(x) COMPUTABLE_PLATFORM_INCLUDE_MAKESTR( COMPUTABLE_PLATFORM_INCLUDE_IMP( x ) )
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment