基于单例模式的配置文件读取方法

TDOptions.h

#pragma once
/**
 * \class CTDOptions TDOptions.h
 * \brief mamage options in TenderShower project
 */
class CTDOptions
{
private:
    CTDOptions(void);
    ~CTDOptions(void);

public:
    static CTDOptions * GetInstance();
//    static void ReleaseInstance();

public:
    //THIDNormFaceGeoFormat* GetFaceGeoFormat();

    bool LoadSystemConfig();
    void SaveSystemConfig();
    //////////////////////////////////////////////
    inline CString GetDBLastUpateTime()  const
    {
        return m_strLastUpdataTime;
    }

    inline int GetDBMaxIndex() const
    {
        return m_nMaxDBIndex;
    }

    void SetDBLastUpdateTime( CString strUpdateTime);
    void SetFPNum(int nFPNum);

private:

    TCHAR  m_pPathName[MAX_PATH];

    CString             m_strLastUpdataTime;
    int                 m_nMaxDBIndex;
};

#define TDGI CTDOptions::GetInstance()

TDOptions.cpp

#include "stdafx.h"
#include "TDOptions.h"

//CTDOptions* CTDOptions::m_pSingleInstance = NULL;

CTDOptions::CTDOptions(void)
{
   // m_nFeatureSize = THIDGetFaceFeatureSize();
    memcpy(m_pPathName, g_strModelPath,MAX_PATH*sizeof(TCHAR));
    ::PathAppend(m_pPathName, _T("RegistVerySyConfig.ini"));
}

CTDOptions::~CTDOptions(void)
{


}

CTDOptions * CTDOptions::GetInstance()
{
    static CTDOptions stance;
    return &stance;
}

bool CTDOptions::LoadSystemConfig()
{

    if (!PathFileExists(m_pPathName))
    {
        return false;
    }
    TCHAR szTempBuffer[100] = {0};

    GetPrivateProfileString(_T("DBParam"),_T("LastUpateTime"),
        _T("2015-09-01 12:00:00"), szTempBuffer,100,  m_pPathName);
    m_strLastUpdataTime=  szTempBuffer;

    m_nMaxDBIndex= GetPrivateProfileInt(_T("DBParam"), _T("MaxIndex"), 0, m_pPathName );

    return true;

}

void CTDOptions::SetDBLastUpdateTime(CString strUpdateTime)
{
    WritePrivateProfileString(_T("DBParam"),
        _T("LastUpateTime"), strUpdateTime, m_pPathName);


}
void CTDOptions::SetFPNum(int nFPNum)
{
    // 将其值写入配置文件中
    CString strTemp;
    strTemp.Format(_T("%d"), nFPNum);
    WritePrivateProfileString(_T("LocalDBNum"),
        _T("FPNum"), strTemp, m_pPathName);

}

RegistVerySyConfig.ini

# 0 1 2 3 4 5 6 7 8 9
[DBParam]
#注释1
LastUpateTime=1
#注释2
MaxIndex=0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值