본문 바로가기
kxLibrary

kxBuffLib::kxFile Class Source Code

by 두루물 2011. 10. 6.
/*
 * kxBuffLibrary : krkim's eXtended Intelligent & Sequencial Linear Buffer Library
 * PURPOSE : Intelligent increasing buffer with a big buffer data,add to sequencial data,
 * 	         string,list like MFC String or PtrArray on Non-MFC platforms(general C/C++).
 * 
 * Copyright(c) 2005-2010 Durumul.com ,Korea
 * Author  : KRKIM(kyung rae kim) 
 * yeamaec@hanafos.com (http://www.durumul.com, http://krkim.net)
 * 
 * Version : 1.0.4
 * This source is free to use as you like but leave this notice.
 * If you make any changes(bugfix,updating),please mail the new version to me.
 * 
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

/*
  History:
    1.0.3  - 2007.11.27 <krkim> add operators to IBuff.
    1.0.2  - 2007.11    <krkim> Renew TCHAR and LPTSTR for UNICODE Compatible.
    1.0.1  - 2006.12.07 <krkim> Add resize at kxList.
    1.0.0  - not support decreasing buffer.
    Initial version 1.0 2005 12.15 KRKIM.
 */
#pragma once
#pragma warning (push)
#pragma warning(disable : 4996)

#ifndef KXFILE__H
#define KXFILE__H
#include <kxbuff.h>

namespace kxBuffLib{

class kxFile
{
public:
	FILE *m_fp;
	kxFile(){
		m_fp = 0;
	}
	kxFile(kxString file,kxString mode){
		m_fp = fopen(file,mode);
	}
	~kxFile(){
		if(m_fp) fclose(m_fp);
		m_fp = 0;
	}
	FILE *fp(){
		return m_fp;
	}
	bool IsOpened() { return m_fp != 0;}
	bool Close(){
		if(m_fp)
			fclose(m_fp);
		m_fp = 0;
	}
	kxFile& operator=(const kxFile& srcFile){ 
		Close();
		m_fp = srcFile.m_fp;
		return (*this); 
	}
	//
	// 밀리 초는 10^-3 초 입니다.마이크로는 10^-6초 나노초는 10^-9초 피코초는 10^-12초 입니다 10^-1 = 10분의 1초
	static INT64 ConvFileTime(FILETIME filetime)//10초당 (100나노초) 단위
	{
		INT64 i64;
		//FILETIME = 100나노초
		i64=(((INT64)filetime.dwHighDateTime) << 32) + filetime.dwLowDateTime;
		i64 = i64 / 100000000;//10초를 100나노초 단위로 환산
		return i64;
	}

	static INT64 ConvSystemTime(SYSTEMTIME systime)//10초 단위 100나노초단위로 변환
	{
		INT64 i64;
		FILETIME ft;//100나노초 단위

		//1초 = 1000000000 나노초
		//1초 = 10000000 (100나노초)
		//하루 = 86400 초 = 864000000000 (100나노초)
		//1분 = 60초
		systime.wMilliseconds = systime.wDayOfWeek = 0;
		SystemTimeToFileTime(&systime,&ft);
		i64=ConvFileTime(ft);
		return i64;
	}

	static bool FileExists(LPCTSTR szFile,INT64 *lwtime = NULL)
	{
		HANDLE flag32;
		WIN32_FIND_DATA read32={0,};//32bit porting routine..
		if((flag32 = FindFirstFile(szFile,&read32)) == INVALID_HANDLE_VALUE){
			if(lwtime)
				*lwtime = kxFile::ConvFileTime(read32.ftLastWriteTime);
			return false;
		}
		FindClose(flag32);
		return true;
	}
};

}

using namespace kxBuffLib;

#endif
#pragma warning (pop)

'kxLibrary' 카테고리의 다른 글

kxLibrary Class Diagram  (0) 2012.04.11
KFCApp Class Updated  (0) 2012.04.11
KFC1.0 Class Update For KFCScrollBar  (0) 2011.05.05
KFC1.0 Class Update For KFCBitmap  (0) 2011.05.05
KFC1.0 Class Update For Thread Safe ResourceHandle  (0) 2010.12.18