- added timestamps to output

Tue, 16 Dec 2014 00:15:44 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Dec 2014 00:15:44 +0200
changeset 51
481073b016a9
parent 50
874bbfa55da8
child 52
ae5b486f6882

- added timestamps to output
- removed the silly shouldExit stuff

sources/basics.h file | annotate | diff | comparison | revisions
sources/interface.cpp file | annotate | diff | comparison | revisions
sources/list.h file | annotate | diff | comparison | revisions
sources/main.cpp file | annotate | diff | comparison | revisions
--- a/sources/basics.h	Tue Dec 16 00:05:27 2014 +0200
+++ b/sources/basics.h	Tue Dec 16 00:15:44 2014 +0200
@@ -63,7 +63,6 @@
 using Function = std::function<Signature>;
 
 FUNCTION print_to_console (String a) -> void;
-FUNCTION request_exit() -> void;
 
 template<typename T> inline FUNCTION
 clamp (T a, T b, T c) -> T
--- a/sources/interface.cpp	Tue Dec 16 00:05:27 2014 +0200
+++ b/sources/interface.cpp	Tue Dec 16 00:15:44 2014 +0200
@@ -29,6 +29,7 @@
 */
 
 #include <string.h>
+#include <time.h>
 #include "interface.h"
 #include "network/rconsession.h"
 #include "network/ipaddress.h"
@@ -916,6 +917,17 @@
 			continue;
 		}
 
+		if (g_output[g_output.size() - 1].length() == 0)
+		{
+			time_t now;
+			time (&now);
+			char timestamp[32];
+			strftime (timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime (&now));
+
+			for (char* cp = timestamp; *cp != '\0'; ++cp)
+				g_output[g_output.size() - 1].add_char (*cp);
+		}
+
 		g_output[g_output.size() - 1].add_char (ch);
 	}
 
--- a/sources/list.h	Tue Dec 16 00:05:27 2014 +0200
+++ b/sources/list.h	Tue Dec 16 00:15:44 2014 +0200
@@ -68,9 +68,11 @@
 	auto find (const T& needle) const -> ConstIterator;
 	auto find (Function<bool (T const&)> func) -> Iterator;
 	auto find (Function<bool (T const&)> func) const -> ConstIterator;
+	auto first() -> T&;
 	auto first() const -> const T&;
 	auto insert (int pos, const T& value) -> void;
 	auto is_empty() const -> bool;
+	auto last() -> T&;
 	auto last() const -> const T&;
 	auto merge (const Self& other) -> void;
 	auto pop (T& val) -> bool;
@@ -484,6 +486,14 @@
 // -------------------------------------------------------------------------------------------------
 //
 template<typename T, typename C>
+auto Container<T, C>::first() -> T&
+{
+	return *m_container.begin();
+}
+
+// -------------------------------------------------------------------------------------------------
+//
+template<typename T, typename C>
 auto Container<T, C>::first() const -> const T&
 {
 	return *m_container.cbegin();
@@ -492,6 +502,14 @@
 // -------------------------------------------------------------------------------------------------
 //
 template<typename T, typename C>
+auto Container<T, C>::last() -> T&
+{
+	return *(m_container.end() - 1);
+}
+
+// -------------------------------------------------------------------------------------------------
+//
+template<typename T, typename C>
 auto Container<T, C>::last() const -> const T&
 {
 	return *(m_container.cend() - 1);
--- a/sources/main.cpp	Tue Dec 16 00:05:27 2014 +0200
+++ b/sources/main.cpp	Tue Dec 16 00:15:44 2014 +0200
@@ -35,8 +35,6 @@
 #include "huffman/huffman.h"
 #include "interface.h"
 
-static bool g_shouldExit = false;
-
 // -------------------------------------------------------------------------------------------------
 //
 FUNCTION
@@ -60,9 +58,6 @@
 	{
 		for (;;)
 		{
-			if (g_shouldExit)
-				break;
-
 			fd_set fdset;
 			int highest = 0;
 			timeval timeout;
@@ -98,11 +93,3 @@
 
 	return EXIT_SUCCESS;
 }
-
-// -------------------------------------------------------------------------------------------------
-//
-FUNCTION
-request_exit() -> void
-{
-	g_shouldExit = true;
-}

mercurial