Skip to content

Commit 0459f05

Browse files
committed
重构:
1.重构一个高性能多线程日志模块, 参见 ftlLog.h 和 CFLogTest.ini(通过 CFLogTest.ini 分析 LogViewer 的日志); 2.增加 源码目录历史对话框, 方便同时存在多个源码目录时; 3.更改 SeqNumber 为 Line Num(日志中的行号, 可以 Goto) 和 Seq(唯一递增序号,可以检查日志是否有丢失或反序) 4.在 Sort/Filter 时尽量保持当前选中日志; 5.增强选择日志记录后的右键拷贝功能; 6.更改一些bug;
1 parent 6972c5f commit 0459f05

39 files changed

+3746
-1924
lines changed

FTL/ftlBase.h

Lines changed: 98 additions & 397 deletions
Large diffs are not rendered by default.

FTL/ftlBase.hpp

Lines changed: 337 additions & 1200 deletions
Large diffs are not rendered by default.

FTL/ftlConversion.h

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
#pragma once
55

6-
#ifndef FTL_BASE_H
7-
# error ftlConversion.h requires ftlbase.h to be included first
8-
#endif
6+
#include "ftlDefine.h"
97

108
/************************************************************************************************************
119
* CodePage -- 代码页,是Windows为不同的字符编码方案所分配的一个数字编号。
@@ -36,6 +34,114 @@
3634

3735
namespace FTL
3836
{
37+
#ifndef DEFAULT_MEMALLOCATOR_FIXED_COUNT
38+
#define DEFAULT_MEMALLOCATOR_FIXED_COUNT 32
39+
#endif
40+
41+
//! 方便的管理需要分配的临时内存,在类的构造中分配内存,析构中释放
42+
//! 是否可能生成小的内存碎片?使用Pool优化?
43+
enum MemoryAllocType
44+
{
45+
matNew, //使用new分配,使用delete释放,为了方便管理,即使只分配一个,也使用数组方式
46+
matVirtualAlloc, //使用VirtualAlloc直接在进程的地址空间中保留一快内存(既非堆又非栈),速度快
47+
matLocalAlloc, //使用LocalAlloc分配,LocalFree释放,主要是为了兼容老的程序?
48+
//matMalloca, //使用 _malloca 在栈上分配,通过 _freea 释放
49+
};
50+
51+
template <typename T, UINT DefaultFixedCount = DEFAULT_MEMALLOCATOR_FIXED_COUNT, MemoryAllocType allocType = matNew>
52+
class CFMemAllocator
53+
{
54+
//和ATL中的 CTempBuffer 模板类比较
55+
DISABLE_COPY_AND_ASSIGNMENT(CFMemAllocator);
56+
public:
57+
FTLINLINE CFMemAllocator();
58+
FTLINLINE CFMemAllocator(DWORD nCount, BOOL bAlignment = FALSE);
59+
FTLINLINE ~CFMemAllocator();
60+
FTLINLINE T* GetMemory(UINT nMaxSize);
61+
FTLINLINE T* GetMemory();
62+
FTLINLINE operator T*()
63+
{
64+
if (!m_pMem && m_nCount <= DefaultFixedCount)
65+
{
66+
return m_FixedMem;
67+
}
68+
return m_pMem;
69+
}
70+
71+
FTLINLINE T* Detatch();
72+
FTLINLINE UINT GetCount() const;
73+
protected:
74+
FTLINLINE VOID _Init(DWORD nCount, BOOL bAlignment);
75+
FTLINLINE UINT _AdjustAlignmentSize(UINT nCount);
76+
FTLINLINE VOID _FreeMemory();
77+
FTLINLINE UINT _GetBlockSize(UINT nMaxCount);
78+
private:
79+
T* m_pMem;
80+
T m_FixedMem[DefaultFixedCount];
81+
MemoryAllocType m_allocType;
82+
UINT m_nCount;
83+
BOOL m_bAlignment;
84+
};
85+
86+
//! 字符串格式化,可以根据传入的格式化字符长度自动调整,析构时释放分配的内存
87+
class CFStringFormater
88+
{
89+
DISABLE_COPY_AND_ASSIGNMENT(CFStringFormater);
90+
public:
91+
//可以分配的最大内存空间为 : dwInitAllocLength * dwMaxBufferTimes(注意:dwMaxBufferTimes 最好是2的倍数)
92+
FTLINLINE CFStringFormater(DWORD dwMaxBufferLength = MAX_BUFFER_LENGTH);
93+
FTLINLINE virtual ~CFStringFormater();
94+
FTLINLINE BOOL Reset(DWORD dwNewLength = 0);
95+
FTLINLINE VOID Clear(); //清除内容
96+
FTLINLINE HRESULT __cdecl Format(LPCTSTR lpszFormat, ...);
97+
FTLINLINE HRESULT __cdecl FormatV(LPCTSTR lpszFormat, va_list argList);
98+
FTLINLINE HRESULT __cdecl AppendFormat(LPCTSTR lpszFormat, ...);
99+
FTLINLINE HRESULT __cdecl AppendFormatV(LPCTSTR lpszFormat, va_list argList);
100+
101+
//各种支持函数的定义
102+
#if 0
103+
const CFStringFormater& operator=(const CFStringFormater& src);
104+
const CFStringFormater& operator=(const TCHAR ch);
105+
const CFStringFormater& operator=(LPCTSTR pstr);
106+
# ifdef _UNICODE
107+
const CFStringFormater& CFStringFormater::operator=(LPCSTR lpStr);
108+
const CFStringFormater& CFStringFormater::operator+=(LPCSTR lpStr);
109+
# else
110+
const CFStringFormater& CFStringFormater::operator=(LPCWSTR lpwStr);
111+
const CFStringFormater& CFStringFormater::operator+=(LPCWSTR lpwStr);
112+
# endif
113+
CFStringFormater operator+(const CFStringFormater& src) const;
114+
CFStringFormater operator+(LPCTSTR pstr) const;
115+
const CFStringFormater& operator+=(const CFStringFormater& src);
116+
const CFStringFormater& operator+=(LPCTSTR pstr);
117+
const CFStringFormater& operator+=(const TCHAR ch);
118+
TCHAR operator[] (int nIndex) const;
119+
bool operator == (LPCTSTR str) const;
120+
bool operator != (LPCTSTR str) const;
121+
bool operator <= (LPCTSTR str) const;
122+
bool operator < (LPCTSTR str) const;
123+
bool operator >= (LPCTSTR str) const;
124+
bool operator > (LPCTSTR str) const;
125+
#endif
126+
127+
FTLINLINE operator LPCTSTR() const
128+
{
129+
return m_pBuf;
130+
}
131+
FTLINLINE LPCTSTR GetString() const;
132+
FTLINLINE LPTSTR GetString();
133+
FTLINLINE LONG GetStringLength() const;
134+
FTLINLINE LONG GetSize() const;
135+
FTLINLINE LPTSTR Detach();
136+
protected:
137+
TCHAR m_szInitBuf[DEFAULT_BUFFER_LENGTH];
138+
LPTSTR m_pBuf;
139+
DWORD m_dwTotalBufferLength;
140+
const DWORD m_dwMaxBufferLength;
141+
FTLINLINE HRESULT __cdecl _InnerFormatV(LPTSTR pszBuf, DWORD dwBufLength, BOOL bAppend, LPCTSTR lpszFormat, va_list argList);
142+
FTLINLINE VOID _CheckAndReleaseBuf();
143+
};
144+
39145
class CFConversion
40146
{
41147
public:
@@ -85,6 +191,9 @@ namespace FTL
85191
class CFConvUtil
86192
{
87193
public:
194+
//return True or False
195+
FTLINLINE static LPCTSTR GetVariantBoolString(VARIANT_BOOL varBool);
196+
88197
//ex. pb = {255,15} -> sz = {"FF,0F"} -- TODO: AtlHexDecode/AtlHexEncode
89198
FTLINLINE static BOOL HexFromBinary(__in const BYTE* pBufSrc, __in LONG nSrcLen,
90199
__out LPTSTR pBufDest, __inout LONG* pDestCharCount,

0 commit comments

Comments
 (0)