TNB Library
TnbMutualAccessor.h
[詳解]
1#pragma once
11#include "TnbAccessor.h"
12#include "TnbSerializer.h"
13
14
15
16//TNB Library
17namespace TNB
18{
19
20
21
72{
73public:
74
87 struct IWorker
88 {
90 virtual ~IWorker(void) {}
91
100 virtual bool MutualAccessWorks(IAccessor::CSection& sec, LPCTSTR lpszKey, bool isQuery) = 0;
101
102 #ifndef _TnbDOXYGEN //Document作成用シンボル
103 virtual bool Works(IAccessor::CSection& sec, LPCTSTR lpszKey, bool isQuery)
104 {
105 return MutualAccessWorks(sec, lpszKey, isQuery);
106 }
107 #endif
108 };
109
123 {
124 public:
130 CSubSection(CMutualAccessor* P, LPCTSTR lpszSub) : m_pMu(P), m_success(false)
131 {
132 m_success = m_pMu->InSubSection(lpszSub);
133 }
136 {
137 if ( m_success )
138 {
139 m_pMu->PreviousSubSection();
140 }
141 }
142 private:
143 CMutualAccessor* m_pMu;
144 bool m_success;
145 };
146
147
148 //----------------------------------------------------------------
149
150
152 enum EMode
153 {
156 };
157
164 : m_sec(IAccessor::CSection(pAccessor, _T(""))), m_isQuery(mode == QUERY)
165 {
166 }
167
174 : m_sec(sec), m_isQuery(mode == QUERY)
175 {
176 }
177
185 bool InSubSection(LPCTSTR lpszSection)
186 {
187 return m_Result(m_sec.InSubSection(lpszSection));
188 }
189
196 {
197 m_sec.PreviousSubSection();
198 }
199
205 bool IsQueryMode(void) const
206 {
207 return m_isQuery;
208 }
209
215 bool IsWriteMode(void) const
216 {
217 return ! m_isQuery;
218 }
219
227 {
228 return &m_sec;
229 }
230
241 bool Works(LPCTSTR lpszKey, bool& _boValue, bool def = false)
242 {
243 CStrVector vs;
244 vs.Add(_T("false"));
245 vs.Add(_T("true"));
246 DWORD w = _boValue;
247 bool r = Works(lpszKey, w, vs, def);
248 _boValue = (w != 0);
249 return m_Result(r);
250 }
251
261 bool Works(LPCTSTR lpszKey, BYTE& _bValue, BYTE def = 0)
262 {
263 if ( m_isQuery )
264 {
265 DWORD w = m_sec.QueryDword(lpszKey, def);
266 _bValue = static_cast<BYTE>(w);
267 return true;
268 }
269 return m_Result(m_sec.WriteDword(lpszKey, _bValue));
270 }
271
281 bool Works(LPCTSTR lpszKey, WORD& _wValue, WORD def = 0)
282 {
283 if ( m_isQuery )
284 {
285 DWORD w = m_sec.QueryDword(lpszKey, def);
286 _wValue = static_cast<WORD>(w);
287 return true;
288 }
289 return m_Result(m_sec.WriteDword(lpszKey, _wValue));
290 }
291
301 bool Works(LPCTSTR lpszKey, short& _value, short def = 0)
302 {
303 if ( m_isQuery )
304 {
305 DWORD w = m_sec.QueryDword(lpszKey, def);
306 _value = static_cast<short>(w);
307 return true;
308 }
309 return m_Result(m_sec.WriteDword(lpszKey, _value));
310 }
311
321 bool Works(LPCTSTR lpszKey, DWORD& _dwValue, DWORD def = 0)
322 {
323 if ( m_isQuery )
324 {
325 _dwValue = m_sec.QueryDword(lpszKey, def);
326 return true;
327 }
328 return m_Result(m_sec.WriteDword(lpszKey, _dwValue));
329 }
330
340 bool Works(LPCTSTR lpszKey, int& _iValue, int def = 0)
341 {
342 if ( m_isQuery )
343 {
344 LONGLONG l = m_sec.QueryLonglong(lpszKey, def);
345 _iValue = static_cast<int>(l);
346 return true;
347 }
348 return m_Result(m_sec.WriteLonglong(lpszKey, _iValue));
349 }
350
360 bool Works(LPCTSTR lpszKey, long& _lValue, long def = 0)
361 {
362 if ( m_isQuery )
363 {
364 LONGLONG l = m_sec.QueryLonglong(lpszKey, def);
365 _lValue = static_cast<long>(l);
366 return true;
367 }
368 return m_Result(m_sec.WriteLonglong(lpszKey, _lValue));
369 }
370
380 bool Works(LPCTSTR lpszKey, LONGLONG& _llValue, LONGLONG def = 0)
381 {
382 if ( m_isQuery )
383 {
384 _llValue = m_sec.QueryLonglong(lpszKey, def);
385 return true;
386 }
387 return m_Result(m_sec.WriteLonglong(lpszKey, _llValue));
388 }
389
399 bool Works(LPCTSTR lpszKey, double& _value, double def = 0.0)
400 {
401 if ( m_isQuery )
402 {
403 CByteVector vb = m_sec.QueryData(lpszKey);
404 _value = def;
405 if ( vb.GetSize() == sizeof(double) )
406 {
407 _value = *reinterpret_cast<const double*>(vb.ReferBuffer());
408
409 }
410 return true;
411 }
412 return m_Result(m_sec.WriteData(lpszKey, CConstAdapterT<BYTE>(sizeof(double), &_value)));
413 }
414
424 bool Works(LPCTSTR lpszKey, CStr& _strValue, LPCTSTR def = NULL)
425 {
426 if ( m_isQuery )
427 {
428 _strValue = m_sec.QueryString(lpszKey, def);
429 return true;
430 }
431 return m_Result(m_sec.WriteString(lpszKey, _strValue));
432 }
433
443 bool Works(LPCTSTR lpszKey, size_t size, LPVOID P)
444 {
445 if ( m_isQuery )
446 {
447 CByteVector vb = m_sec.QueryData(lpszKey);
448 memset(P, 0, size);
449 if ( vb.GetSize() == size )
450 {
451 vb.GetElements(size, static_cast<BYTE*>(P));
452 }
453 return true;
454 }
455 return m_Result(m_sec.WriteData(lpszKey, CConstAdapterT<BYTE>(size, P)));
456 }
457
466 bool Works(LPCTSTR lpszKey, ICollectionT<BYTE>& _c)
467 {
468 if ( m_isQuery )
469 {
470 CByteVector vb = m_sec.QueryData(lpszKey);
471 _c.Copy(vb);
472 return true;
473 }
474 return m_Result(m_sec.WriteData(lpszKey, _c));
475 }
476
485 bool Works(LPCTSTR lpszKey, ISerializable& _s)
486 {
487 ASSERTLIB( false ); // このメソッドは潜在的なバグのある可能性があります。
488 CSubSection sub(this, lpszKey);
489 bool r = false;
490 try
491 {
492 CMySerializer sr(&m_sec);
493 if ( m_isQuery )
494 {
495 sr >> _s;
496 }
497 else
498 {
499 m_sec.DeleteAllKeys();
500 sr << _s;
501 }
502 r = true;
503 }
504 catch ( CNoSuchTypeException& e )
505 {
506 e.OnCatch();
507 }
508 return r;
509 }
510
522 bool Works(LPCTSTR lpszKey, DWORD& _dwValue, const CStrVector& vs, DWORD def = 0)
523 {
524 if ( m_isQuery )
525 {
526 _dwValue = def;
527 if ( ! m_sec.HasKey(lpszKey) )
528 {
529 return true;
530 }
531 CStr s = m_sec.QueryString(lpszKey);
532 INDEX r = vs.Find(s);
533 if ( r != INVALID_INDEX )
534 {
535 _dwValue = r;
536 return true;
537 }
538 return m_Result(false);
539 }
540 if ( vs.GetSize() > _dwValue )
541 {
542 return m_Result(m_sec.WriteString(lpszKey, vs[_dwValue]));
543 }
544 m_sec.DeleteKey(lpszKey);
545 return m_Result(false);
546 }
547
556 bool Works(LPCTSTR lpszKey, IWorker& _worker)
557 {
558 bool r = _worker.Works(m_sec, lpszKey, m_isQuery);
559 return m_Result(r);
560 }
561
562#ifdef __AFX_H__
572 bool Works(LPCTSTR lpszKey, CString& _strValue, LPCTSTR def = NULL)
573 {
574 if ( m_isQuery )
575 {
576 _strValue = m_sec.QueryString(lpszKey, def);
577 return true;
578 }
579 CStr s = _strValue;
580 return m_Result(m_sec.WriteString(lpszKey, s));
581 }
582
592 bool Works(LPCTSTR lpszKey, HWND hWnd, LPCTSTR def = NULL)
593 {
594 if ( m_isQuery )
595 {
596 m_sec.QueryWindowText(lpszKey, hWnd, def);
597 return true;
598 }
599 return m_Result(m_sec.WriteWindowText(lpszKey, hWnd));
600 }
601
611 bool Works(LPCTSTR lpszKey, CComboBox& comboBox, int def = 0)
612 {
613 if ( m_isQuery )
614 {
615 comboBox.SetCurSel(m_sec.QueryDword(lpszKey, def));
616 return true;
617 }
618 return m_Result(m_sec.WriteDword(lpszKey, comboBox.GetCurSel()));
619 }
620
630 bool Works(LPCTSTR lpszKey, CButton& button, int def = BST_UNCHECKED)
631 {
632 if ( m_isQuery )
633 {
634 button.SetCheck(m_sec.QueryDword(lpszKey, def));
635 return true;
636 }
637 return m_Result(m_sec.WriteDword(lpszKey, button.GetCheck()));
638 }
639#endif //__AFX_H__
640
641protected:
642
648 virtual void OnFalse(void) const
649 {
650 }
651
652private:
653
654 bool m_isQuery;
655 IAccessor::CSection m_sec;
657 bool m_Result(bool r) const
658 {
659 if ( ! r )
660 {
661 OnFalse();
662 }
663 return r;
664 }
665
666 // シリアライザー
667 class CMySerializer : public ISerializer, public IDeserializer
668 {
669 public:
674 CMySerializer(IAccessor::CSection* P) : m_pSec(P), m_count(0)
675 {
676 }
682 virtual void AddRaw(size_t size, LPCVOID P)
683 {
684 m_pSec->WriteData(CStr::Fmt(_T("%04d"), m_count), CConstAdapterT<BYTE>(size, P));
685 m_count++;
686 }
692 virtual void GetRaw(size_t size, LPVOID _P) const
693 {
694 CByteVector vb = m_pSec->QueryData(CStr::Fmt(_T("%04d"), m_count));
695 if ( size != vb.GetSize() )
696 {
697 throw CNoSuchTypeException();
698 }
699 vb.GetElements(size, static_cast<BYTE*>(_P));
700 m_count++;
701 }
702 private:
703 mutable int m_count;
704 IAccessor::CSection* m_pSec;
705 };
706};
707
708
709
710}; // TNB
情報アクセス関係のヘッダ
シリアライザー関係のヘッダ
ボタンコントロール.
情報参照アダプタテンプレート
情報相互アクセスサブセクションクラス
~CSubSection(void)
デストラクタ
CSubSection(CMutualAccessor *P, LPCTSTR lpszSub)
コンストラクタ
情報相互アクセスクラス
bool InSubSection(LPCTSTR lpszSection)
[設定] 対象セクション変更.
bool IsQueryMode(void) const
[確認] モード確認
IAccessor::CSection * operator->(void)
[参照] CSection 参照.
bool Works(LPCTSTR lpszKey, int &_iValue, int def=0)
[処理] int 情報処理.
CMutualAccessor(IAccessor::CSection &sec, EMode mode=QUERY)
コンストラクタ
bool Works(LPCTSTR lpszKey, size_t size, LPVOID P)
[処理] レガシー構造体情報処理.
virtual void OnFalse(void) const
[通知] 各処理失敗通知.
bool Works(LPCTSTR lpszKey, LONGLONG &_llValue, LONGLONG def=0)
[処理] LONGLONG 情報処理.
bool Works(LPCTSTR lpszKey, CButton &button, int def=BST_UNCHECKED)
[処理] ボタン情報処理.
bool Works(LPCTSTR lpszKey, ICollectionT< BYTE > &_c)
[処理] コレクション情報処理.
bool Works(LPCTSTR lpszKey, CString &_strValue, LPCTSTR def=NULL)
[処理] 文字列情報処理.
bool Works(LPCTSTR lpszKey, ISerializable &_s)
[処理] シリアライザブル情報処理.
bool Works(LPCTSTR lpszKey, short &_value, short def=0)
[処理] short 情報処理.
bool Works(LPCTSTR lpszKey, CComboBox &comboBox, int def=0)
[処理] コンボボックス情報処理.
bool IsWriteMode(void) const
[確認] モード確認
bool Works(LPCTSTR lpszKey, HWND hWnd, LPCTSTR def=NULL)
[処理] ウィンドウテキスト情報処理.
void PreviousSubSection(void)
[設定] 対象セクション変更.
bool Works(LPCTSTR lpszKey, double &_value, double def=0.0)
[処理] LONGLONG 情報処理.
CMutualAccessor(IAccessor *pAccessor, EMode mode=QUERY)
コンストラクタ
bool Works(LPCTSTR lpszKey, BYTE &_bValue, BYTE def=0)
[処理] BYTE 情報処理.
bool Works(LPCTSTR lpszKey, DWORD &_dwValue, DWORD def=0)
[処理] DWORD 情報処理.
bool Works(LPCTSTR lpszKey, CStr &_strValue, LPCTSTR def=NULL)
[処理] 文字列情報処理.
bool Works(LPCTSTR lpszKey, long &_lValue, long def=0)
[処理] long 情報処理.
bool Works(LPCTSTR lpszKey, bool &_boValue, bool def=false)
[処理] bool 情報処理.
bool Works(LPCTSTR lpszKey, WORD &_wValue, WORD def=0)
[処理] WORD 情報処理.
bool Works(LPCTSTR lpszKey, IWorker &_worker)
[処理] ワーカー情報処理.
bool Works(LPCTSTR lpszKey, DWORD &_dwValue, const CStrVector &vs, DWORD def=0)
[処理] DWORD 情報処理.
タイプ相違例外
Definition: TnbException.h:146
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
Definition: TnbStr.h:1206
void OnCatch(void) const
[表示] 内容表示
Definition: TnbException.h:69
virtual size_t GetSize(void) const
[取得] サイズ取得
Definition: TnbVector.h:368
virtual const TYP * ReferBuffer(void) const
[取得] データアドレス取得
Definition: TnbVector.h:664
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
Definition: TnbVector.h:383
セクション情報アクセスクラス
Definition: TnbAccessor.h:294
bool WriteWindowText(LPCTSTR lpszKey, HWND hWnd)
[追加] ウィンドウテキスト情報記録
Definition: TnbAccessor.h:751
CStr QueryString(LPCTSTR lpszKey, LPCTSTR lpszDefault=NULL) const
[取得] 文字列情報取得
Definition: TnbAccessor.h:506
bool InSubSection(LPCTSTR lpszSubName)
[設定] 対象セクション変更.
Definition: TnbAccessor.h:365
bool WriteDword(LPCTSTR lpszKey, DWORD dwValue)
[追加] 数値情報記録
Definition: TnbAccessor.h:576
bool QueryWindowText(LPCTSTR lpszKey, HWND hWnd, LPCTSTR lpszDefault=NULL) const
[取得] ウィンドウテキスト情報取得
Definition: TnbAccessor.h:772
bool WriteString(LPCTSTR lpszKey, LPCTSTR lpszValue)
[追加] 文字列情報記録
Definition: TnbAccessor.h:495
LONGLONG QueryLonglong(LPCTSTR lpszKey, LONGLONG llDefault=0) const
[取得] 数値情報取得
Definition: TnbAccessor.h:611
bool WriteData(LPCTSTR lpszKey, const IConstCollectionT< BYTE > &c)
[追加] バイナリ情報記録
Definition: TnbAccessor.h:541
bool HasKey(LPCTSTR lpszKey) const
[確認] 情報存在確認
Definition: TnbAccessor.h:450
bool DeleteAllKeys(void)
[削除] 全キー削除
Definition: TnbAccessor.h:429
void PreviousSubSection(void)
[設定] 対象セクション変更.
Definition: TnbAccessor.h:384
DWORD QueryDword(LPCTSTR lpszKey, DWORD dwDefault=0) const
[取得] 数値情報取得
Definition: TnbAccessor.h:587
bool WriteLonglong(LPCTSTR lpszKey, LONGLONG llValue)
[追加] 数値情報記録
Definition: TnbAccessor.h:600
bool DeleteKey(LPCTSTR lpszKey)
[削除] 指定キー削除
Definition: TnbAccessor.h:461
CByteVector QueryData(LPCTSTR lpszKey) const
[取得] バイナリ情報取得
Definition: TnbAccessor.h:564
TNB Library
Definition: TnbDoxyTitle.txt:2
情報相互アクセスのワーカーインターフェース
virtual bool MutualAccessWorks(IAccessor::CSection &sec, LPCTSTR lpszKey, bool isQuery)=0
[処理]
virtual ~IWorker(void)
デストラクタ
情報アクセスインターフェース.
Definition: TnbAccessor.h:74
virtual size_t Copy(const IConstCollectionT< TYP > &c)
[設定] コピー.
virtual size_t GetElements(size_t size, TYP *_P, INDEX offset=0) const
[取得] 複数要素取り出し.
INDEX Find(const IChecker &checker, INDEX startIndex=0, bool boIsReverse=false) const
[検索] 条件一致要素の検索.
デシリアライザーインターフェースクラス.
シリアライザブルインターフェース.
Definition: TnbSerializer.h:47
シリアライザーインターフェースクラス.