ホーム » 2018 » 11月

月別アーカイブ: 11月 2018

2018年11月
 123
45678910
11121314151617
18192021222324
252627282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,437 アクセス



template の複数の型の順番

先日作成した template .
  template <class V3, class VT> V3 ToV3 (const VT& vt,const long type)
型の順番で,戻り値の型 V3 と,引数の型 VT .
どちらを先に指定した方が良いか悩んだが,呼び出しで省略する場合を考慮するとこれで良さそう.
  Vd4 v4(1,2,3,1) ;
  Vd3 v3(1,2,3) ;
  Vd2 v2(1,2) ;
  Vd3 v43 = ToV3<Vd3/*,Vd4*/>(v4,to_x0y) ;
  Vd3 v33 = ToV3<Vd3/*,Vd3*/>(v3,to_x0y) ;
  Vd3 v23 = ToV3<Vd3/*,Vd2*/>(v2,to_x0y) ;

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

::ToV3<Vd3,Vd2>(v2,to_x0y) で C2784

次の様な template の利用で,C2784 エラー.

    Vd2 v2(1,2) ;
    Vd3 v3 = ::ToV3<Vd3,Vd2>(v2,to_x0y) ;

\\DevS\...\tovxx.hxx(123) : error C2784: 'struct Vector3<T> __cdecl ToX0Y(const struct Vector4<T> &)' : 'const struct Vector4<T> & 用のテンプレート引数を 'const struct Vector2<double>' から減少できませんでした。 C:\... \VF3DView.cpp(236) : コンパイルされたクラスのテンプレートのインスタンス化 'struct Vector3<double> __cdecl ToV3(const struct Vector2<double> &,const long)' の参照を確認してください
template <class V3, class VT> V3 ToV3 (const VT& vt,const long type) { V3 v3 ; { switch (type) { case to_xyz : v3 = ::ToXYZ(vt) ; break ; case to_xzy : v3 = ::ToXZY(vt) ; break ; case to_x0y : v3 = ::ToX0Y(vt) ; break ; default : v3 = ::ToXYZ(vt) ; break ; } } return v3 ; }
Vector4 のものは昨日定義していたが,Vector2 のものを追加.ついでに Vector3 も. template <class T> Vector3<T> ToXYZ (const Vector2<T>& p) { return Vector3<T> (p.x,p.y, 0 ) ; } template <class T> Vector3<T> ToXYZ (const Vector3<T>& p) { return Vector3<T> (p.x,p.y,p.z) ; } template <class T> Vector3<T> ToXZY (const Vector2<T>& p) { return Vector3<T> (p.x, 0 ,p.y) ; } template <class T> Vector3<T> ToXZY (const Vector3<T>& p) { return Vector3<T> (p.x,p.z,p.y) ; } template <class T> Vector3<T> ToX0Y (const Vector2<T>& p) { return Vector3<T> (p.x, 0 ,p.y) ; } template <class T> Vector3<T> ToX0Y (const Vector3<T>& p) { return Vector3<T> (p.x, 0 ,p.y) ; }

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

template で複数の型を指定

template で複数の型を指定する場合は,カンマで区切って指定すれば良い.

    template <class V2, class V3> V2 ToV2 (const V3& v3,const long type)
    {
        V2 v2 ;
        switch (type) {
            case to_xy : v2 = ::ToXY(v3) ; break ;
            case to_yz : v2 = ::ToYZ(v3) ; break ;
            case to_zx : v2 = ::ToZX(v3) ; break ;
            case to_xz : v2 = ::ToXZ(v3) ; break ;
            default :    v2 = ::ToXY(v3) ; break ;
            }
        return v2 ;
        }

呼び出しは,次の様な感じ.

    Vd3 v3 = Vd3(1,2,3) ;
    Vd2 v2 = ::ToV2<Vd2,Vd3>(v3,to_xy) ;

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

WEB SQL Injection Attempt -87

ルータ RT-AC86U の AiProtection ではじかれているが,今日は Web サーバへの攻撃が多い?
2018-11-22 18:06:23  External Attacks  129.121.176.228  192.168.x.x WEB SQL Injection Attempt -87


Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

ファイルの検索

あるフォルダ内のファイルを列挙するコード 

