1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: fslow_IArchive.h 4 5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 24584 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_FSLOW_FSLOW_IARCHIVE_H_ 17 #define NN_FSLOW_FSLOW_IARCHIVE_H_ 18 19 #include <nn/Result.h> 20 #include <nn/fs/fs_Result.h> 21 #include <nn/util/util_Result.h> 22 #include <nn/fs/fs_Parameters.h> 23 #include <nn/util/util_NonCopyable.h> 24 #include "fslow_Common.h" 25 26 #include <cstring> 27 #include <cstdlib> 28 29 namespace nn { namespace fslow { 30 31 // アーカイブの基底クラス 32 template <class TArchiveTypeInfo> 33 class IArchive : private nn::util::NonCopyable<IArchive<TArchiveTypeInfo> > 34 { 35 public: 36 typedef TArchiveTypeInfo ArchiveTypeInfo; 37 typedef typename ArchiveTypeInfo::File File; 38 typedef typename ArchiveTypeInfo::Directory Directory; 39 typedef typename ArchiveTypeInfo::Path Path; 40 41 virtual Result OpenFile(File* pOut, nn::fs::Transaction transaction, Path path, bit32 mode, nn::fs::Attributes attributes) = 0; OpenFile(File * pOut,nn::fs::Transaction transaction,Path path,nn::fs::PathMark pathMark,bit32 mode,nn::fs::Attributes attributes)42 virtual Result OpenFile(File* pOut, nn::fs::Transaction transaction, Path path, nn::fs::PathMark pathMark, bit32 mode, nn::fs::Attributes attributes) 43 { 44 NN_UNUSED_VAR( pOut); 45 NN_UNUSED_VAR( transaction); 46 NN_UNUSED_VAR( path); 47 NN_UNUSED_VAR( pathMark); 48 NN_UNUSED_VAR( mode); 49 NN_UNUSED_VAR( attributes); 50 return nn::fs::ResultUnsupportedOperation(); 51 } 52 53 virtual Result OpenDirectory(Directory* pOut, Path path) = 0; 54 55 virtual Result DeleteFile(nn::fs::Transaction transaction, Path path) = 0; 56 virtual Result DeleteDirectory(nn::fs::Transaction transaction, Path path) = 0; DeleteDirectoryRecursively(nn::fs::Transaction,Path)57 virtual Result DeleteDirectoryRecursively(nn::fs::Transaction, Path) { return nn::fs::ResultUnsupportedOperation(); } 58 virtual Result CreateDirectory(nn::fs::Transaction transaction, Path path, nn::fs::Attributes attributes) = 0; 59 60 virtual Result RenameFile(nn::fs::Transaction transaction, Path oldPath, Path newPath) = 0; 61 virtual Result RenameDirectory(nn::fs::Transaction transaction, Path oldPath, Path newPath) = 0; 62 GetPathMark(nn::fs::PathMark * pathMark,Path path)63 virtual Result GetPathMark( nn::fs::PathMark* pathMark, Path path) 64 { 65 NN_UNUSED_VAR( pathMark); 66 NN_UNUSED_VAR( path); 67 return nn::fs::ResultUnsupportedOperation(); 68 } 69 70 virtual void FreeFileObject(File) = 0; 71 virtual void FreeDirectoryObject(Directory) = 0; 72 73 protected: ~IArchive()74 virtual ~IArchive() {} 75 }; 76 77 template <class TBase> 78 class ReadOnlyArchiveBase : public TBase 79 { 80 public: 81 typedef typename TBase::ArchiveTypeInfo ArchiveTypeInfo; 82 typedef typename ArchiveTypeInfo::Path Path; DeleteFile(nn::fs::Transaction,Path)83 virtual Result DeleteFile(nn::fs::Transaction, Path) { return nn::fs::ResultUnsupportedOperation(); } DeleteDirectory(nn::fs::Transaction,Path)84 virtual Result DeleteDirectory(nn::fs::Transaction, Path) { return nn::fs::ResultUnsupportedOperation(); } CreateDirectory(nn::fs::Transaction,Path,nn::fs::Attributes)85 virtual Result CreateDirectory(nn::fs::Transaction, Path, nn::fs::Attributes) { return nn::fs::ResultUnsupportedOperation(); } RenameFile(nn::fs::Transaction,Path,Path)86 virtual Result RenameFile(nn::fs::Transaction, Path, Path) { return nn::fs::ResultUnsupportedOperation(); } RenameDirectory(nn::fs::Transaction,Path,Path)87 virtual Result RenameDirectory(nn::fs::Transaction, Path, Path) { return nn::fs::ResultUnsupportedOperation(); } 88 }; 89 90 template <class TChar, size_t TMaxLength, TChar TSeparator> 91 class ArchiveName 92 { 93 public: 94 95 typedef TChar Char; 96 static const size_t MaxLength = TMaxLength; 97 static const TChar Separator = TSeparator; 98 99 private: 100 101 static const size_t ByteSize = sizeof(Char) * (MaxLength + 1); 102 103 union Data 104 { 105 Char c[MaxLength + 1]; 106 bit32 w[ByteSize / sizeof(bit32)]; 107 }; 108 109 Data m_Data; 110 Clear()111 void Clear() { std::memset(&m_Data, 0, sizeof(m_Data)); } 112 113 public: 114 ArchiveName()115 ArchiveName() { Clear(); } 116 ArchiveName(const Char * s)117 ArchiveName(const Char* s) 118 { 119 Clear(); 120 for (s32 i = 0; i <= MaxLength; ++i) 121 { 122 if (!s[i] || s[i] == Separator) 123 { 124 return; 125 } 126 m_Data.c[i] = s[i]; 127 } 128 Clear(); 129 } 130 GetPathString(const Char * s)131 static const Char* GetPathString(const Char* s) 132 { 133 for (s32 i = 0; i <= MaxLength; ++i) 134 { 135 if (!*s) 136 { 137 return 0; 138 } 139 if (*s++ == Separator) 140 { 141 return s; 142 } 143 } 144 return 0; 145 } 146 147 template <class Path> GetPathString(Path path)148 static Path GetPathString(Path path) 149 { 150 const typename Path::Char* s = path; 151 for (s32 i = 0; i <= MaxLength; ++i) 152 { 153 if (!*s) 154 { 155 return Path(); 156 } 157 if (*s++ == Separator) 158 { 159 { 160 typename Path::Updater u(path); 161 u->EraseHead(i + 1); 162 } 163 return path; 164 } 165 } 166 return Path(); 167 } 168 169 operator const Char*() const { return m_Data.c; } 170 IsValid()171 bool IsValid() const { return m_Data.c[0] != 0; } 172 173 bool operator==(const ArchiveName& rhs) const { return std::memcmp(&this->m_Data, &rhs.m_Data, sizeof(Data)) == 0; } 174 bool operator!=(const ArchiveName& rhs) const { return !(*this == rhs); } 175 176 bool operator>(const ArchiveName& rhs) const { return std::memcmp(&this->m_Data, &rhs.m_Data, sizeof(Data)) > 0; } 177 bool operator<=(const ArchiveName& rhs) const { return !(*this > rhs); } 178 bool operator<(const ArchiveName& rhs) const { return rhs > *this; } 179 bool operator>=(const ArchiveName& rhs) const { return rhs <= *this; } 180 181 }; 182 183 }} 184 185 #endif 186