mirror of
https://github.com/grumpycoders/pcsx-redux.git
synced 2026-10-12 02:15:13 +00:00
Upgrading json.hpp and adding some File helpers.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2022 PCSX-Redux authors *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "support/container-file.h"
|
||||
|
||||
PCSX::FileIterator& PCSX::FileIterator::operator++() {
|
||||
target->advance();
|
||||
return *this;
|
||||
}
|
||||
PCSX::FileIterator::reference PCSX::FileIterator::operator*() const { return target->getCurrent(); }
|
||||
@@ -0,0 +1,58 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2022 PCSX-Redux authors *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "support/file.h"
|
||||
|
||||
namespace PCSX {
|
||||
|
||||
class FileAsContainer;
|
||||
|
||||
struct FileIterator {
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using value_type = char;
|
||||
using pointer = const char*;
|
||||
using reference = const char&;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
FileIterator& operator++();
|
||||
reference operator*() const;
|
||||
bool operator!=(const FileIterator& rhs) const { return rhs.target != target; }
|
||||
FileAsContainer* target = nullptr;
|
||||
};
|
||||
|
||||
class FileAsContainer {
|
||||
public:
|
||||
FileAsContainer(IO<File> file) : m_file(file) {}
|
||||
void advance() { m_ptr++; }
|
||||
const char& getCurrent() {
|
||||
m_current = m_file->readAt<char>(m_ptr);
|
||||
return m_current;
|
||||
}
|
||||
FileIterator begin() { return FileIterator{this}; }
|
||||
FileIterator end() { return {}; }
|
||||
|
||||
private:
|
||||
IO<File> m_file;
|
||||
size_t m_ptr = 0;
|
||||
char m_current;
|
||||
};
|
||||
|
||||
} // namespace PCSX
|
||||
@@ -0,0 +1,64 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2022 PCSX-Redux authors *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <streambuf>
|
||||
|
||||
#include "support/file.h"
|
||||
|
||||
namespace PCSX {
|
||||
|
||||
template <class CharType, class traits = std::char_traits<CharType> >
|
||||
class BasicFileStreamBuf : public std::basic_streambuf<CharType, traits> {
|
||||
public:
|
||||
BasicFileStreamBuf(IO<File> file) : m_file(file) {}
|
||||
|
||||
private:
|
||||
virtual typename traits::int_type overflow(typename traits::int_type c) override {
|
||||
if (traits::eq_int_type(c, traits::eof())) return traits::not_eof(c);
|
||||
|
||||
CharType ch = c;
|
||||
if (m_file->write(&ch, sizeof(ch)) != sizeof(ch)) return traits::eof();
|
||||
return traits::not_eof(c);
|
||||
}
|
||||
virtual std::streamsize xsputn(const CharType* s, std::streamsize count) override {
|
||||
return m_file->write(s, count);
|
||||
}
|
||||
|
||||
public:
|
||||
IO<File> m_file;
|
||||
};
|
||||
|
||||
template <class CharType, class traits = std::char_traits<CharType> >
|
||||
class BasicFileOStream : public std::basic_ostream<CharType, traits> {
|
||||
public:
|
||||
BasicFileOStream(IO<File> file)
|
||||
: std::basic_ios<CharType, traits>(&m_sbuf), std::basic_ostream<CharType, traits>(&m_sbuf), m_sbuf(file) {}
|
||||
|
||||
private:
|
||||
BasicFileStreamBuf<CharType, traits> m_sbuf;
|
||||
};
|
||||
|
||||
typedef BasicFileOStream<char> FileOStream;
|
||||
|
||||
} // namespace PCSX
|
||||
Vendored
+6725
-9503
File diff suppressed because it is too large
Load Diff
@@ -284,11 +284,13 @@
|
||||
<ClInclude Include="..\..\src\mips\common\util\sjis-table.h" />
|
||||
<ClInclude Include="..\..\src\support\binstruct.h" />
|
||||
<ClInclude Include="..\..\src\support\circular.h" />
|
||||
<ClInclude Include="..\..\src\support\container-file.h" />
|
||||
<ClInclude Include="..\..\src\support\djbhash.h" />
|
||||
<ClInclude Include="..\..\src\support\eventbus.h" />
|
||||
<ClInclude Include="..\..\src\support\file.h" />
|
||||
<ClInclude Include="..\..\src\support\hashtable.h" />
|
||||
<ClInclude Include="..\..\src\support\list.h" />
|
||||
<ClInclude Include="..\..\src\support\stream-file.h" />
|
||||
<ClInclude Include="..\..\src\support\strings-helpers.h" />
|
||||
<ClInclude Include="..\..\src\support\protobuf.h" />
|
||||
<ClInclude Include="..\..\src\support\settings.h" />
|
||||
@@ -305,6 +307,7 @@
|
||||
<ClInclude Include="..\..\third_party\typestring.hh" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\support\container-file.cc" />
|
||||
<ClCompile Include="..\..\src\support\file.cc" />
|
||||
<ClCompile Include="..\..\src\support\sjis_conv.cc" />
|
||||
<ClCompile Include="..\..\src\support\uvfile.cc" />
|
||||
|
||||
@@ -81,6 +81,12 @@
|
||||
<ClInclude Include="..\..\src\support\zip.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\support\stream-file.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\support\container-file.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\support\file.cc">
|
||||
@@ -98,5 +104,8 @@
|
||||
<ClCompile Include="..\..\src\support\zip.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\support\container-file.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user