Files
tft/src/utils.hpp
T
2023-02-25 21:52:00 +02:00

62 lines
1.3 KiB
C++

#pragma once
#include <utility>
#include <ncursesw/ncurses.h>
#include "common/basicTypes.h"
/* template <class Vec> */
/* Vec& operator+=(Vec& lhs, Vec&& rhs) // Combine 2 vectors */
/* { */
/* lhs.reserve(lhs.size() + rhs.size()); */
/* for(auto&& el: rhs) */
/* lhs.push_back( std::move(el) ); */
/* return lhs; */
/* } */
/* template <class Vec> */
/* Vec& operator+=(Vec& lhs, const Vec& rhs) // Combine 2 vectors */
/* { */
/* lhs.reserve(lhs.size() + rhs.size()); */
/* for(const auto& el: rhs) */
/* lhs.push_back(el); */
/* return lhs; */
/* } */
using fd_t = int; /* file descriptor */
struct MappedFile
{
char* data;
unsigned len;
};
void init();
MappedFile mapfile(fd_t);
fd_t openOrDie(const char* path);
template <class Vec>
void remove(Vec& vec, size_t pos) /* Remove from vector by moving the last element in its place */
{
vec[pos] = vec[vec.size() - 1];
vec.pop_back();
}
inline I32 min(I32 a, I32 b)
{
return a <= b ? a : b;
}
inline I32 max(I32 a, I32 b)
{
return a >= b ? a : b;
}
/* wheather a pad with the given coordinates will be visible */
bool willBeVisible(I16 drawY, I16 drawX, U16 height, U16 width);
/* like pnoutrefresh but pminrow,col are calculated based on width,height and
top left coords, which can be negative (outside the screen) */
void drawpad(WINDOW* pad, I16 drawY, I16 drawX);