SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Public Member Functions | List of all members
SDX::File Class Reference

入出力可能なテキストかバイナリファイルを表すクラス. More...

#include <File.h>

Public Member Functions

 File (const char *ファイル名, FileMode 読み書きモード, bool バイナリファイル=false, SaveMode Androidの保存先=SaveMode::Asset)
 ファイル名とモードを指定して、ファイルを開く. More...
 
bool Open (const char *ファイル名, FileMode 読み書きモード, bool バイナリファイル=false, SaveMode Androidの保存先=SaveMode::Asset)
 ファイル名とモードを指定して、ファイルを開く. More...
 
void Close ()
 ファイルを閉じる. More...
 
FileMode GetFileMode ()
 ファイルモードを取得. More...
 
const char * GetFileName ()
 ファイル名を取得. More...
 
template<class T >
bool Read (T &読み込み先変数)
 データを読み込む. More...
 
template<class T >
bool Read (std::vector< T > &読み込み元配列)
 可変長配列を読み込む. More...
 
bool Read (std::string &読み込み先変数)
 文字列を読み込む. More...
 
template<class T >
bool Read (T *読み込み先配列, int 要素数)
 データを読み込む. More...
 
template<class TSaveType , class TOutput >
bool Read (TOutput *読み込み先配列, int 要素数, int 分母)
 型変換をしつつ配列に読み込む. More...
 
template<class TSaveType , class TOutput >
bool Read (TOutput &読み込み先変数)
 型変換をしつつ読み込む. More...
 
template<class T >
bool Write (T &書込み元変数)
 データを書き込む. More...
 
bool Write (const std::string &書込み元変数, bool is文字数=true)
 文字列を書き込む. More...
 
bool Write (std::string &書込み元変数, bool is文字数=true)
 
template<class T >
bool Write (std::vector< T > &書込み元配列)
 可変長配列を読み込む. More...
 
template<class TSaveType , class TInput >
bool Write (TInput *書き込み元配列, int 要素数)
 型変換をして書き込む. More...
 
template<class T >
bool ReadWrite (T &読み書き変数)
 変数を読み書きする. More...
 
template<class T >
bool ReadWrite (T *読み書き変数, int 要素数)
 配列に読み書きする. More...
 
bool AddLine (VariadicStream 文字列)
 改行付きの文字列を一行書き込む. More...
 
std::vector< std::string > GetLineS ()
 ファイルを改行区切りで一括して読み込む. More...
 
std::vector< std::string > GetCsvToString ()
 カンマ区切りのCSVファイルを配列に文字列として一括読込. More...
 
std::vector< std::vector
< std::string > > 
GetCsvToString2 ()
 カンマ区切りのCSVファイルを二次元配列に文字列として一括読込. More...
 
std::vector< int > GetCsvToInt ()
 カンマ区切りのCSVファイルを配列に整数として一括読込. More...
 
std::vector< std::vector< int > > GetCsvToInt2 ()
 カンマ区切りのCSVファイルを二次元配列に整数として一括読込. More...
 
bool CheckEOF ()
 ファイルの終端判定. More...
 

Detailed Description

入出力可能なテキストかバイナリファイルを表すクラス.

Todo:
配列の保存と読み込みの仕様が分かりにくい?
//Copyright © 2014 SDXFramework
//[License]GNU Affero General Public License, version 3
//[Contact]http://sourceforge.jp/projects/dxframework/
//ファイルに書き込みと読み込みを行う
bool SampleFile()
{
using namespace SDX;
File fileA("test.txt", FileMode::Write, true);
int a = 100;
double b = 1.23;
char c = 123;
std::string str = "こんにちは";
fileA.Write(a);
fileA.Write(b);
fileA.Write(c);
fileA.Write(str);
fileA.Close();
File fileB("test.txt", FileMode::Read, true);
int a2;
double b2;
char c2;
std::string str2;
fileB.Read(a2);
fileB.Read(b2);
fileB.Read(c2);
fileB.Read(str2);
fileB.Close();
File fileC("csv.txt", FileMode::Write);
fileC.Write("1,2,3,4,5");
fileC.Close();
File fileD("csv.txt", FileMode::Read);
std::vector<int> intS = fileD.GetCsvToInt();
fileD.Close();
File fileE("csv2.txt", FileMode::Write);
fileE.Write("1,こんにちは,3,さようなら,5");
fileE.Close();
File fileF("csv2.txt", FileMode::Read);
std::vector<std::string> strS = fileF.GetCsvToString();
fileF.Close();
System::Initialise("sample", 640, 480);
while (System::Update())
{
Drawing::String({ 10, 10 }, Color::White, { "書き込みA:", a, " ", b, " ", c, " ", str });
Drawing::String({ 10, 30 }, Color::White, { "読み込みB:", a2, " ", b2, " ", c2, " ", str2 });
Drawing::String({ 10, 50 }, Color::White, { "読み込みD:", intS[0], intS[1], intS[2], intS[3], intS[4] });
Drawing::String({ 10, 70 }, Color::White, { "読み込みF:", strS[0], strS[1], strS[2], strS[3], strS[4], });
if (Input::key.Return.on){ break;}//Enterで終了
}
return true;
}

