summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-06 02:29:11 -0300
committerGravatar Yuri Kunde Schlesner2015-05-06 23:45:06 -0300
commitb89f644cfef7592a501f1c0b9aae0c4ae757d854 (patch)
treedeee6a64137895b6cd7a65a95e9ba5d411ecbd9a
parentFileSys: Clean-up includes, de-inline destructors (diff)
downloadyuzu-b89f644cfef7592a501f1c0b9aae0c4ae757d854.tar.gz
yuzu-b89f644cfef7592a501f1c0b9aae0c4ae757d854.tar.xz
yuzu-b89f644cfef7592a501f1c0b9aae0c4ae757d854.zip
FileSys: De-inline Path members
Diffstat (limited to '')
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/file_sys/archive_backend.cpp127
-rw-r--r--src/core/file_sys/archive_backend.h134
-rw-r--r--src/core/hle/service/cfg/cfg.cpp2
4 files changed, 139 insertions, 125 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 42733b95e..fa6b4215a 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -12,6 +12,7 @@ set(SRCS
12 arm/skyeye_common/vfp/vfpdouble.cpp 12 arm/skyeye_common/vfp/vfpdouble.cpp
13 arm/skyeye_common/vfp/vfpinstr.cpp 13 arm/skyeye_common/vfp/vfpinstr.cpp
14 arm/skyeye_common/vfp/vfpsingle.cpp 14 arm/skyeye_common/vfp/vfpsingle.cpp
15 file_sys/archive_backend.cpp
15 file_sys/archive_extsavedata.cpp 16 file_sys/archive_extsavedata.cpp
16 file_sys/archive_romfs.cpp 17 file_sys/archive_romfs.cpp
17 file_sys/archive_savedata.cpp 18 file_sys/archive_savedata.cpp
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp
new file mode 100644
index 000000000..0439868ab
--- /dev/null
+++ b/src/core/file_sys/archive_backend.cpp
@@ -0,0 +1,127 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <sstream>
6
7#include "common/logging/log.h"
8#include "common/string_util.h"
9
10#include "core/file_sys/archive_backend.h"
11#include "core/mem_map.h"
12
13
14namespace FileSys {
15
16Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) {
17 switch (type) {
18 case Binary:
19 {
20 u8* data = Memory::GetPointer(pointer);
21 binary = std::vector<u8>(data, data + size);
22 break;
23 }
24
25 case Char:
26 {
27 const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
28 string = std::string(data, size - 1); // Data is always null-terminated.
29 break;
30 }
31
32 case Wchar:
33 {
34 const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
35 u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
36 break;
37 }
38
39 default:
40 break;
41 }
42}
43
44const std::string Path::DebugStr() const {
45 switch (GetType()) {
46 case Invalid:
47 default:
48 return "[Invalid]";
49 case Empty:
50 return "[Empty]";
51 case Binary:
52 {
53 std::stringstream res;
54 res << "[Binary: ";
55 for (unsigned byte : binary)
56 res << std::hex << std::setw(2) << std::setfill('0') << byte;
57 res << ']';
58 return res.str();
59 }
60 case Char:
61 return "[Char: " + AsString() + ']';
62 case Wchar:
63 return "[Wchar: " + AsString() + ']';
64 }
65}
66
67const std::string Path::AsString() const {
68 switch (GetType()) {
69 case Char:
70 return string;
71 case Wchar:
72 return Common::UTF16ToUTF8(u16str);
73 case Empty:
74 return{};
75 case Invalid:
76 case Binary:
77 default:
78 // TODO(yuriks): Add assert
79 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
80 return{};
81 }
82}
83
84const std::u16string Path::AsU16Str() const {
85 switch (GetType()) {
86 case Char:
87 return Common::UTF8ToUTF16(string);
88 case Wchar:
89 return u16str;
90 case Empty:
91 return{};
92 case Invalid:
93 case Binary:
94 // TODO(yuriks): Add assert
95 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
96 return{};
97 }
98}
99
100const std::vector<u8> Path::AsBinary() const {
101 switch (GetType()) {
102 case Binary:
103 return binary;
104 case Char:
105 return std::vector<u8>(string.begin(), string.end());
106 case Wchar:
107 {
108 // use two u8 for each character of u16str
109 std::vector<u8> to_return(u16str.size() * 2);
110 for (size_t i = 0; i < u16str.size(); ++i) {
111 u16 tmp_char = u16str.at(i);
112 to_return[i*2] = (tmp_char & 0xFF00) >> 8;
113 to_return[i*2 + 1] = (tmp_char & 0x00FF);
114 }
115 return to_return;
116 }
117 case Empty:
118 return{};
119 case Invalid:
120 default:
121 // TODO(yuriks): Add assert
122 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
123 return{};
124 }
125}
126
127}
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index 1956d76cb..c6a1be79d 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -5,18 +5,14 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <sstream>
9#include <string> 8#include <string>
10#include <utility> 9#include <utility>
11#include <vector> 10#include <vector>
12 11
13#include "common/bit_field.h" 12#include "common/bit_field.h"
14#include "common/common_types.h" 13#include "common/common_types.h"
15#include "common/logging/log.h"
16#include "common/string_util.h"
17 14
18#include "core/hle/result.h" 15#include "core/hle/result.h"
19#include "core/mem_map.h"
20 16
21 17
22namespace FileSys { 18namespace FileSys {
@@ -42,134 +38,22 @@ union Mode {
42 38
43class Path { 39class Path {
44public: 40public:
41 Path() : type(Invalid) {}
42 Path(const char* path) : type(Char), string(path) {}
43 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {}
44 Path(LowPathType type, u32 size, u32 pointer);
45 45
46 Path() : type(Invalid) { 46 LowPathType GetType() const { return type; }
47 }
48
49 Path(const char* path) : type(Char), string(path) {
50 }
51
52 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {
53 }
54
55 Path(LowPathType type, u32 size, u32 pointer) : type(type) {
56 switch (type) {
57 case Binary:
58 {
59 u8* data = Memory::GetPointer(pointer);
60 binary = std::vector<u8>(data, data + size);
61 break;
62 }
63
64 case Char:
65 {
66 const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
67 string = std::string(data, size - 1); // Data is always null-terminated.
68 break;
69 }
70
71 case Wchar:
72 {
73 const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
74 u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
75 break;
76 }
77
78 default:
79 break;
80 }
81 }
82
83 LowPathType GetType() const {
84 return type;
85 }
86 47
87 /** 48 /**
88 * Gets the string representation of the path for debugging 49 * Gets the string representation of the path for debugging
89 * @return String representation of the path for debugging 50 * @return String representation of the path for debugging
90 */ 51 */
91 const std::string DebugStr() const { 52 const std::string DebugStr() const;
92 switch (GetType()) {
93 case Invalid:
94 default:
95 return "[Invalid]";
96 case Empty:
97 return "[Empty]";
98 case Binary:
99 {
100 std::stringstream res;
101 res << "[Binary: ";
102 for (unsigned byte : binary)
103 res << std::hex << std::setw(2) << std::setfill('0') << byte;
104 res << ']';
105 return res.str();
106 }
107 case Char:
108 return "[Char: " + AsString() + ']';
109 case Wchar:
110 return "[Wchar: " + AsString() + ']';
111 }
112 }
113 53
114 const std::string AsString() const { 54 const std::string AsString() const;
115 switch (GetType()) { 55 const std::u16string AsU16Str() const;
116 case Char: 56 const std::vector<u8> AsBinary() const;
117 return string;
118 case Wchar:
119 return Common::UTF16ToUTF8(u16str);
120 case Empty:
121 return {};
122 case Invalid:
123 case Binary:
124 default:
125 // TODO(yuriks): Add assert
126 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
127 return {};
128 }
129 }
130
131 const std::u16string AsU16Str() const {
132 switch (GetType()) {
133 case Char:
134 return Common::UTF8ToUTF16(string);
135 case Wchar:
136 return u16str;
137 case Empty:
138 return {};
139 case Invalid:
140 case Binary:
141 // TODO(yuriks): Add assert
142 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
143 return {};
144 }
145 }
146
147 const std::vector<u8> AsBinary() const {
148 switch (GetType()) {
149 case Binary:
150 return binary;
151 case Char:
152 return std::vector<u8>(string.begin(), string.end());
153 case Wchar:
154 {
155 // use two u8 for each character of u16str
156 std::vector<u8> to_return(u16str.size() * 2);
157 for (size_t i = 0; i < u16str.size(); ++i) {
158 u16 tmp_char = u16str.at(i);
159 to_return[i*2] = (tmp_char & 0xFF00) >> 8;
160 to_return[i*2 + 1] = (tmp_char & 0x00FF);
161 }
162 return to_return;
163 }
164 case Empty:
165 return {};
166 case Invalid:
167 default:
168 // TODO(yuriks): Add assert
169 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
170 return {};
171 }
172 }
173 57
174private: 58private:
175 LowPathType type; 59 LowPathType type;
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp
index 94bac5498..207f660e6 100644
--- a/src/core/hle/service/cfg/cfg.cpp
+++ b/src/core/hle/service/cfg/cfg.cpp
@@ -4,6 +4,8 @@
4 4
5#include <algorithm> 5#include <algorithm>
6 6
7#include "common/string_util.h"
8
7#include "core/file_sys/file_backend.h" 9#include "core/file_sys/file_backend.h"
8#include "core/hle/service/cfg/cfg.h" 10#include "core/hle/service/cfg/cfg.h"
9#include "core/hle/service/cfg/cfg_i.h" 11#include "core/hle/service/cfg/cfg_i.h"