Commit f946a7bc authored by Philip Trettner's avatar Philip Trettner

Removed Qt5 dependency

parent 8e0104c1
......@@ -9,10 +9,7 @@ target_include_directories(aion PUBLIC src/)
if (MSVC)
target_compile_options(aion PUBLIC /MP)
else()
target_compile_options(aion PRIVATE -Wall -Werror)
target_compile_options(aion PRIVATE -Wall -Werror -fPIC)
target_compile_options(aion PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>)
endif()
find_package(Qt5Core REQUIRED)
target_link_libraries(aion PRIVATE ${Qt5Core_LIBRARIES})
......@@ -2,12 +2,11 @@
#include "common/format.hh"
#include <string>
#include <algorithm>
#include <vector>
#include <mutex>
#include <QString>
#include <QFileInfo>
#include "ActionEntry.hh"
using namespace aion;
......@@ -48,18 +47,15 @@ void writeTime(ActionEntry &e)
std::string ActionLabel::shortDesc() const
{
auto filename = QFileInfo(QString::fromStdString(mFile)).fileName().toStdString();
auto filename = mFile;
if (filename.find('/') != std::string::npos)
filename = filename.substr(filename.rfind('/') + 1);
if (filename.find('\\') != std::string::npos)
filename = filename.substr(filename.rfind('\\') + 1);
auto name = mName;
if (name.empty())
{
QString n = QString::fromStdString(mFunction);
n = n.mid(0, n.indexOf('('));
n = n.mid(n.lastIndexOf(' ') + 1);
if (n.contains(':'))
n = n.mid(n.lastIndexOf(':') + 1);
name = n.toStdString() + "()";
}
name = nameOrFunc();
else
name = "\"" + name + "\"";
......@@ -71,10 +67,11 @@ std::string ActionLabel::nameOrFunc() const
auto name = mName;
if (name.empty())
{
QString n = QString::fromStdString(mFunction);
n = n.mid(0, n.indexOf('('));
n = n.mid(n.lastIndexOf(' ') + 1);
name = n.toStdString() + "()";
name = mFunction;
name = name.substr(0, name.find('('));
name = name.substr(name.rfind(' ') + 1);
// TODO: more special cases
name += "()";
}
return name;
......
......@@ -5,9 +5,6 @@
#include "common/NetMessage.hh"
#include <QFileInfo>
#include <QDir>
using namespace aion;
ActionPackage::ActionPackage(std::vector<ActionEntry> const& entries, std::vector<ActionLabel*> const& labels)
......@@ -24,7 +21,7 @@ ActionPackage::~ActionPackage()
void ActionPackage::saveToFile(const std::string& filename) const
{
QFileInfo(QString::fromStdString(filename)).dir().mkpath(".");
// QFileInfo(QString::fromStdString(filename)).dir().mkpath(".");
NetMessage m;
......
......@@ -2,9 +2,7 @@
#include "snappy/snappy.hh"
#include <QIODevice>
#include <QFile>
#include <QByteArray>
#include <fstream>
#include "NetMessageReader.hh"
......@@ -295,10 +293,8 @@ UniqueNetMessage NetMessage::cloneUnique() const
return UniqueNetMessage(clone());
}
void NetMessage::send(QIODevice *stream)
void NetMessage::send(std::vector<char> &output)
{
assert(stream->isWritable());
compress();
unsigned int size = (unsigned)mData.size();
......@@ -306,7 +302,8 @@ void NetMessage::send(QIODevice *stream)
// assemble header
// Write type and option byte
stream->putChar(mOptions);
output.clear();
output.push_back(mOptions);
// decompose size
......@@ -337,7 +334,7 @@ void NetMessage::send(QIODevice *stream)
firstByte += 1 << 7;
needNextByte = true;
}
stream->putChar(firstByte);
output.push_back(firstByte);
if (needNextByte)
{
......@@ -351,7 +348,7 @@ void NetMessage::send(QIODevice *stream)
secondByte += 1 << 7;
needNextByte = true;
}
stream->putChar(secondByte);
output.push_back(secondByte);
if (needNextByte)
{
......@@ -365,7 +362,7 @@ void NetMessage::send(QIODevice *stream)
thirdByte += 1 << 7;
needNextByte = true;
}
stream->putChar(thirdByte);
output.push_back(thirdByte);
if (needNextByte)
{
......@@ -379,7 +376,7 @@ void NetMessage::send(QIODevice *stream)
forthByte += 1 << 7;
needNextByte = true;
}
stream->putChar(forthByte);
output.push_back(forthByte);
assert(!needNextByte);
}
......@@ -388,33 +385,52 @@ void NetMessage::send(QIODevice *stream)
// write actual data
if (size > 0)
stream->write(&mData[0], size);
{
auto hSize = output.size();
output.resize(output.size() + size);
std::copy(begin(mData), end(mData), begin(output) + hSize);
}
}
void NetMessage::writeToFile(const std::string &filename)
{
QFile file(QString::fromStdString(filename));
if (!file.open(QIODevice::WriteOnly))
std::ofstream file(filename);
if (!file.good())
{
std::cerr << "Unable to open " << filename << " for writing" << std::endl;
return;
}
send(&file);
std::vector<char> data;
send(data);
file.write(data.data(), data.size());
}
static std::vector<char> ReadAllBytes(std::string const &filename)
{
std::ifstream ifs(filename, std::ios::binary | std::ios::ate);
std::ifstream::pos_type pos = ifs.tellg();
std::vector<char> result(pos);
ifs.seekg(0, std::ios::beg);
ifs.read(result.data(), pos);
return result;
}
SharedNetMessage NetMessage::readFromFile(const std::string &filename)
{
QFile file(QString::fromStdString(filename));
if (!file.open(QIODevice::ReadOnly))
if (!std::ifstream(filename).good())
{
std::cerr << "Unable to open " << filename << " for reading" << std::endl;
return nullptr;
}
QByteArray ba = file.readAll();
auto bytes = ReadAllBytes(filename);
NetMessageReader r;
r.pushBytes(ba.constData(), ba.size());
r.pushBytes(bytes.data(), bytes.size());
NetMessage *m = nullptr;
if (!r.receiveMessage(m))
......
......@@ -15,9 +15,6 @@
#include "NetMessageFlags.hh"
AION_SHARED(class, QIODevice);
namespace aion
{
#ifdef NETMESSAGE_VALUE_TYPE
......@@ -285,7 +282,7 @@ public:
// TODO: copy ctor, assignment op, create from data
/// Writes a header and the content of this message to a stream
void send(QIODevice *stream);
void send(std::vector<char> &output);
void writeToFile(std::string const& filename);
static SharedNetMessage readFromFile(std::string const& filename);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment