Fixed some windows issues

This commit is contained in:
2024-12-06 16:27:19 +01:00
parent fd62fb822d
commit f73ca0eaec
4 changed files with 27 additions and 13 deletions

View File

@ -55,7 +55,9 @@
"text_encoding": "cpp", "text_encoding": "cpp",
"typeinfo": "cpp", "typeinfo": "cpp",
"variant": "cpp", "variant": "cpp",
"sstream": "cpp" "sstream": "cpp",
"fstream": "cpp",
"iomanip": "cpp"
}, },
"C_Cpp.codeAnalysis.clangTidy.checks.disabled": [ "C_Cpp.codeAnalysis.clangTidy.checks.disabled": [
"modernize-use-trailing-return-type", "modernize-use-trailing-return-type",

View File

@ -95,12 +95,12 @@ class ArgManager {
template<typename T> template<typename T>
std::optional<T> get(const int id) { std::optional<T> get(const unsigned int id) {
if(id < pos_argument.size()) return Argument<T>::get(pos_argument[id]); if((unsigned int) id < pos_argument.size()) return Argument<T>::get(pos_argument[id]);
return std::make_optional<T>(); return std::make_optional<T>();
} }
std::istream& get_input(const int id) { std::istream& get_input(const unsigned int id) {
if(id < pos_argument.size()) return ArgInput::get(pos_argument[id]); if(id < pos_argument.size()) return ArgInput::get(pos_argument[id]);
return util::cin; return util::cin;
} }
@ -171,7 +171,7 @@ class ArgFactory {
if(flag) { if(flag) {
parse_flag(manager, flag); parse_flag(manager, flag);
} }
int i = 0; unsigned int i = 0;
for(const auto& arg : vec) { for(const auto& arg : vec) {
std::shared_ptr<_Argument> a; std::shared_ptr<_Argument> a;
if(i >= pos_arg_rules.size()) throw std::invalid_argument("More arguments then excpected"); if(i >= pos_arg_rules.size()) throw std::invalid_argument("More arguments then excpected");

View File

@ -3,6 +3,10 @@
#include <istream> #include <istream>
#include <streambuf> #include <streambuf>
#ifdef _WIN32
#include <iostream>
#endif
namespace fsh::util namespace fsh::util
{ {
@ -16,7 +20,7 @@ namespace fsh::util
*/ */
void prepTerminal(); void prepTerminal();
#if defined(__unix__) || defined(__APPLE__) #ifndef _WIN32
class CursorIStreamBuffer : public std::streambuf { class CursorIStreamBuffer : public std::streambuf {
public: public:
@ -52,9 +56,12 @@ public:
private: private:
CursorIStreamBuffer buffer; CursorIStreamBuffer buffer;
}; };
extern CursorIStream cin; extern CursorIStream cin;
#else
extern std::istream& cin;
#endif #endif

View File

@ -1,10 +1,14 @@
#ifdef WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h> #include <unistd.h>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <termios.h> #include <termios.h>
#endif #endif
@ -15,18 +19,17 @@
namespace fsh::util namespace fsh::util
{ {
#ifndef WIN32 #ifndef _WIN32
struct termios prev_attr; struct termios prev_attr;
void resetTerminal() { void resetTerminal() {
tcsetattr(STDIN_FILENO, TCSANOW, &prev_attr); tcsetattr(STDIN_FILENO, TCSANOW, &prev_attr);
} }
#endif #endif
void prepTerminal() { void prepTerminal() {
#ifdef WIN32 #ifdef _WIN32
/* Ovaj deo koda je namenjen da omoguci koriscenje neke ansi-escape sekvence na windows platformi */ /* Ovaj deo koda je namenjen da omoguci koriscenje neke ansi-escape sekvence na windows platformi */
#else #else
@ -52,7 +55,7 @@ void prepTerminal() {
} }
#if defined(__unix__) || defined(__APPLE__) #ifndef _WIN32
int CursorIStreamBuffer::underflow() { int CursorIStreamBuffer::underflow() {
if(gptr() < egptr()) return traits_type::to_int_type(*gptr()); if(gptr() < egptr()) return traits_type::to_int_type(*gptr());
@ -138,7 +141,9 @@ int CursorIStreamBuffer::readInputToNewLine(){
} }
CursorIStream cin; CursorIStream cin;
#else
std::istream& cin = std::cin;
#endif #endif
} }