Last active
November 21, 2021 15:12
-
-
Save KiJeong-Lim/16fb437700d299e66c8093ad6f983323 to your computer and use it in GitHub Desktop.
QVE THE FVCK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include "prettyprinter.hpp" | |
int main() | |
{ | |
using namespace std; | |
PPrinter printer1 = PPrinter::ostream<2, 16>(); | |
PPrinter printer2 = PPrinter::ostream<2, 16>(); | |
printf("printer1.buf_ptr = %u\n", printer1.get_buf_ptr()); | |
printf("printer2.buf_ptr = %u\n", printer2.get_buf_ptr()); | |
return 0; | |
} | |
/* output: | |
printer1.buf_ptr = 4227264 | |
printer2.buf_ptr = 4227328 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PRETTYPRINTER | |
#define PRETTYPRINTER | |
#include <cstdlib> | |
#define PPrinter PrettyPrinter<__LINE__> | |
template <int printer_id> | |
class PrettyPrinter { | |
int width; | |
int height; | |
char *buf_ptr; | |
public: | |
PrettyPrinter(PrettyPrinter const &other) | |
: width{ other.width } | |
, height{ other.height } | |
, buf_ptr{ other.buf_ptr } | |
{ | |
} | |
~PrettyPrinter() | |
{ | |
} | |
private: | |
PrettyPrinter(int _width, int _height, char *_buf_ptr) | |
: width{ _width } | |
, height{ _height } | |
, buf_ptr{ _buf_ptr } | |
{ | |
} | |
public: | |
char *get_buf_ptr() const | |
{ | |
return buf_ptr; | |
} | |
template <size_t NumberOfRows, size_t NumberOfCols> | |
static constexpr | |
PrettyPrinter ostream() | |
{ | |
static char buf[NumberOfRows][NumberOfCols + 1] = { }; | |
return { ._width = static_cast<int>(NumberOfCols), ._height = static_cast<int>(NumberOfRows), ._buf_ptr = static_cast<char *>(&buf[0][0]) }; | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment