SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
VariadicStream.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <sstream>
6 #include <iostream>
7 
8 namespace SDX
9 {
10  //メモ、よく使うiomanip
11  //参考:http://www.booran.com/menu/cplus/manipulator.html
12  //dec :10進数
13  //hex :16進数
14  //oct :8進数
15  //left :左寄せ
16  //right :右寄せ
17  //setfill:setwで充填する文字を指定、初期は半角space
18  //showpoint:浮動小数点数「.0」を必ず表示
19  //setw:フィールド幅を指定
20  //setprecision:小数点以下の桁数を指定
21  //showpos:正の値なら+を表示
22 
26  {
27  private:
28  template < typename ... TRest>
29  std::string Change(TRest... 残りの要素)
30  {
31  std::ostringstream os;
32 
33  Change(os, 残りの要素...);
34 
35  return os.str();
36  }
37 
38  template < class TFirst, typename ... TRest>
39  void Change(std::ostringstream& 文字列, TFirst 最初の要素, TRest... 残りの要素)
40  {
41  文字列 << 最初の要素;
42  Change(文字列, 残りの要素...);
43  }
44 
45  template < class TFirst>
46  void Change(std::ostringstream& 文字列, TFirst 最初の要素)
47  {
48  文字列 << 最初の要素;
49  }
50 
51  public:
53  std::vector<std::string> StringS;
54 
55  template < typename ... TStream>
58  VariadicStream(TStream... 文字列ストリーム)
59  {
60  std::string 分割する文字列 = Change(文字列ストリーム...);
61 
62  size_t 開始位置 = 0;
63  size_t 終了位置 = 0;
64 
65  //改行コードで区切る
66  while (終了位置 != std::string::npos)
67  {
68  終了位置 = 分割する文字列.find("\n", 開始位置);
69 
70  StringS.push_back(分割する文字列.substr(開始位置, 終了位置 - 開始位置));
71 
72  開始位置 = 終了位置 + 1;
73  }
74  }
75  };
76 }
VariadicStream(TStream...文字列ストリーム)
コンストラクタ.
Definition: VariadicStream.h:58
std::vector< std::string > StringS
一行ずつの文字列.
Definition: VariadicStream.h:53
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:25