mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-09 00:05:46 +00:00
Add GUI Support
This commit is contained in:
36
src/TextStreams/StdIOReader.cpp
Normal file
36
src/TextStreams/StdIOReader.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "TessesFramework/TextStreams/StdIOReader.hpp"
|
||||
|
||||
|
||||
namespace Tesses::Framework::TextStreams
|
||||
{
|
||||
ConsoleReader::ConsoleReader()
|
||||
{
|
||||
|
||||
}
|
||||
bool ConsoleReader::ReadBlock(std::string& str,size_t len)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
uint8_t* buff = new uint8_t[len];
|
||||
#else
|
||||
uint8_t buff[len];
|
||||
#endif
|
||||
size_t read=0;
|
||||
size_t readTotal=0;
|
||||
uint8_t* buffOff=buff;
|
||||
do {
|
||||
read=fread(buffOff,1,len,stdin);
|
||||
if(read != 0) {readTotal+= read;len-=read; buffOff+=read;}
|
||||
} while(read != 0);
|
||||
if(readTotal == 0) return false;
|
||||
str.append((const char*)buff, readTotal);
|
||||
#if defined(_WIN32)
|
||||
delete buff;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
ConsoleReader StdIn()
|
||||
{
|
||||
return ConsoleReader();
|
||||
}
|
||||
}
|
||||
42
src/TextStreams/StdIOWriter.cpp
Normal file
42
src/TextStreams/StdIOWriter.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "TessesFramework/TextStreams/StdIOWriter.hpp"
|
||||
#if defined(__PS2__)
|
||||
#include <debug.h>
|
||||
#else
|
||||
#include <cstdio>
|
||||
#endif
|
||||
namespace Tesses::Framework::TextStreams
|
||||
{
|
||||
ConsoleWriter::ConsoleWriter(bool isError) : TextWriter()
|
||||
{
|
||||
this->isError=isError;
|
||||
}
|
||||
|
||||
void ConsoleWriter::WriteData(const char* text, size_t len)
|
||||
{
|
||||
#if defined(__PS2__)
|
||||
char lenThing[10];//%.2048s
|
||||
while(len > 0) {
|
||||
int b = std::min((int)2047,(int)len);
|
||||
snprintf(lenThing,18,"%%.%is",b);
|
||||
|
||||
scr_printf(lenThing,text);
|
||||
|
||||
len -= b;
|
||||
text += b;
|
||||
}
|
||||
#else
|
||||
if(isError)
|
||||
fwrite(text,1,len,stderr);
|
||||
else
|
||||
fwrite(text,1,len,stdout);
|
||||
#endif
|
||||
}
|
||||
ConsoleWriter StdOut()
|
||||
{
|
||||
return ConsoleWriter(false);
|
||||
}
|
||||
ConsoleWriter StdErr()
|
||||
{
|
||||
return ConsoleWriter(true);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,15 @@ namespace Tesses::Framework::TextStreams {
|
||||
StreamReader::StreamReader(std::filesystem::path path) : StreamReader(new FileStream(path,"rb"),true)
|
||||
{
|
||||
|
||||
}
|
||||
bool StreamReader::Rewind()
|
||||
{
|
||||
if(this->strm->CanSeek())
|
||||
{
|
||||
this->strm->Seek((int64_t)0,Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
StreamReader::StreamReader(Stream* strm, bool owns) : TextReader()
|
||||
{
|
||||
|
||||
38
src/TextStreams/StringReader.cpp
Normal file
38
src/TextStreams/StringReader.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "TessesFramework/TextStreams/StringReader.hpp"
|
||||
|
||||
namespace Tesses::Framework::TextStreams {
|
||||
StringReader::StringReader()
|
||||
{
|
||||
this->offset=0;
|
||||
this->str="";
|
||||
}
|
||||
StringReader::StringReader(std::string str)
|
||||
{
|
||||
this->offset=0;
|
||||
this->str=str;
|
||||
}
|
||||
size_t& StringReader::GetOffset()
|
||||
{
|
||||
return this->offset;
|
||||
}
|
||||
std::string& StringReader::GetString()
|
||||
{
|
||||
return this->str;
|
||||
}
|
||||
bool StringReader::Rewind()
|
||||
{
|
||||
this->offset=0;
|
||||
return true;
|
||||
}
|
||||
bool StringReader::ReadBlock(std::string& str,size_t sz)
|
||||
{
|
||||
if(this->offset < this->str.size())
|
||||
{
|
||||
size_t len = std::min(sz,this->str.size()-this->offset);
|
||||
str.insert(str.size(),this->str.data()+this->offset,len);
|
||||
offset+=len;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
src/TextStreams/StringWriter.cpp
Normal file
21
src/TextStreams/StringWriter.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "TessesFramework/TextStreams/StringWriter.hpp"
|
||||
|
||||
namespace Tesses::Framework::TextStreams
|
||||
{
|
||||
std::string& StringWriter::GetString()
|
||||
{
|
||||
return this->text;
|
||||
}
|
||||
StringWriter::StringWriter() : TextWriter()
|
||||
{
|
||||
|
||||
}
|
||||
StringWriter::StringWriter(std::string str) : TextWriter()
|
||||
{
|
||||
this->text = str;
|
||||
}
|
||||
void StringWriter::WriteData(const char* text, size_t len)
|
||||
{
|
||||
this->text.append(text,len);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace Tesses::Framework::TextStreams
|
||||
{
|
||||
bool TextReader::Rewind()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int32_t TextReader::ReadChar()
|
||||
{
|
||||
std::string txt;
|
||||
|
||||
@@ -1,7 +1,91 @@
|
||||
#include "TessesFramework/TextStreams/TextWriter.hpp"
|
||||
#include "TessesFramework/Http/HttpUtils.hpp"
|
||||
|
||||
namespace Tesses::Framework::TextStreams
|
||||
{
|
||||
void TextWriter::Write(int64_t n)
|
||||
{
|
||||
std::string text = std::to_string(n);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::Write(uint64_t n)
|
||||
{
|
||||
std::string text = std::to_string(n);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
|
||||
void TextWriter::Write(const void* ptr)
|
||||
{
|
||||
std::string text = "0x";
|
||||
uintptr_t ptr2 = (uintptr_t)ptr;
|
||||
|
||||
for(size_t i = 1; i <= sizeof(ptr); i++)
|
||||
{
|
||||
uint8_t v = (uint8_t)(ptr2 >> (int)((sizeof(ptr) - i) * 8));
|
||||
text.push_back(Tesses::Framework::Http::HttpUtils::NibbleToHex(v >> 4));
|
||||
text.push_back(Tesses::Framework::Http::HttpUtils::NibbleToHex(v));
|
||||
}
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::Write(const char* ptr)
|
||||
{
|
||||
WriteData(ptr,strlen(ptr));
|
||||
}
|
||||
void TextWriter::Write(char c)
|
||||
{
|
||||
WriteData(&c,1);
|
||||
}
|
||||
void TextWriter::Write(double d)
|
||||
{
|
||||
std::string text = std::to_string(d);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
|
||||
|
||||
void TextWriter::WriteLine(int64_t n)
|
||||
{
|
||||
std::string text = std::to_string(n);
|
||||
text.append(newline);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::WriteLine(uint64_t n)
|
||||
{
|
||||
std::string text = std::to_string(n);
|
||||
text.append(newline);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::WriteLine(const void* ptr)
|
||||
{
|
||||
std::string text = "0x";
|
||||
uintptr_t ptr2 = (uintptr_t)ptr;
|
||||
|
||||
for(size_t i = 1; i <= sizeof(ptr); i++)
|
||||
{
|
||||
uint8_t v = (uint8_t)(ptr2 >> (int)((sizeof(ptr) - i) * 8));
|
||||
text.push_back(Tesses::Framework::Http::HttpUtils::NibbleToHex(v >> 4));
|
||||
text.push_back(Tesses::Framework::Http::HttpUtils::NibbleToHex(v));
|
||||
}
|
||||
text.append(newline);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::WriteLine(const char* ptr)
|
||||
{
|
||||
std::string text = ptr;
|
||||
text.append(newline);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::WriteLine(char c)
|
||||
{
|
||||
std::string text = {c};
|
||||
text.append(newline);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
void TextWriter::WriteLine(double d)
|
||||
{
|
||||
std::string text = std::to_string(d);
|
||||
text.append(newline);
|
||||
WriteData(text.c_str(),text.size());
|
||||
}
|
||||
TextWriter::TextWriter()
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
|
||||
Reference in New Issue
Block a user