/*---------------------------------------------------------------------------* Project: Horizon File: fslow_IArchive.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 24584 $ *---------------------------------------------------------------------------*/ #ifndef NN_FSLOW_FSLOW_IARCHIVE_H_ #define NN_FSLOW_FSLOW_IARCHIVE_H_ #include #include #include #include #include #include "fslow_Common.h" #include #include namespace nn { namespace fslow { // アーカイブの基底クラス template class IArchive : private nn::util::NonCopyable > { public: typedef TArchiveTypeInfo ArchiveTypeInfo; typedef typename ArchiveTypeInfo::File File; typedef typename ArchiveTypeInfo::Directory Directory; typedef typename ArchiveTypeInfo::Path Path; virtual Result OpenFile(File* pOut, nn::fs::Transaction transaction, Path path, bit32 mode, nn::fs::Attributes attributes) = 0; virtual Result OpenFile(File* pOut, nn::fs::Transaction transaction, Path path, nn::fs::PathMark pathMark, bit32 mode, nn::fs::Attributes attributes) { NN_UNUSED_VAR( pOut); NN_UNUSED_VAR( transaction); NN_UNUSED_VAR( path); NN_UNUSED_VAR( pathMark); NN_UNUSED_VAR( mode); NN_UNUSED_VAR( attributes); return nn::fs::ResultUnsupportedOperation(); } virtual Result OpenDirectory(Directory* pOut, Path path) = 0; virtual Result DeleteFile(nn::fs::Transaction transaction, Path path) = 0; virtual Result DeleteDirectory(nn::fs::Transaction transaction, Path path) = 0; virtual Result DeleteDirectoryRecursively(nn::fs::Transaction, Path) { return nn::fs::ResultUnsupportedOperation(); } virtual Result CreateDirectory(nn::fs::Transaction transaction, Path path, nn::fs::Attributes attributes) = 0; virtual Result RenameFile(nn::fs::Transaction transaction, Path oldPath, Path newPath) = 0; virtual Result RenameDirectory(nn::fs::Transaction transaction, Path oldPath, Path newPath) = 0; virtual Result GetPathMark( nn::fs::PathMark* pathMark, Path path) { NN_UNUSED_VAR( pathMark); NN_UNUSED_VAR( path); return nn::fs::ResultUnsupportedOperation(); } virtual void FreeFileObject(File) = 0; virtual void FreeDirectoryObject(Directory) = 0; protected: virtual ~IArchive() {} }; template class ReadOnlyArchiveBase : public TBase { public: typedef typename TBase::ArchiveTypeInfo ArchiveTypeInfo; typedef typename ArchiveTypeInfo::Path Path; virtual Result DeleteFile(nn::fs::Transaction, Path) { return nn::fs::ResultUnsupportedOperation(); } virtual Result DeleteDirectory(nn::fs::Transaction, Path) { return nn::fs::ResultUnsupportedOperation(); } virtual Result CreateDirectory(nn::fs::Transaction, Path, nn::fs::Attributes) { return nn::fs::ResultUnsupportedOperation(); } virtual Result RenameFile(nn::fs::Transaction, Path, Path) { return nn::fs::ResultUnsupportedOperation(); } virtual Result RenameDirectory(nn::fs::Transaction, Path, Path) { return nn::fs::ResultUnsupportedOperation(); } }; template class ArchiveName { public: typedef TChar Char; static const size_t MaxLength = TMaxLength; static const TChar Separator = TSeparator; private: static const size_t ByteSize = sizeof(Char) * (MaxLength + 1); union Data { Char c[MaxLength + 1]; bit32 w[ByteSize / sizeof(bit32)]; }; Data m_Data; void Clear() { std::memset(&m_Data, 0, sizeof(m_Data)); } public: ArchiveName() { Clear(); } ArchiveName(const Char* s) { Clear(); for (s32 i = 0; i <= MaxLength; ++i) { if (!s[i] || s[i] == Separator) { return; } m_Data.c[i] = s[i]; } Clear(); } static const Char* GetPathString(const Char* s) { for (s32 i = 0; i <= MaxLength; ++i) { if (!*s) { return 0; } if (*s++ == Separator) { return s; } } return 0; } template static Path GetPathString(Path path) { const typename Path::Char* s = path; for (s32 i = 0; i <= MaxLength; ++i) { if (!*s) { return Path(); } if (*s++ == Separator) { { typename Path::Updater u(path); u->EraseHead(i + 1); } return path; } } return Path(); } operator const Char*() const { return m_Data.c; } bool IsValid() const { return m_Data.c[0] != 0; } bool operator==(const ArchiveName& rhs) const { return std::memcmp(&this->m_Data, &rhs.m_Data, sizeof(Data)) == 0; } bool operator!=(const ArchiveName& rhs) const { return !(*this == rhs); } bool operator>(const ArchiveName& rhs) const { return std::memcmp(&this->m_Data, &rhs.m_Data, sizeof(Data)) > 0; } bool operator<=(const ArchiveName& rhs) const { return !(*this > rhs); } bool operator<(const ArchiveName& rhs) const { return rhs > *this; } bool operator>=(const ArchiveName& rhs) const { return rhs <= *this; } }; }} #endif