5 #include <Multimedia/SDX.h> 
   32         SDL_RWops *handle = 
nullptr;
 
   43             File::Open(ファイル名, 読み書きモード, バイナリファイル, Androidの保存先);
 
   62                 fileName = SDL_AndroidGetExternalStoragePath();
 
   66                 fileName = SDL_AndroidGetInternalStoragePath();
 
   74             fileName = SDL_GetBasePath();
 
   85                 if (isBinary){ handle = SDL_RWFromFile(fileName.c_str(), 
"rb"); }
 
   86                 else{ handle = SDL_RWFromFile(fileName.c_str(), 
"r"); }
 
   93                 if (isBinary){ handle = SDL_RWFromFile(fileName.c_str(), 
"wb"); }
 
   94                 else{ handle = SDL_RWFromFile(fileName.c_str(), 
"w"); }
 
  100                 if (isBinary){ handle = SDL_RWFromFile(fileName.c_str(), 
"ab"); }
 
  101                 else{ handle = SDL_RWFromFile(fileName.c_str(), 
"a"); }
 
  110             if (handle == 
nullptr)
 
  146             return this->fileName.c_str();
 
  154             if (!canRead) 
return false;
 
  156             SDL_RWread(handle, &読み込み先変数, 
sizeof(読み込み先変数), 1);
 
  165         bool Read(std::vector<T> &読み込み元配列)
 
  167             if (!canRead) 
return false;
 
  170             SDL_RWread(handle, &要素数, 
sizeof(
int), 1);
 
  174             for (
int a = 0; a < 要素数; ++a)
 
  177                 SDL_RWread(handle, &値, 
sizeof(T), 1);
 
  178                 読み込み元配列.push_back(値);
 
  187         bool Read(std::string &読み込み先変数)
 
  189             if (!canRead) 
return false;
 
  192             SDL_RWread(handle, &文字数, 
sizeof(
int), 1);
 
  201             SDL_RWread(handle, (
char*)読み込み先変数.c_str(), 文字数, 1);
 
  210             if (!canRead) 
return false;
 
  212             for (
int a = 0; a < 要素数; ++a)
 
  214                 SDL_RWread(handle, &読み込み先配列[a], 
sizeof(T), 1);
 
  220         template <
class TSaveType, 
class TOutput>
 
  223         bool Read(TOutput *読み込み先配列, 
int 要素数, 
int 分母)
 
  225             if (!canRead) 
return false;
 
  229             for (
int a = 0; a < 要素数; ++a)
 
  231                 SDL_RWread(handle, &buff, 
sizeof(TSaveType), 1);
 
  232                 読み込み先配列[a] = TOutput(buff) / 分母;
 
  238         template< 
class TSaveType, 
class TOutput>
 
  242             if (!canRead) 
return false;
 
  245             SDL_RWread(handle, &buff, 
sizeof(TSaveType), 1);
 
  247             読み込み先変数 = TOutput(buff);
 
  258             if (!canWrite) 
return false;
 
  260             SDL_RWwrite(handle, &書込み元変数, 
sizeof(書込み元変数), 1);
 
  269         bool Write(
const std::string &書込み元変数 , 
bool is文字数 = 
true)
 
  271             if (!canWrite) 
return false;
 
  273             const int 文字数 = (int)書込み元変数.size();
 
  277                 SDL_RWwrite(handle, &文字数, 
sizeof(
int), 1);
 
  280             if (文字数 == 0){ 
return canWrite; }
 
  282             SDL_RWwrite(handle, 書込み元変数.c_str(), 文字数, 1);
 
  287         bool Write(std::string &書込み元変数, 
bool is文字数 = 
true)
 
  289             if (!canWrite) 
return false;
 
  291             const int 文字数 = (int)書込み元変数.size();
 
  295                 SDL_RWwrite(handle, &文字数, 
sizeof(
int), 1);
 
  298             if (文字数 == 0){ 
return canWrite; }
 
  300             SDL_RWwrite(handle, 書込み元変数.c_str(), 文字数, 1);
 
  311             if (!canWrite) 
