ATCFS
 全て クラス 名前空間 ファイル 関数 変数 型定義 マクロ定義 ページ
AtcfsCfg.h
[詳解]
1 //
2 // Generated on 2018/07/09 by inimoni
3 //
4 
5 /*
6 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 Documentation
8  Struct = Section name, Field = Key name.
9  The function used is only a declaration, load(), and save().
10  The constructor automatically reads initialization file [initFileName].
11  Please rewrite [initFileName] in the source freely.
12  It becomes Windows folder when there is not path. The relative path can be used.
13 
14 Example
15 #include "SampleIni.h"
16 void CTestDlg::OnButton1()
17 {
18  //initFileName = "./sample.ini";
19  SampleIni data1; // Open ./sample.ini
20  int v = data1.Sample.value; // [Sample]-value Get
21  data1.Sample.value = v+1; // [Sample]-value Modify
22  data1.save(); // Save ./Sample.ini (Opened file)
23 
24  SampleIni data2("sample.ini"); // Open C:/WINDOWS/Sample.ini
25  data2.load("./sample.ini"); // Open Specified file.
26  data2.save(); // Save Opened file (Making at not being)
27 }
28 
29 Supplementation
30  Reading and writing becomes the unit of the file.
31  [initFileName] is the same as the argument of GetPrivateProfileString() of SDK.
32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 */
34 
35 #ifndef ATCFSCFG_H
36 #define ATCFSCFG_H
37 
38 #include <string>
39 using namespace std;
40 
41 #include <windows.h>
42 #include <tchar.h>
43 #include <stdio.h>
44 
45 #ifdef _UNICODE
46  typedef std::wstring string_t;
47 #else
48  typedef std::string string_t;
49 #endif
50 
51 namespace inimoni{
52  template<class T>
53  static bool inirw(int is_read, string_t& fname, string_t sec, string_t key, T& val_t);
54 };
55 
59 class AtcfsCfg
60 {
61 public:
62 
63  AtcfsCfg(string_t fname=_T(""))
64  {
65  initFileName = _T("./atcfs.cfg"); //Default file.
66  init();
67  load(fname);
68  }
69 
76  bool load(string_t fname=_T(""))
77  {
78  if(fname.empty()){
79  fname = initFileName;
80  }
81  loadFileName = fname;
82  WIN32_FIND_DATA fd;
83  HANDLE h = ::FindFirstFile(fname.c_str(), &fd);
84  if (h != INVALID_HANDLE_VALUE) {
85  iniRW(fname,1);
86  }
87  return (h != INVALID_HANDLE_VALUE);
88  }
89 
96  bool save(string_t fname=_T(""))
97  {
98  if(fname.empty()){
99  fname = loadFileName;
100  }
101  iniRW(fname,0);
102  return true;
103  }
104 
105 public:
106 
107  // Emulate
108  struct _Emulate
109  {
112  } Emulate;
113 
114  // Wiper
115  struct _Wiper
116  {
121  int WiperWet;
122  } Wiper;
123 
124  // ATC
125  struct _ATC
126  {
127  int AtcUse;
128  int AtcType;
129  int AtcMax;
143  int Xe;
144  int Xo;
145  int Xk;
146  } ATC;
147 
148  // ATS_P
149  struct _ATS_P
150  {
151  int AtspUse;
152  int AtspMax;
154  } ATS_P;
155 
156 protected:
157 
160 
161  bool iniRW(string_t f, int r)
162  {
163  string_t s;
164 
165  s = _T("Emulate");
166  inimoni::inirw( r,f,s, _T("MaxDeceleration "), Emulate.MaxDeceleration );
167  inimoni::inirw( r,f,s, _T("LeverDelay "), Emulate.LeverDelay );
168 
169  s = _T("Wiper");
170  inimoni::inirw( r,f,s, _T("WiperRate "), Wiper.WiperRate );
171  inimoni::inirw( r,f,s, _T("WiperHoldPosition"), Wiper.WiperHoldPosition );
172  inimoni::inirw( r,f,s, _T("WiperDelay "), Wiper.WiperDelay );
173  inimoni::inirw( r,f,s, _T("WiperSoundBehaviour"), Wiper.WiperSoundBehaviour );
174  inimoni::inirw( r,f,s, _T("WiperWet "), Wiper.WiperWet );
175 
176  s = _T("ATC");
177  inimoni::inirw( r,f,s, _T("AtcUse "), ATC.AtcUse );
178  inimoni::inirw( r,f,s, _T("AtcType "), ATC.AtcType );
179  inimoni::inirw( r,f,s, _T("AtcMax "), ATC.AtcMax );
180  inimoni::inirw( r,f,s, _T("AtcSpeed3 "), ATC.AtcSpeed3 );
181  inimoni::inirw( r,f,s, _T("AtcSpeed4 "), ATC.AtcSpeed4 );
182  inimoni::inirw( r,f,s, _T("AtcSpeed5 "), ATC.AtcSpeed5 );
183  inimoni::inirw( r,f,s, _T("AtcSpeed6 "), ATC.AtcSpeed6 );
184  inimoni::inirw( r,f,s, _T("AtcSpeed7 "), ATC.AtcSpeed7 );
185  inimoni::inirw( r,f,s, _T("AtcSpeed8 "), ATC.AtcSpeed8 );
186  inimoni::inirw( r,f,s, _T("AtcSpeed9 "), ATC.AtcSpeed9 );
187  inimoni::inirw( r,f,s, _T("AtcSpeed10 "), ATC.AtcSpeed10 );
188  inimoni::inirw( r,f,s, _T("AtcSpeed11 "), ATC.AtcSpeed11 );
189  inimoni::inirw( r,f,s, _T("AtcDeceleration1 "), ATC.AtcDeceleration1 );
190  inimoni::inirw( r,f,s, _T("AtcDeceleration2 "), ATC.AtcDeceleration2 );
191  inimoni::inirw( r,f,s, _T("AtcDeceleration3 "), ATC.AtcDeceleration3 );
192  inimoni::inirw( r,f,s, _T("AtcDeceleration4 "), ATC.AtcDeceleration4 );
193  inimoni::inirw( r,f,s, _T("Xe "), ATC.Xe );
194  inimoni::inirw( r,f,s, _T("Xo "), ATC.Xo );
195  inimoni::inirw( r,f,s, _T("Xk "), ATC.Xk );
196 
197  s = _T("ATS_P");
198  inimoni::inirw( r,f,s, _T("AtspUse "), ATS_P.AtspUse );
199  inimoni::inirw( r,f,s, _T("AtspMax "), ATS_P.AtspMax );
200  inimoni::inirw( r,f,s, _T("AtspDeceleration "), ATS_P.AtspDeceleration );
201  return true;
202  }
203 
204  void init()
205  {
206  Emulate.MaxDeceleration = 2700;
207  Emulate.LeverDelay = 250;
208  Wiper.WiperRate = 700;
209  Wiper.WiperHoldPosition = 0;
210  Wiper.WiperDelay = 700;
211  Wiper.WiperSoundBehaviour = 0;
212  Wiper.WiperWet = 0;
213  ATC.AtcUse = 1;
214  ATC.AtcType = 0;
215  ATC.AtcMax = 220;
216  ATC.AtcSpeed3 = 120;
217  ATC.AtcSpeed4 = 170;
218  ATC.AtcSpeed5 = 220;
219  ATC.AtcSpeed6 = 230;
220  ATC.AtcSpeed7 = 255;
221  ATC.AtcSpeed8 = 270;
222  ATC.AtcSpeed9 = 275;
223  ATC.AtcSpeed10 = 285;
224  ATC.AtcSpeed11 = 300;
225  ATC.AtcDeceleration1 = 1500;
226  ATC.AtcDeceleration2 = 1900;
227  ATC.AtcDeceleration3 = 2400;
228  ATC.AtcDeceleration4 = 2600;
229  ATC.Xe = 5000;
230  ATC.Xo = 10000;
231  ATC.Xk = 0;
232  ATS_P.AtspUse = 0;
233  ATS_P.AtspMax = 140;
234  ATS_P.AtspDeceleration = 2600;
235  }
236 };
237 typedef AtcfsCfg AtcfsFile; //新旧互換
238 
239 //---------------------------------------------------------------------------
240 // Common method
241 //---------------------------------------------------------------------------
242 #ifndef INIMONI_INIRW
243 #define INIMONI_INIRW
244 namespace inimoni
245 {
246  /*
247  Read and Write INI file
248  int is_read 1=Read mode, 0=Write mode
249  string fname Filename (The Windows folder when there is not path)
250  string sec Section name
251  string key Key name
252  T val_t [Read]Init+Output, [Write]Input
253  */
254  template<class T>
255  bool inirw(int is_read, string_t& fname, string_t sec, string_t key, T& val_t)
256  {
257  if(is_read){
258  inimoni::read(fname.c_str(), sec.c_str(), key.c_str(), val_t);
259  }
260  else{
261  inimoni::write(fname.c_str(), sec.c_str(), key.c_str(), val_t);
262  }
263  return true;
264  }
265 
266  bool read(string_t ifn, string_t sec, string_t key, int& dst)
267  {
268  dst = GetPrivateProfileInt( sec.c_str(), key.c_str(), dst, ifn.c_str() );
269  return true;
270  }
271 
272  bool read(string_t ifn, string_t sec, string_t key, basic_string<TCHAR>& dst)
273  {
274  TCHAR buf[256];
275  GetPrivateProfileString(
276  sec.c_str(),
277  key.c_str(),
278  dst.c_str(),
279  buf,
280  sizeof(buf),
281  ifn.c_str() );
282  dst = buf;
283  return true;
284  }
285 
286  bool read(string_t ifn, string_t sec, string_t key, double& dst)
287  {
288  string_t s;
289  inimoni::read(ifn, sec, key, s);
290 
291  TCHAR* e;
292  double x = _tcstod(s.c_str(), &e);
293 
294  dst = 0.0;
295  if (!*e) {
296  dst = x;
297  }
298  return true;
299  }
300 
301  template<class T>
302  bool write(string_t ifn, string_t sec, string_t key, T val_t)
303  {
304  TCHAR val[1024];
305  inimoni::to_string(val, val_t);
306  WritePrivateProfileString( sec.c_str(), key.c_str(), val, ifn.c_str() );
307  return true;
308  }
309 
310  void to_string(TCHAR* str, int val)
311  {
312  _stprintf( str, _T("%d"), val );
313  }
314 
315  void to_string(TCHAR* str, double val)
316  {
317  _stprintf( str, _T("%f"), val );
318  }
319 
320  void to_string(TCHAR* str, basic_string<TCHAR> val)
321  {
322  _stprintf( str, _T("%s"), val.c_str() );
323  }
324 };
325 
326 #endif
327 #endif
328 
std::string string_t
Definition: AtcfsCfg.h:48
string_t initFileName
Definition: AtcfsCfg.h:158
int AtcSpeed9
Definition: AtcfsCfg.h:136
int AtcMax
Definition: AtcfsCfg.h:129
int AtcSpeed11
Definition: AtcfsCfg.h:138
void init()
Definition: AtcfsCfg.h:204
bool load(string_t fname=_T(""))
Definition: AtcfsCfg.h:76
int AtspDeceleration
Definition: AtcfsCfg.h:153
bool iniRW(string_t f, int r)
Definition: AtcfsCfg.h:161
bool read(string_t ifn, string_t sec, string_t key, int &dst)
Definition: AtcfsCfg.h:266
int WiperWet
Definition: AtcfsCfg.h:121
int AtcSpeed4
Definition: AtcfsCfg.h:131
int WiperRate
Definition: AtcfsCfg.h:117
int AtcSpeed10
Definition: AtcfsCfg.h:137
int AtcSpeed5
Definition: AtcfsCfg.h:132
Definition: AtcfsCfg.h:108
bool inirw(int is_read, string_t &fname, string_t sec, string_t key, T &val_t)
Definition: AtcfsCfg.h:255
int AtcDeceleration1
Definition: AtcfsCfg.h:139
int AtcSpeed8
Definition: AtcfsCfg.h:135
int WiperDelay
Definition: AtcfsCfg.h:119
int Xk
Definition: AtcfsCfg.h:145
int WiperHoldPosition
Definition: AtcfsCfg.h:118
AtcfsCfg(string_t fname=_T(""))
Definition: AtcfsCfg.h:63
void to_string(TCHAR *str, basic_string< TCHAR > val)
Definition: AtcfsCfg.h:320
int MaxDeceleration
Definition: AtcfsCfg.h:110
bool write(string_t ifn, string_t sec, string_t key, T val_t)
Definition: AtcfsCfg.h:302
int WiperSoundBehaviour
Definition: AtcfsCfg.h:120
int AtcSpeed7
Definition: AtcfsCfg.h:134
int AtspMax
Definition: AtcfsCfg.h:152
int AtspUse
Definition: AtcfsCfg.h:151
int Xe
Definition: AtcfsCfg.h:143
int AtcDeceleration4
Definition: AtcfsCfg.h:142
Definition: AtcfsCfg.h:115
bool read(string_t ifn, string_t sec, string_t key, double &dst)
Definition: AtcfsCfg.h:286
int AtcDeceleration2
Definition: AtcfsCfg.h:140
void to_string(TCHAR *str, int val)
Definition: AtcfsCfg.h:310
int AtcSpeed3
Definition: AtcfsCfg.h:130
Definition: AtcfsCfg.h:125
static bool inirw(int is_read, string_t &fname, string_t sec, string_t key, T &val_t)
Definition: AtcfsCfg.h:255
bool save(string_t fname=_T(""))
Definition: AtcfsCfg.h:96
int LeverDelay
Definition: AtcfsCfg.h:111
int AtcType
Definition: AtcfsCfg.h:128
int AtcUse
Definition: AtcfsCfg.h:127
int AtcDeceleration3
Definition: AtcfsCfg.h:141
Definition: Wiper.h:37
Definition: AtcfsCfg.h:149
Definition: AtcfsCfg.h:59
int Xo
Definition: AtcfsCfg.h:144
int AtcSpeed6
Definition: AtcfsCfg.h:133
AtcfsCfg AtcfsFile
Definition: AtcfsCfg.h:237
string_t loadFileName
Definition: AtcfsCfg.h:159