Initial commit

Tue, 16 Jul 2013 23:53:31 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Jul 2013 23:53:31 +0300
changeset 0
bb264814dd81
child 1
c9b22c06307c

Initial commit

.gitignore file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/src.pro file | annotate | diff | comparison | revisions
src/types.cpp file | annotate | diff | comparison | revisions
src/types.h file | annotate | diff | comparison | revisions
zandemo.pro file | annotate | diff | comparison | revisions
--- /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
--- /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
--- /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
--- /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
--- /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 <QObject>
+#include <QStringList>
+#include <QTextStream>
+#include <assert.h>
+#include "types.h"
+
+str doFormat( std::vector<StringFormatArg> 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<StringFormatArg> 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
--- /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 <QString>
+#include <QList>
+
+typedef QString str;
+typedef QChar qchar;
+template<class T> using list = QList<T>;
+typedef unsigned int uint;
+typedef unsigned short ushort;
+typedef unsigned long ulong;
+template<class T> using initlist = std::initializer_list<T>;
+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<class T> StringFormatArg( const list<T>& 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<StringFormatArg> 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
--- /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

mercurial