return false;
 
  313             int 要素数 = 書込み元配列.size();
 
  314             SDL_RWwrite(handle, &要素数, 
sizeof(
int), 1);
 
  316             for (
int a = 0; a < 要素数; ++a)
 
  318                 SDL_RWwrite(handle, &書込み元配列[a], 
sizeof(T), 1);
 
  324         template <
class TSaveType, 
class TInput>
 
  327         bool Write(TInput *書き込み元配列, 
int 要素数)
 
  329             if (!canWrite) 
return false;
 
  331             for (
int a = 0; a < 要素数; ++a)
 
  333                 TSaveType buff = (TSaveType)書き込み元配列[a];
 
  335                 SDL_RWwrite(handle, &buff, 
sizeof(TSaveType), 1);
 
  351                 return Write(読み書き変数);
 
  363                 return Read(読み書き変数 , 要素数);
 
  366                 return Write(読み書き変数);
 
  374             if (!canWrite) 
return false;
 
  378             const int 文字数 = (int)文字列.
StringS[0].size();
 
  384             SDL_RWwrite(handle, 文字列.
StringS[0].c_str(), 文字数, 1);
 
  392             std::vector<std::string> lineS;
 
  397                 unsigned int fileSize = (
unsigned int)handle->size(handle);
 
  398                 all.resize(fileSize);
 
  399                 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
 
  402                 std::istringstream iss(all);
 
  405                 while (std::getline(iss, buf, 
'\n'))
 
  407                     numA = buf.find_first_of(
'\r');
 
  408                     numB = buf.find_first_of(
'\n');
 
  409                     if (numA < numB){ numA = numB; };
 
  411                     if (numA != std::string::npos)
 
  413                         buf = buf.substr(0, numA);
 
  416                     lineS.push_back(buf.substr());
 
  425             std::vector<std::string> lineS;
 
  430                 unsigned int fileSize = (
unsigned int)handle->size(handle);
 
  431                 all.resize(fileSize);
 
  432                 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
 
  437                 std::istringstream iss(all);
 
  439                 while (std::getline(iss, buf, 
'\n'))
 
  442                     if (buf.find(
"\r") != std::string::npos)
 
  444                         buf.replace(buf.find(
"\r"), 1, 
"");
 
  447                     std::istringstream iss2(buf);
 
  448                     while (std::getline(iss2, buf2, 
','))
 
  450                         lineS.push_back(buf2);
 
  461             std::vector<std::vector<std::string>> lineS;
 
  466                 unsigned int fileSize = (
unsigned int)handle->size(handle);
 
  467                 all.resize(fileSize);
 
  468                 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
 
  473                 std::istringstream iss(all);
 
  475                 while (std::getline(iss, buf, 
'\n'))
 
  478                     if (buf.find(
"\r") != std::string::npos)
 
  480                         buf.replace(buf.find(
"\r"), 1, 
"");
 
  483                     std::istringstream iss2(buf);                   
 
  484                     lineS.push_back(std::vector<std::string>());
 
  486                     while (std::getline(iss2, buf2, 
','))
 
  488                         lineS[lineNo].push_back(buf2);
 
  499             std::vector<int> lineS;
 
  504                 unsigned int fileSize = (
unsigned int)handle->size(handle);
 
  505                 all.resize(fileSize);
 
  506                 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
 
  511                 std::istringstream iss(all);
 
  513                 while (std::getline(iss, buf, 
'\n'))
 
  515                     std::istringstream iss2(buf);
 
  517                     while (std::getline(iss2, buf2, 
','))
 
  519                         lineS.push_back(atoi(buf2.c_str()));
 
  530             std::vector<std::vector<int>> lineS;
 
  535                 unsigned int fileSize = (
unsigned int)handle->size(handle);
 
  536                 all.resize(fileSize);
 
  537                 SDL_RWread(handle, (
char*)all.c_str(), fileSize, 1);
 
  542                 std::istringstream iss(all);
 
  544                 while (std::getline(iss, buf, 
'\n'))
 
  546                     std::istringstream iss2(buf);
 
  547                     lineS.push_back(std::vector<int>());
 
  549                     while (std::getline(iss2, buf2, 
','))
 
  551                         lineS[lineNo].push_back(atoi(buf2.c_str()));
 
  562             return (SDL_RWtell(handle) == RW_SEEK_END);
 
