5 #include <Multimedia/System.h>
31 SDL_RWops *handle =
nullptr;
40 File(
const char* ファイル名 ,
FileMode 読み書きモード ,
bool バイナリファイル =
false ,
SaveMode Androidの保存先 = SaveMode::Asset)
42 File::Open( ファイル名 , 読み書きモード , バイナリファイル , Androidの保存先);
51 bool Open(
const char* ファイル名 ,
FileMode 読み書きモード ,
bool バイナリファイル =
false ,
SaveMode Androidの保存先 = SaveMode::Asset )
60 case SaveMode::External:
61 fileName = SDL_AndroidGetExternalStoragePath();
64 case SaveMode::Internal:
65 fileName = SDL_AndroidGetInternalStoragePath();
78 if (isBinary) handle = SDL_RWFromFile( fileName.c_str() ,
"rb" );
79 else handle = SDL_RWFromFile(fileName.c_str(),
"r");
86 if (isBinary) handle = SDL_RWFromFile(fileName.c_str(),
"wb");
87 else handle = SDL_RWFromFile(fileName.c_str(),
"w");
93 if (isBinary) handle = SDL_RWFromFile(fileName.c_str(),
"ab");
94 else handle = SDL_RWFromFile(fileName.c_str(),
"a");
103 if ( handle ==
nullptr )
139 return this->fileName.c_str();
152 SDL_RWread( handle, &読み込み先変数,
sizeof(読み込み先変数), 1);
156 bool Read(std::string &読み込み先変数)
161 SDL_RWread(handle, &文字数,
sizeof(
int), 1);
164 SDL_RWread(handle, (
char*)読み込み先変数.c_str(), 文字数 , 1);
177 SDL_RWwrite( handle , &書込み元変数 ,
sizeof(書込み元変数) , 1);
181 bool Write(std::string &書込み元変数)
185 const int 文字数 = (int)書込み元変数.size();
187 SDL_RWwrite(handle, &文字数,
sizeof(
int), 1);
188 SDL_RWwrite(handle, 書込み元変数.c_str(), 文字数, 1);
200 }
else if( canWrite ){
201 return Write(読み書き変数);
209 std::vector<std::string> lineS;
214 unsigned int fileSize = (
unsigned int)handle->size(handle);
215 all.resize(fileSize);
216 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
219 std::istringstream iss(all);
221 while (std::getline(iss, buf,
'\n'))
223 lineS.push_back(buf);
230 std::vector<std::vector<std::string>>
GetCsvS()
232 std::vector<std::vector<std::string>> lineS;
237 unsigned int fileSize = (
unsigned int)handle->size(handle);
238 all.resize(fileSize);
239 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
244 std::istringstream iss(all);
246 while (std::getline(iss, buf,
'\n'))
248 std::istringstream iss2(buf);
249 lineS.push_back(std::vector<std::string>());
251 while (std::getline(iss2, buf2,
','))
253 lineS[lineNo].push_back(buf2);
264 return (SDL_RWtell(handle) == RW_SEEK_END);
bool Write(T &書込み元変数)
データを書き込む.
Definition: File.h:173
File(const char *ファイル名, FileMode 読み書きモード, bool バイナリファイル=false, SaveMode Androidの保存先=SaveMode::Asset)
ファイル名とモードを指定して、ファイルを開く.
Definition: File.h:40
bool CheckEOF()
ファイルの終端判定.
Definition: File.h:262
bool Read(T &読み込み先変数)
データを読み込む.
Definition: File.h:146
SaveMode
Androidでの保存先.
Definition: File.h:19
void Close()
ファイルを閉じる.
Definition: File.h:115
const char * GetFileName()
ファイル名を取得.
Definition: File.h:137
入出力可能なテキストかバイナリファイルを表すクラス.
Definition: File.h:28
std::vector< std::string > GetLineS()
ファイルを改行区切りで一括して読み込む.
Definition: File.h:207
std::vector< std::vector< std::string > > GetCsvS()
カンマ区切りのCSVファイルを一括読込.
Definition: File.h:230
FileMode GetFileMode()
ファイルモードを取得.
Definition: File.h:128
bool Open(const char *ファイル名, FileMode 読み書きモード, bool バイナリファイル=false, SaveMode Androidの保存先=SaveMode::Asset)
ファイルを開く.
Definition: File.h:51
FileMode
ファイルの読込書込モード.
Definition: File.h:10
bool ReadWrite(T &読み書き変数)
FileModeがReadの場合Read、WriteかAddの場合Writeを行う.
Definition: File.h:195