initial class layout

This commit is contained in:
Jack Andersen 2015-06-26 09:30:03 -10:00
commit 791056d966
13 changed files with 293 additions and 0 deletions

24
NODLib.pro Normal file
View File

@ -0,0 +1,24 @@
TEMPLATE = lib
CONFIG += staticlib c++11
CONFIG -= app_bundle
CONFIG -= qt
QT =
INCLUDEPATH += include
HEADERS += \
include/NODLib.hpp \
include/IDiscIO.hpp \
include/IFileIO.hpp \
include/DiscBase.hpp \
include/DiscGCN.hpp \
include/DiscWii.hpp
SOURCES += \
lib/DiscIOFILE.cpp \
lib/DiscIOWBFS.cpp \
lib/FileIOFILE.cpp \
lib/FileIOMEM.cpp \
lib/DiscBase.cpp \
lib/DiscGCN.cpp \
lib/DiscWii.cpp

64
include/DiscBase.hpp Normal file
View File

@ -0,0 +1,64 @@
#ifndef __NOD_DISC_BASE__
#define __NOD_DISC_BASE__
#include <list>
#include <memory>
#include <string>
#include "IDiscIO.hpp"
#include "IFileIO.hpp"
namespace NOD
{
class DiscBase
{
IDiscIO& m_discIO;
protected:
struct Partition
{
enum Kind
{
PART_DATA,
PART_UPDATE
};
struct File
{
std::unique_ptr<IFileIO> m_hddFile;
std::string m_discPath;
size_t m_discOffset;
size_t m_discLength;
File(const std::string& discPath)
: m_discPath(discPath) {}
};
std::list<File> files;
Kind m_kind;
Partition(Kind kind)
: m_kind(kind) {}
};
std::list<Partition> partitions;
Partition& addPartition(Partition::Kind kind);
public:
DiscBase(IDiscIO& dio);
virtual bool sync()=0;
class IPartReadStream
{
public:
virtual size_t read(void* buf, size_t length)=0;
};
virtual std::unique_ptr<IPartReadStream> beginDataReadStream()=0;
virtual std::unique_ptr<IPartReadStream> beginUpdateReadStream()=0;
class IPartWriteStream
{
public:
virtual size_t write(void* buf, size_t length)=0;
};
virtual std::unique_ptr<IPartWriteStream> beginDataWriteStream()=0;
virtual std::unique_ptr<IPartWriteStream> beginUpdateWriteStream()=0;
};
}
#endif // __NOD_DISC_BASE__

18
include/DiscGCN.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef __NOD_DISC_GCN__
#define __NOD_DISC_GCN__
#include "DiscBase.hpp"
namespace NOD
{
class DiscGCN : public DiscBase
{
public:
DiscGCN(IDiscIO& discio);
};
}
#endif // __NOD_DISC_GCN__

17
include/DiscWii.hpp Normal file
View File

@ -0,0 +1,17 @@
#ifndef __NOD_DISC_WII__
#define __NOD_DISC_WII__
#include "DiscBase.hpp"
namespace NOD
{
class DiscWii : public DiscBase
{
public:
DiscWii(IDiscIO& discio);
};
}
#endif // __NOD_DISC_WII__

32
include/IDiscIO.hpp Normal file
View File

@ -0,0 +1,32 @@
#ifndef __NOD_IDISC_IO__
#define __NOD_IDISC_IO__
#include <memory>
#include <stdlib.h>
namespace NOD
{
class IDiscIO
{
public:
virtual ~IDiscIO() {}
class IReadStream
{
public:
virtual size_t read(void* buf, size_t length)=0;
};
virtual std::unique_ptr<IReadStream> beginReadStream(size_t offset);
class IWriteStream
{
public:
virtual size_t write(void* buf, size_t length)=0;
};
virtual std::unique_ptr<IWriteStream> beginWriteStream(size_t offset);
};
}
#endif // __NOD_IDISC_IO__

36
include/IFileIO.hpp Normal file
View File

@ -0,0 +1,36 @@
#ifndef __NOD_IFILE_IO__
#define __NOD_IFILE_IO__
#include <memory>
#include <stdlib.h>
#include "IDiscIO.hpp"
namespace NOD
{
class IFileIO
{
public:
virtual ~IFileIO() {}
virtual size_t size()=0;
class IWriteStream
{
public:
virtual ~IWriteStream() {}
virtual size_t copyFromDisc(IDiscIO::IReadStream& discio, size_t length)=0;
};
virtual std::unique_ptr<IWriteStream> beginWriteStream();
class IReadStream
{
public:
virtual ~IReadStream() {}
virtual size_t copyToDisc(IDiscIO::IWriteStream& discio, size_t length)=0;
};
virtual std::unique_ptr<IReadStream> beginReadStream();
};
}
#endif // __NOD_IFILE_IO__

17
include/NODLib.hpp Normal file
View File

@ -0,0 +1,17 @@
#ifndef __NOD_LIB__
#define __NOD_LIB__
#include <memory>
#include "DiscGCN.hpp"
#include "DiscWii.hpp"
#include "IDiscIO.hpp"
namespace NOD
{
std::unique_ptr<IDiscIO> NewDiscIOFILE(const char* path);
std::unique_ptr<IDiscIO> NewDiscIOWBFS(const char* path);
}
#endif // __NOD_LIB__

0
lib/DiscBase.cpp Normal file
View File

0
lib/DiscGCN.cpp Normal file
View File

68
lib/DiscIOFILE.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <stdio.h>
#include <stdexcept>
#include "IDiscIO.hpp"
namespace NOD
{
class DiscIOFILE : public IDiscIO
{
std::string filepath;
public:
DiscIOFILE(const std::string& fpin)
: filepath(fpin) {}
class FILEReadStream : public IReadStream
{
friend class DiscIOFILE;
FILE* fp;
FILEReadStream(FILE* fpin)
: fp(fpin) {}
~FILEReadStream() {fclose(fp);}
public:
size_t read(void* buf, size_t length)
{return fread(buf, 1, length, fp);}
};
std::unique_ptr<IReadStream> beginReadStream(size_t offset)
{
FILE* fp = fopen(filepath.c_str(), "rb");
if (!fp)
{
throw std::runtime_error("Unable to open '" + filepath + "' for reading");
return std::unique_ptr<IReadStream>();
}
fseek(fp, offset, SEEK_SET);
return std::unique_ptr<IReadStream>(new FILEReadStream(fp));
}
class FILEWriteStream : public IWriteStream
{
friend class DiscIOFILE;
FILE* fp;
FILEWriteStream(FILE* fpin)
: fp(fpin) {}
~FILEWriteStream() {fclose(fp);}
public:
size_t write(void* buf, size_t length)
{return fwrite(buf, 1, length, fp);}
};
std::unique_ptr<IWriteStream> beginWriteStream(size_t offset)
{
FILE* fp = fopen(filepath.c_str(), "wb");
if (!fp)
{
throw std::runtime_error("Unable to open '" + filepath + "' for writing");
return std::unique_ptr<IWriteStream>();
}
fseek(fp, offset, SEEK_SET);
return std::unique_ptr<IWriteStream>(new FILEWriteStream(fp));
}
};
std::unique_ptr<IDiscIO> NewDiscIOFILE(const char* path)
{
return std::unique_ptr<IDiscIO>(new DiscIOFILE(path));
}
}

0
lib/DiscIOWBFS.cpp Normal file
View File

7
lib/DiscWii.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "DiscWii.hpp"
namespace NOD
{
}

10
main.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}