bool Write(T &書込み元変数)
データを書き込む. 
Definition: File.h:256
std::vector< std::string > GetCsvToString()
カンマ区切りのCSVファイルを配列に文字列として一括読込. 
Definition: File.h:423
File(const char *ファイル名, FileMode 読み書きモード, bool バイナリファイル=false, SaveMode Androidの保存先=SaveMode::Asset)
ファイル名とモードを指定して、ファイルを開く. 
Definition: File.h:41
bool CheckEOF()
ファイルの終端判定. 
Definition: File.h:560
bool Read(T &読み込み先変数)
データを読み込む. 
Definition: File.h:152
SaveMode
Androidでの保存先. 
Definition: File.h:19
void Close()
ファイルを閉じる. 
Definition: File.h:122
const char * GetFileName()
ファイル名を取得. 
Definition: File.h:144
bool ReadWrite(T *読み書き変数, int 要素数)
配列に読み書きする. 
Definition: File.h:359
入出力可能なテキストかバイナリファイルを表すクラス. 
Definition: File.h:29
std::vector< std::string > GetLineS()
ファイルを改行区切りで一括して読み込む. 
Definition: File.h:390
bool Read(TOutput &読み込み先変数)
型変換をしつつ読み込む. 
Definition: File.h:240
std::vector< std::string > StringS
一行ずつの文字列. 
Definition: VariadicStream.h:53
bool Read(T *読み込み先配列, int 要素数)
データを読み込む. 
Definition: File.h:208
bool Read(std::vector< T > &読み込み元配列)
可変長配列を読み込む. 
Definition: File.h:165
bool AddLine(VariadicStream 文字列)
改行付きの文字列を一行書き込む. 
Definition: File.h:372
FileMode GetFileMode()
ファイルモードを取得. 
Definition: File.h:135
bool Open(const char *ファイル名, FileMode 読み書きモード, bool バイナリファイル=false, SaveMode Androidの保存先=SaveMode::Asset)
ファイル名とモードを指定して、ファイルを開く. 
Definition: File.h:52
bool Write(std::vector< T > &書込み元配列)
可変長配列を読み込む. 
Definition: File.h:309
可変数引数な文字列を処理するクラス. 
Definition: VariadicStream.h:25
bool Write(const std::string &書込み元変数, bool is文字数=true)
文字列を書き込む. 
Definition: File.h:269
FileMode
ファイルの読込書込モード. 
Definition: File.h:10
bool Read(TOutput *読み込み先配列, int 要素数, int 分母)
型変換をしつつ配列に読み込む. 
Definition: File.h:223
std::vector< std::vector< std::string > > GetCsvToString2()
カンマ区切りのCSVファイルを二次元配列に文字列として一括読込. 
Definition: File.h:459
bool ReadWrite(T &読み書き変数)
変数を読み書きする. 
Definition: File.h:344
std::vector< std::vector< int > > GetCsvToInt2()
カンマ区切りのCSVファイルを二次元配列に整数として一括読込. 
Definition: File.h:528
std::vector< int > GetCsvToInt()
カンマ区切りのCSVファイルを配列に整数として一括読込. 
Definition: File.h:497
bool Write(TInput *書き込み元配列, int 要素数)
型変換をして書き込む. 
Definition: File.h:327
bool Read(std::string &読み込み先変数)
文字列を読み込む. 
Definition: File.h:187