# HG changeset patch # User Teemu Piippo # Date 1374008011 -10800 # Node ID bb264814dd81ec21628d884dca9087a945973d3a Initial commit diff -r 000000000000 -r bb264814dd81 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,5 @@ +Makefile +zandemo.kdev4 +*.o +ui_*.h +zandemo diff -r 000000000000 -r bb264814dd81 src/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cpp Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,28 @@ +#include "types.h" + +int main() { + print ("Hello world! This is " APPNAME " %1\n", versionString() ); +} + +QString versionString() { + str text = fmt( "v%1.%2", VERSION_MAJOR, VERSION_MINOR ); +#if VERSION_PATCH != 0 + text += fmt( ".%3", VERSION_PATCH ); +#endif + +#if BUILD_ID == BUILD_INTERNAL + text += "-intern"; +#elif BUILD_ID == BUILD_ALPHA + text += "-alpha"; +#elif BUILD_ID == BUILD_BETA + text += "-beta"; +#elif BUILD_ID == BUILD_RC + text += fmt( "-rc%1", RC_ID ); +#elif BUILD_ID == BUILD_RELEASE + text += "-rel"; +#else +# error Invalid build code! +#endif // BUILD_ID + + return text; +} \ No newline at end of file diff -r 000000000000 -r bb264814dd81 src/main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.h Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,21 @@ +#ifndef MAIN_H +#define MAIN_H + +#define APPNAME "ZanDemo" +#define UNIXNAME "zandemo" +#define VERSION_MAJOR 0 +#define VERSION_MINOR 0 +#define VERSION_PATCH 999 +#define BUILD_ID BUILD_INTERNAL +#define RC_ID 0 + +#define BUILD_INTERNAL 0 +#define BUILD_ALPHA 1 +#define BUILD_BETA 2 +#define BUILD_RC 3 +#define BUILD_RELEASE 4 + +class QString; +QString versionString(); + +#endif // MAIN_H \ No newline at end of file diff -r 000000000000 -r bb264814dd81 src/src.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/src.pro Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,13 @@ +TARGET = ../zandemo +DEPENDPATH += . +INCLUDEPATH += . +# RC_FILE = ../ldforge.rc +# RESOURCES = ../ldforge.qrc +RCC_DIR = ./build/ +OBJECTS_DIR = ./build/ +MOC_DIR = ./build/ +RCC_DIR = ./build/ +SOURCES = *.cpp +HEADERS = *.h +# FORMS = ui/*.ui +QMAKE_CXXFLAGS += -std=c++0x \ No newline at end of file diff -r 000000000000 -r bb264814dd81 src/types.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/types.cpp Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include "types.h" + +str doFormat( std::vector args ) { + assert( args.size() >= 1 ); + str text = args[0].value(); + + for( uchar i = 1; i < args.size(); ++i ) + text = text.arg( args[i].value() ); + + return text; +} + +void doPrint( initlist args ) { + printf( "%s", doFormat( args ).toStdString().c_str() ); +} + +// ============================================================================= +StringFormatArg::StringFormatArg( const str& v ) { m_val = v; } +StringFormatArg::StringFormatArg( const char& v ) { m_val = v; } +StringFormatArg::StringFormatArg( const uchar& v ) { m_val = v; } +StringFormatArg::StringFormatArg( const qchar& v ) { m_val = v; } +StringFormatArg::StringFormatArg( const float& v ) { m_val = str::number( v ); } +StringFormatArg::StringFormatArg( const double& v ) { m_val = str::number( v ); } +StringFormatArg::StringFormatArg( const char* v ) { m_val = v; } +StringFormatArg::StringFormatArg( const void* v ) { m_val.sprintf( "%p", v ); } \ No newline at end of file diff -r 000000000000 -r bb264814dd81 src/types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/types.h Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,91 @@ +#ifndef TYPES_H +#define TYPES_H + +#include "main.h" +#include +#include + +typedef QString str; +typedef QChar qchar; +template using list = QList; +typedef unsigned int uint; +typedef unsigned short ushort; +typedef unsigned long ulong; +template using initlist = std::initializer_list; +using std::size_t; + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +// StringFormatArg +// +// Converts a given value into a string that can be retrieved with ::value (). +// Used as the argument type to the formatting functions, hence its name. +// ============================================================================= +class StringFormatArg { +public: + StringFormatArg( const str& v ); + StringFormatArg( const char& v ); + StringFormatArg( const uchar& v ); + StringFormatArg( const qchar& v ); + +#define NUMERIC_FORMAT_ARG(T,C) \ + StringFormatArg (const T& v) { \ + char valstr[32]; \ + sprintf (valstr, "%" #C, v); \ + m_val = valstr; \ + } + + NUMERIC_FORMAT_ARG( int, d ) + NUMERIC_FORMAT_ARG( short, d ) + NUMERIC_FORMAT_ARG( long, ld ) + NUMERIC_FORMAT_ARG( uint, u ) + NUMERIC_FORMAT_ARG( ushort, u ) + NUMERIC_FORMAT_ARG( ulong, lu ) + + StringFormatArg( const float& v ); + StringFormatArg( const double& v ); + StringFormatArg( const char* v ); + StringFormatArg( const void* v ); + + template StringFormatArg( const list& v ) { + m_val = "{ "; + uint i = 0; + + for( const T& it : v ) { + if( i++ ) + m_val += ", "; + + StringFormatArg arg( it ); + m_val += arg.value(); + } + + if( i ) + m_val += " "; + + m_val += "}"; + } + + str value() const { + return m_val; + } +private: + str m_val; +}; + +// Formatter function +str doFormat( std::vector< StringFormatArg > args ); + +// printf replacement +void doPrint( initlist args ); // heh + +// Macros to access these functions +#ifndef IN_IDE_PARSER +# define fmt(...) doFormat({ __VA_ARGS__ }) +# define print(...) doPrint({ __VA_ARGS__ }) +#else +str fmt( const char* fmtstr, ... ); +void print( const char* fmtstr, ... ); +#endif + +#endif // TYPES_H \ No newline at end of file diff -r 000000000000 -r bb264814dd81 zandemo.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zandemo.pro Tue Jul 16 23:53:31 2013 +0300 @@ -0,0 +1,7 @@ +###################################################################### +# Automatically generated by qmake (2.01a) ti heinäkuuta 16 23:34:02 2013 +###################################################################### + +TEMPLATE = subdirs +TARGET = zandemo +SUBDIRS += src