Start fleshing out tracing library
This commit is contained in:
		
							
								
								
									
										1
									
								
								deps/ox/src/ox/std/CMakeLists.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								deps/ox/src/ox/std/CMakeLists.txt
									
									
									
									
										vendored
									
									
								
							@@ -24,6 +24,7 @@ install(
 | 
				
			|||||||
		strops.hpp
 | 
							strops.hpp
 | 
				
			||||||
		std.hpp
 | 
							std.hpp
 | 
				
			||||||
		types.hpp
 | 
							types.hpp
 | 
				
			||||||
 | 
							typetraits.hpp
 | 
				
			||||||
	DESTINATION
 | 
						DESTINATION
 | 
				
			||||||
		include/ox/std
 | 
							include/ox/std
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								deps/ox/src/ox/std/math.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								deps/ox/src/ox/std/math.hpp
									
									
									
									
										vendored
									
									
								
							@@ -8,6 +8,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "typetraits.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace ox {
 | 
					namespace ox {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename T>
 | 
					template<typename T>
 | 
				
			||||||
@@ -20,4 +22,13 @@ inline const T &max(const T &a, const T &b) {
 | 
				
			|||||||
	return a > b ? a : b;
 | 
						return a > b ? a : b;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<typename I>
 | 
				
			||||||
 | 
					inline I pow(I v, int e) {
 | 
				
			||||||
 | 
						I out = 1;
 | 
				
			||||||
 | 
						for (I i = 0; i < e; i++) {
 | 
				
			||||||
 | 
							out *= v;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return out;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								deps/ox/src/ox/std/std.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								deps/ox/src/ox/std/std.hpp
									
									
									
									
										vendored
									
									
								
							@@ -16,4 +16,5 @@
 | 
				
			|||||||
#include "strops.hpp"
 | 
					#include "strops.hpp"
 | 
				
			||||||
#include "string.hpp"
 | 
					#include "string.hpp"
 | 
				
			||||||
#include "types.hpp"
 | 
					#include "types.hpp"
 | 
				
			||||||
 | 
					#include "typetraits.hpp"
 | 
				
			||||||
#include "vector.hpp"
 | 
					#include "vector.hpp"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										31
									
								
								deps/ox/src/ox/std/string.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										31
									
								
								deps/ox/src/ox/std/string.hpp
									
									
									
									
										vendored
									
									
								
							@@ -29,6 +29,12 @@ class BString {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		const BString &operator=(char *str);
 | 
							const BString &operator=(char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const BString &operator=(int64_t i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const BString &operator+=(const char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const BString &operator+=(char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		bool operator==(const BString &other);
 | 
							bool operator==(const BString &other);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		char *data();
 | 
							char *data();
 | 
				
			||||||
@@ -59,6 +65,13 @@ BString<size>::BString(const char *str) {
 | 
				
			|||||||
	*this = str;
 | 
						*this = str;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<size_t size>
 | 
				
			||||||
 | 
					const BString<size> &BString<size>::operator=(int64_t i) {
 | 
				
			||||||
 | 
						char str[65];
 | 
				
			||||||
 | 
						ox_itoa(i, str);
 | 
				
			||||||
 | 
						return this->operator=(str);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<size_t size>
 | 
					template<size_t size>
 | 
				
			||||||
const BString<size> &BString<size>::operator=(const char *str) {
 | 
					const BString<size> &BString<size>::operator=(const char *str) {
 | 
				
			||||||
	size_t strLen = ox_strlen(str) + 1;
 | 
						size_t strLen = ox_strlen(str) + 1;
 | 
				
			||||||
@@ -76,6 +89,24 @@ const BString<size> &BString<size>::operator=(char *str) {
 | 
				
			|||||||
	return *this = (const char*) str;
 | 
						return *this = (const char*) str;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<size_t size>
 | 
				
			||||||
 | 
					const BString<size> &BString<size>::operator+=(const char *str) {
 | 
				
			||||||
 | 
						size_t strLen = ox_strlen(str) + 1;
 | 
				
			||||||
 | 
						auto currentSize = size();
 | 
				
			||||||
 | 
						if (cap() < currentSize + strLen) {
 | 
				
			||||||
 | 
							strLen = cap() - currentSize;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ox_memcpy(m_buff + currentSize, str, strLen);
 | 
				
			||||||
 | 
						// make sure last element is a null terminator
 | 
				
			||||||
 | 
						m_buff[cap() - 1] = 0;
 | 
				
			||||||
 | 
						return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<size_t size>
 | 
				
			||||||
 | 
					const BString<size> &BString<size>::operator+=(char *str) {
 | 
				
			||||||
 | 
						return *this = (const char*) str;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<size_t buffLen>
 | 
					template<size_t buffLen>
 | 
				
			||||||
bool BString<buffLen>::operator==(const BString<buffLen> &other) {
 | 
					bool BString<buffLen>::operator==(const BString<buffLen> &other) {
 | 
				
			||||||
	bool retval = true;
 | 
						bool retval = true;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										29
									
								
								deps/ox/src/ox/std/strops.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										29
									
								
								deps/ox/src/ox/std/strops.cpp
									
									
									
									
										vendored
									
									
								
							@@ -6,6 +6,8 @@
 | 
				
			|||||||
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "math.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "strops.hpp"
 | 
					#include "strops.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ox_strcmp(const char *str1, const char *str2) {
 | 
					int ox_strcmp(const char *str1, const char *str2) {
 | 
				
			||||||
@@ -89,3 +91,30 @@ int ox_atoi(const char *str) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return total;
 | 
						return total;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *ox_itoa(int64_t v, char *str) {
 | 
				
			||||||
 | 
						auto mod = 1000000000000000000;
 | 
				
			||||||
 | 
						constexpr auto base = 10;
 | 
				
			||||||
 | 
						auto it = 0;
 | 
				
			||||||
 | 
						if (v < 0) {
 | 
				
			||||||
 | 
							str[it] = '-';
 | 
				
			||||||
 | 
							it++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						while (mod) {
 | 
				
			||||||
 | 
							auto digit = v / mod;
 | 
				
			||||||
 | 
							v %= mod;
 | 
				
			||||||
 | 
							mod /= base;
 | 
				
			||||||
 | 
							if (it or digit) {
 | 
				
			||||||
 | 
								int start;
 | 
				
			||||||
 | 
								if (digit < 10) {
 | 
				
			||||||
 | 
									start = '0';
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									start = 'a';
 | 
				
			||||||
 | 
									digit -= 10;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								str[it] = start + digit;
 | 
				
			||||||
 | 
								it++;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return str;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								deps/ox/src/ox/std/strops.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								deps/ox/src/ox/std/strops.hpp
									
									
									
									
										vendored
									
									
								
							@@ -9,6 +9,7 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "types.hpp"
 | 
					#include "types.hpp"
 | 
				
			||||||
 | 
					#include "typetraits.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ox_strcmp(const char *str1, const char *str2);
 | 
					int ox_strcmp(const char *str1, const char *str2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -25,3 +26,5 @@ int ox_lastIndexOf(const char *str, int character, int maxLen = 0xFFFFFFFF);
 | 
				
			|||||||
int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF);
 | 
					int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ox_atoi(const char *str);
 | 
					int ox_atoi(const char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *ox_itoa(int64_t v, char *str);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										63
									
								
								deps/ox/src/ox/std/typetraits.hpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								deps/ox/src/ox/std/typetraits.hpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright 2015 - 2018 gtalent2@gmail.com
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This Source Code Form is subject to the terms of the Mozilla Public
 | 
				
			||||||
 | 
					 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
				
			||||||
 | 
					 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "types.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace ox {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<class T, T v>
 | 
				
			||||||
 | 
					struct integral_constant {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						using value_type = T;
 | 
				
			||||||
 | 
						using type = integral_constant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static constexpr T value = v;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						constexpr operator value_type() const noexcept {
 | 
				
			||||||
 | 
							return value;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						constexpr value_type operator()() const noexcept {
 | 
				
			||||||
 | 
							return value;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using false_type = ox::integral_constant<bool, false>;
 | 
				
			||||||
 | 
					using true_type = ox::integral_constant<bool, true>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// is_integral /////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<typename T> struct is_integral: ox::false_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<bool>    : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<wchar_t> : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<int8_t>  : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<uint8_t> : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<int16_t> : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<uint16_t>: ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<int32_t> : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<uint32_t>: ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<int64_t> : ox::true_type {};
 | 
				
			||||||
 | 
					template<> struct is_integral<uint64_t>: ox::true_type {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// enable_if ///////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<bool B, class T = void>
 | 
				
			||||||
 | 
					struct enable_if {
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<class T>
 | 
				
			||||||
 | 
					struct enable_if<true, T> {
 | 
				
			||||||
 | 
						using type = T;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										17
									
								
								deps/ox/src/ox/trace/trace.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								deps/ox/src/ox/trace/trace.cpp
									
									
									
									
										vendored
									
									
								
							@@ -6,24 +6,17 @@
 | 
				
			|||||||
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdarg.h>
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <ox/std/std.hpp>
 | 
					#include <ox/std/std.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "trace.hpp"
 | 
					#include "trace.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace ox {
 | 
					namespace ox {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct TraceMsg {
 | 
					OutStream::OutStream(const char *file, int line, const char *ch, const char *msg) {
 | 
				
			||||||
	const char *file;
 | 
						m_msg.file = file;
 | 
				
			||||||
	int line;
 | 
						m_msg.line = line;
 | 
				
			||||||
	uint64_t time;
 | 
						m_msg.ch = ch;
 | 
				
			||||||
	const char *ch;
 | 
						m_msg.msg = msg;
 | 
				
			||||||
	const char *msg;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void trace(const char *file, int line, const char *ch, const char *msg) {
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										31
									
								
								deps/ox/src/ox/trace/trace.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										31
									
								
								deps/ox/src/ox/trace/trace.hpp
									
									
									
									
										vendored
									
									
								
							@@ -8,10 +8,37 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <ox/std/std.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace ox {
 | 
					namespace ox {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void trace(const char *file, int line, const char *ch, const char *msg);
 | 
					struct TraceMsg {
 | 
				
			||||||
 | 
						const char *file;
 | 
				
			||||||
 | 
						int line;
 | 
				
			||||||
 | 
						uint64_t time;
 | 
				
			||||||
 | 
						const char *ch;
 | 
				
			||||||
 | 
						ox::BString<100> msg;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class OutStream {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private:
 | 
				
			||||||
 | 
							TraceMsg m_msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public:
 | 
				
			||||||
 | 
							OutStream() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							OutStream(const char *file, int line, const char *ch, const char *msg = "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							template<typename T>
 | 
				
			||||||
 | 
							OutStream &operator<<(T v) {
 | 
				
			||||||
 | 
								m_msg.msg += " ";
 | 
				
			||||||
 | 
								m_msg.msg += v;
 | 
				
			||||||
 | 
								return *this;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ox_trace(ch, msg) ox::trace(__FILE__, __LINE__, ch, msg)
 | 
					#define oxTrace(ch, msg) ox::OutStream(__FILE__, __LINE__, ch, msg)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user