1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: fslow_IArchive.h 4 5 Copyright (C)2009-2012 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: 46347 $ 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 25 #include <cstring> 26 #include <cstdlib> 27 28 namespace nn { namespace fslow { 29 30 template <class TChar, size_t TMaxLength, TChar TSeparator> 31 class ArchiveName 32 { 33 public: 34 35 typedef TChar Char; 36 static const size_t MaxLength = TMaxLength; 37 static const TChar Separator = TSeparator; 38 39 private: 40 41 static const size_t ByteSize = sizeof(Char) * (MaxLength + 1); 42 43 union Data 44 { 45 Char c[MaxLength + 1]; 46 bit32 w[ByteSize / sizeof(bit32)]; 47 }; 48 49 Data m_Data; 50 Clear()51 void Clear() { std::memset(&m_Data, 0, sizeof(m_Data)); } 52 53 public: 54 ArchiveName()55 ArchiveName() { Clear(); } 56 ArchiveName(const Char * s)57 ArchiveName(const Char* s) 58 { 59 Clear(); 60 for (s32 i = 0; i <= MaxLength; ++i) 61 { 62 if (!s[i] || s[i] == Separator) 63 { 64 return; 65 } 66 m_Data.c[i] = s[i]; 67 } 68 Clear(); 69 } 70 GetPathString(const Char * s)71 static const Char* GetPathString(const Char* s) 72 { 73 for (s32 i = 0; i <= MaxLength; ++i) 74 { 75 if (!*s) 76 { 77 return 0; 78 } 79 if (*s++ == Separator) 80 { 81 return s; 82 } 83 } 84 return 0; 85 } 86 87 template <class Path> GetPathString(Path path)88 static Path GetPathString(Path path) 89 { 90 const typename Path::Char* s = path; 91 for (s32 i = 0; i <= MaxLength; ++i) 92 { 93 if (!*s) 94 { 95 return Path(); 96 } 97 if (*s++ == Separator) 98 { 99 { 100 typename Path::Updater u(path); 101 u->EraseHead(i + 1); 102 } 103 return path; 104 } 105 } 106 return Path(); 107 } 108 109 operator const Char*() const { return m_Data.c; } 110 IsValid()111 bool IsValid() const { return m_Data.c[0] != 0; } 112 113 bool operator==(const ArchiveName& rhs) const { return std::memcmp(&this->m_Data, &rhs.m_Data, sizeof(Data)) == 0; } 114 bool operator!=(const ArchiveName& rhs) const { return !(*this == rhs); } 115 116 bool operator>(const ArchiveName& rhs) const { return std::memcmp(&this->m_Data, &rhs.m_Data, sizeof(Data)) > 0; } 117 bool operator<=(const ArchiveName& rhs) const { return !(*this > rhs); } 118 bool operator<(const ArchiveName& rhs) const { return rhs > *this; } 119 bool operator>=(const ArchiveName& rhs) const { return rhs <= *this; } 120 121 }; 122 123 }} 124 125 #endif 126