This commit is contained in:
Timerix22 2024-03-23 02:20:07 +05:00
parent 72352994f7
commit 58b62eb3a8
7 changed files with 72 additions and 10 deletions

2
dependencies/kerep vendored

@ -1 +1 @@
Subproject commit dd5788f72a909b602592da7861ba717d529be9f3
Subproject commit 0e370b31ba98ec85720a4a5295b995348c247d3c

View File

@ -1,8 +1,6 @@
#include "UsefulException.hpp"
#include <sstream>
namespace GraphC {
UsefulException_::UsefulException_(std::string _message, std::string _file, std::string _func, int _line_n)
: message(_message), file(_file), function(_func), line_n(_line_n)
{
@ -15,5 +13,3 @@ UsefulException_::UsefulException_(std::string _message, std::string _file, std:
char const* UsefulException_::what() const noexcept {
return complete_text.c_str();
}
}

View File

@ -3,8 +3,6 @@
#include <stdexcept>
#include <string>
namespace GraphC {
#define UsefulException(MSG) UsefulException_(MSG, __FILE__, __func__, __LINE__)
class UsefulException_ : public std::exception {
@ -19,5 +17,3 @@ public:
virtual char const* what() const noexcept;
};
}

66
src/format.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <string>
#include <sstream>
#include <stdarg.h>
#include "UsefulException.hpp"
#include "../dependencies/kerep/src/base/base.h"
std::string format(const std::string format_str, size_t args_count, ...){
va_list vl;
va_start(vl, args_count);
std::stringstream ss;
for(size_t i = 0; i < format_str.length(); i++){
char c = format_str[i];
// format specifier
if(c == '%'){
c = format_str[++i];
bool l = false;
while(c == 'l'){
l = true;
c = format_str[++i];
}
switch(c){
case 'u':
if(l) ss<<(u64)va_arg(vl, u64);
else ss<<(u32)va_arg(vl, u32);
break;
case 'i':
case 'd':
if(l) ss<<(i64)va_arg(vl, i64);
else ss<<(i32)va_arg(vl, i32);
break;
case 'f':
// f32 is promoted to f64 when passed through '...'
ss<<(f64)va_arg(vl, f64);
break;
case 'p':
ss<<(void*)va_arg(vl, void*);
break;
case 'x':
if(l) ss<<std::hex<<(u64)va_arg(vl, u64);
else ss<<std::hex<<(u32)va_arg(vl, u32);
break;
case 's': {
const char* cptr = va_arg(vl,char*);
if(cptr != nullptr)
ss<<cptr;
else ss<<"<nullptr>";
break;
}
case 'c':
ss<<(char)va_arg(vl,int);
break;
default:
throw UsefulException("invalid format cpecifier");
}
}
// regular character
else ss<<c;
}
va_end(vl);
return ss.str();
}

3
src/format.hpp Normal file
View File

@ -0,0 +1,3 @@
#include <string>
std::string format(const std::string format_str, size_t args_count, ...);

View File

@ -12,7 +12,7 @@ ImFont* _ImFont_LoadEmbedded(const void* data, int data_size, const char* font_n
ImGuiIO& io = ImGui::GetIO();
font_size *= dpi;
ImFontConfig font_cfg = ImFontConfig();
sprintf_s(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", font_name, font_size);
ksprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", font_name, font_size);
return io.Fonts->AddFontFromMemoryCompressedTTF(data, data_size, font_size, &font_cfg);
}

View File

@ -4,6 +4,7 @@
#include "../../dependencies/SDL2/include/SDL.h"
#include "../../dependencies/SDL2/include/SDL_opengl.h"
#include "../../dependencies/imgui/imgui.h"
#include "../format.hpp"
#include "NodeEditor.hpp"
#include "imgui_extensions.hpp"
#include "fonts.hpp"