﻿#if !defined(AFX_PROFILE_H__C7413254_23F4_4782_A100_A6C97A1A0297__INCLUDED_)
#define AFX_PROFILE_H__C7413254_23F4_4782_A100_A6C97A1A0297__INCLUDED_
#pragma once
#include "Forcelib.h"
#include <string>
#include <map>
#include "StringTools.h"
/*
class CField :
	public CObject 
{
private:
	std::wstring m_sEntry;
	std::wstring m_sValue;
public:
	std::wstring Entry() const	{return m_sEntry;};
	std::wstring Value() const	{return m_sValue;};
	CField(std::wstring sEntry,std::wstring sValue):
	m_sEntry(sEntry),m_sValue(sValue){;}
	CField(void);
	~CField(void);
};
*/
class CSection;
typedef std::map<std::wstring, std::wstring> FieldType;
typedef  std::map<std::wstring, CSection*>   SectionType;
class CSection 
{
private:

	FieldType				m_pcField;
	std::wstring m_sSection;
public:
	CSection(const std::wstring& sSection):m_sSection(sSection) {;};
	BOOL AddField( const std::wstring& sEntry,const std::wstring& sValue)	
	{

		m_pcField[sEntry]=sValue;
		return true;
	}
	FieldType&   GetField(){
		return m_pcField;
	}
	std::wstring GetSectionName() const	{return m_sSection;}

	CSection(void);
	~CSection(void);
};
class CProFile
{
private:
	int m_iIndexOfSection;
	void WirteLine(std::wstring sLine);
	void Analysis(std::wstring sLine);
	int  nOutInFlg;
	int Open(const wchar_t* lpszFileName);
public:
	CSection *   m_pSection;
	wchar_t        m_Ch;
	SectionType	m_apSection;
	int		     m_iFileType;	
	std::wstring m_FileName;
public:
	std::wstring GetValue(std::wstring& sSection,std::wstring& sEntry) ;
	void SelectSection(const std::wstring& sSection);

	void Clear();
	void SetDivChar(wchar_t ch=L'='){
		m_Ch=ch;
	}
	BOOL AddSection(const std::wstring& sSection)	
	{
		std::map<std::wstring, CSection*>::iterator it = m_apSection.find(sSection);
		if (it == m_apSection.end()) { 
			CSection* pKey = new CSection(sSection);
			if (pKey != NULL) {
				m_apSection[sSection]=pKey;
				m_pSection=m_apSection[sSection];
				return true;
			}
		}
		return false;
	}
	BOOL OpenForRead(const wchar_t* lpszFileName);
	BOOL OpenForWrite(const wchar_t* lpszFileName);
	BOOL test();
	CProFile(void);
	~CProFile(void);
};

#endif // !defined(AFX_PROFILE_H__C7413254_23F4_4782_A100_A6C97A1A0297__INCLUDED_)