MFC
v_tstring	EnumFiles_MFC	(c_tstring& path,const bool skipDot=true)
{
	v_tstring	foundFiles ;
	{
		iFileFind	ff ;
		BOOL		isWorking = ff.FindFile((::Path_AddLastSP(path)+_T("*.*")).c_str()) ;
		while	(isWorking)	{
			 	isWorking = ff.FindNextFile() ;
			if (skipDot && ff.IsDots()) {	continue ;	}
			tstring	fileName = ff.GetFileName() ;
			if (ff.IsDirectory()) {
				fileName = ::Path_AddLastSP(fileName) ;
				}
			foundFiles.push_back(::Path_AddLastSP(path)+fileName) ;
			}
		}
	return	foundFiles ;
	}

MSC
v_tstring	EnumFiles_MSC	(c_tstring& path,const bool skipDot=true)
{
	v_tstring	foundFiles ;
	{
		tstring	fffPath = ::Path_AddLastSP(path)+_T("*.*") ;
		WIN32_FIND_DATA	fd ;
		memset(&fd,0,sizeof(WIN32_FIND_DATA)) ;
		HANDLE	hFind = ::FindFirstFile(fffPath.c_str(),&fd) ;
		if (hFind != INVALID_HANDLE_VALUE) {
			while	(TRUE)	{
				tstring	fileName = fd.cFileName ;
				if (skipDot) {
					if (fileName == _T("."))   {	fileName = _T("") ;	}
					if (fileName == _T(".."))  {	fileName = _T("") ;	}
					}
				if (!fileName.empty()) {
					if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
						fileName = ::Path_AddLastSP(fileName) ;
						}
					foundFiles.push_back(::Path_AddLastSP(path)+fileName) ;
					}
				if (!::FindNextFile(hFind,&fd)) {
					break ;
					}
				}
			::FindClose(hFind) ;
			}
		}
	return	foundFiles ;
	}

GNUC
v_tstring	EnumFiles_GNUC	(c_tstring& path_,const bool skipDot=true)
{
	tstring 	path = path_ ;
	v_tstring	foundFiles ;
	{
		DIR*	dp = ::opendir(path.c_str()) ;
		struct	dirent*	dent = NULL ;
		do	{
			dent = readdir(dp) ;
			if (dent != NULL)	{
				tstring	fileName = dent->d_name ;
				if (skipDot) {
					if (fileName == _T("."))   {	continue ;	}
					if (fileName == _T(".."))  {	continue ;	}
					}
				if (dent->d_type & DT_DIR) {
					fileName = ::Path_AddLastSP(fileName) ;
					}
				foundFiles.push_back(::Path_AddLastSP(path)+fileName) ;
				}
			}	while (dent != NULL) ;
		::closedir(dp) ;
		}
	return	foundFiles ;
	}

MFC 版で,iFileFind としているのは,VC 6 MFC MBCS 版でのバグのため.

class	iFileFind	:	public	CFileFind	{
	public:
		virtual	CString GetFilePath() const	{
			ASSERT(m_hContext != NULL);
			ASSERT_VALID(this);
			CString strResult = m_strRoot;
			#ifdef	____VC_6_______MBCS_BUG___
			{
				if (strResult[strResult.GetLength()-1] != '\\' &&
					strResult[strResult.GetLength()-1] != '/')	{
					strResult += m_chDirSeparator;
					}
				}
			#else
			{
				LPCTSTR pszResult;
				LPCTSTR pchLast;
				pszResult = strResult;
				pchLast = _tcsdec( pszResult, pszResult+strResult.GetLength() );
				VERIFY(pchLast!=NULL);
				if ((*pchLast != _T('\\')) && (*pchLast != _T('/')))	{
					strResult += m_chDirSeparator;
					}
				}
			#endif
			strResult += GetFileName();
			return strResult;
			}
		} ;

MFC 7 以降であれば,CFileFind として利用可能.


i_FileF.hxx
enumfile.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Chrome の「Google で画像を検索」

Chrome でちょっと面白い機能を見つけたのでメモ.
画像を右クリックして「Google で画像を検索」.
Chrome の「Google で画像を検索」
類似画像が表示される.
「Google で画像を検索」
もとの画像によっては,かなり近い画像が見つかることもある.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

vector<Xxxx<T>> の利用でのエラー

template <class T> Extent2<T> E2_GetExtent (const std::vector<VLine2<T>>& lins)     //  エラー
template <class T> Extent2<T> E2_GetExtent (const std::vector< VLine2<T> >& lins)   //  OK

vector<VLine2<T>> の様にスペースがないとエラーになる.
vector<  VLine2<T>  > の様に空ければ OK .

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.