Constructor & Destructor Documentation

SDX::File::File ( const char *  ファイル名,
FileMode  読み書きモード,
bool  バイナリファイル = false,
SaveMode  Androidの保存先 = SaveMode::Asset 
)
inline

ファイル名とモードを指定して、ファイルを開く.

Member Function Documentation

bool SDX::File::Open ( const char *  ファイル名,
FileMode  読み書きモード,
bool  バイナリファイル = false,
SaveMode  Androidの保存先 = SaveMode::Asset 
)
inline

ファイル名とモードを指定して、ファイルを開く.

void SDX::File::Close ( )
inline

ファイルを閉じる.

FileMode SDX::File::GetFileMode ( )
inline

ファイルモードを取得.

const char* SDX::File::GetFileName ( )
inline

ファイル名を取得.

template<class T >
bool SDX::File::Read ( T &  読み込み先変数)
inline

データを読み込む.

FileMode::Readの場合成功

template<class T >
bool SDX::File::Read ( std::vector< T > &  読み込み元配列)
inline

可変長配列を読み込む.

FileMode::Readの場合成功 要素数を最初に読み込む

bool SDX::File::Read ( std::string &  読み込み先変数)
inline

文字列を読み込む.

1byte目が文字数、残り部分が文字データになっていれば読み込める FileMode::Readの場合成功

template<class T >
bool SDX::File::Read ( T *  読み込み先配列,
int  要素数 
)
inline

データを読み込む.

template<class TSaveType , class TOutput >
bool SDX::File::Read ( TOutput *  読み込み先配列,
int  要素数,
int  分母 
)
inline

型変換をしつつ配列に読み込む.

ファイルにはint型で保存してあって、double型の値に代入したい時等に使う.

template<class TSaveType , class TOutput >
bool SDX::File::Read ( TOutput &  読み込み先変数)
inline

型変換をしつつ読み込む.

template<class T >
bool SDX::File::Write ( T &  書込み元変数)
inline

データを書き込む.

FileModeがWriteかAddの場合成功。
書込元変数をファイルに書き込む。

bool SDX::File::Write ( const std::string &  書込み元変数,
bool  is文字数 = true 
)
inline

文字列を書き込む.

FileModeがWriteかAddの場合成功。
書込元変数をファイルに書き込む。 文字列の長さを文字列自身の前に書き込むかを選択出来る

template<class T >
bool SDX::File::Write ( std::vector< T > &  書込み元配列)
inline

可変長配列を読み込む.

FileMode::Wirteの場合成功 要素数を最初に書き込む

template<class TSaveType , class TInput >
bool SDX::File::Write ( TInput *  書き込み元配列,
int  要素数 
)
inline

型変換をして書き込む.

double型をfloatに変換して保存する時用

template<class T >
bool SDX::File::ReadWrite ( T &  読み書き変数)
inline

変数を読み書きする.

FileModeがReadの場合Read、WriteかAddの場合Writeを行う

template<class T >
bool SDX::File::ReadWrite ( T *  読み書き変数,
int  要素数 
)
inline

配列に読み書きする.

FileModeがReadの場合Read、WriteかAddの場合Writeを行う

bool SDX::File::AddLine ( VariadicStream  文字列)
inline

改行付きの文字列を一行書き込む.

std::vector<std::string> SDX::File::GetLineS ( )
inline

ファイルを改行区切りで一括して読み込む.

std::vector<std::string> SDX::File::GetCsvToString ( )
inline

カンマ区切りのCSVファイルを配列に文字列として一括読込.

std::vector<std::vector<std::string> > SDX::File::GetCsvToString2 ( )
inline

カンマ区切りのCSVファイルを二次元配列に文字列として一括読込.

std::vector<int> SDX::File::GetCsvToInt ( )
inline

カンマ区切りのCSVファイルを配列に整数として一括読込.

std::vector<std::vector<int> > SDX::File::GetCsvToInt2 ( )
inline

カンマ区切りのCSVファイルを二次元配列に整数として一括読込.

bool SDX::File::CheckEOF ( )
inline

ファイルの終端判定.