ホーム » gcc » クラスの配列のダンプ

2019年6月
 1
2345678
9101112131415
16171819202122
23242526272829
30  

カテゴリー

アーカイブ

ブログ統計情報

  • 79,631 アクセス



クラスの配列のダンプ

先日の「クラスの配列」をダンプする template を利用するためのサンプル.

// *******************************************************************************
// Name   : tpl_tstr.cpp
//        : test template To_string vector
// Author : I. Nakagawa
// Create : 2019/06/13
// *******************************************************************************

#include <iostream>
#include "i_vector.hxx"
#include "tstring.hxx"
#include "i_define.hxx"
#include "_tdefine.hxx"

// *******************************************************************************
// To tstring
// Create : 2019/06/10
// *******************************************************************************
template <class T> tstring To_tstring(const std::vector<T>& vt)
{
    tstring str ;
    for (size_t index=0 ; index<vt.size() ; index++) {
        T       e1 = vt[index] ;
        tstring s1 = e1.To_tstring() ;
        str += s1 + _T("\r\n") ;
        }
    return str ;
    }

// *******************************************************************************
// sample class
// Create : 2019/06/13
// *******************************************************************************
class Str_2 {
public:
    Str_2 (const tstring& s1=tstring(),const tstring& s2=tstring()) { Str1 = s1 ; Str2 = s2 ; }
public:
    virtual tstring To_tstring (void) const { return Str1 + _T("\t") + Str2 ; }
protected:
    tstring Str1 ;
    tstring Str2 ;
    } ;

typedef std::vector<Str_2> v_Str_2 ;

// *******************************************************************************
// main
// Create : 2019/06/13
// *******************************************************************************
int _tmain (int argc,TCHAR* argv[])
{
    _tsetlocale(LC_ALL,_T("")) ;
    {
        v_Str_2 v_s2 ;
        {
            Str_2 sd_1(_T("asdf"),_T("qwer")) ;
            Str_2 sd_2(_T("zxcv"),_T("ASDF")) ;
            Str_2 sd_3(_T("QWER"),_T("ZXCV")) ;
            Str_2 sd_4(_T("1234")) ;
            Str_2 sd_5 ;
            v_s2.push_back(sd_1) ;
            v_s2.push_back(sd_2) ;
            v_s2.push_back(sd_3) ;
            v_s2.push_back(sd_4) ;
            v_s2.push_back(sd_5) ;
            v_s2.push_back(sd_4) ;
            v_s2.push_back(sd_3) ;
            v_s2.push_back(sd_2) ;
            v_s2.push_back(sd_1) ;
            }
        std::tout << ::To_tstring<Str_2>(v_s2) ;
        }
    return 0 ;
    }

DS116 での動作テスト.
DS116 上でのクラスの配列のダンプ

C:\WINDOWS\system32>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 22 192.168.xx.xx
Iwao@192.168.xx.xx's password:
Iwao@DS116:~$ source ./set_ds_inc.sh
Iwao@DS116:~$ cd gcc_test/Test/tpl_tstr/
Iwao@DS116:~/gcc_test/Test/tpl_tstr$ ll
total 20
drwxrwxrwx+  3 Iwao users  4096 Jun 13 10:42 .
drwxrwxrwx+ 15 Iwao users  4096 Jun 13 10:32 ..
drwxrwxrwx+  2 Iwao users  4096 Jun 13 10:42 bak
-rwxrwxrwx+  1 Iwao users  2166 Jun 13 10:35 tpl_tstr.cpp
Iwao@DS116:~/gcc_test/Test/tpl_tstr$ g++ tpl_tstr.cpp
Iwao@DS116:~/gcc_test/Test/tpl_tstr$ ll
total 44
drwxrwxrwx+  3 Iwao users  4096 Jun 13 10:43 .
drwxrwxrwx+ 15 Iwao users  4096 Jun 13 10:32 ..
-rwxrwxrwx   1 Iwao users 23540 Jun 13 10:43 a.out
drwxrwxrwx+  2 Iwao users  4096 Jun 13 10:42 bak
-rwxrwxrwx+  1 Iwao users  2166 Jun 13 10:35 tpl_tstr.cpp
Iwao@DS116:~/gcc_test/Test/tpl_tstr$ ./a.out
asdf qwer
zxcv ASDF
QWER ZXCV
1234

1234
QWER ZXCV
zxcv ASDF
asdf qwer
Iwao@DS116:~/gcc_test/Test/tpl_tstr$ 
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

1件のコメント

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。