// CAtlBaseGenerator.h
//

#if !defined(_CATLBASEGENERATOR_H_)
#define _CATLBASEGENERATOR_H_

#include "cmString.h"
#include <map>
#include <vector>
#include "enums.h"

class CXmlClassInfo;
class CXmlProjectSettings;
class CXmlProjectSettings_Atl;
class CXmlBaseFormItem;
class CXmlBaseElement;
class CXmlProject;

using namespace std;

class CAtlBaseGenerator
{
public:
	CAtlBaseGenerator();
	virtual ~CAtlBaseGenerator();

	// properties
	//
	void SetClassInfo(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack);
	void SetProject(CXmlProject* project);

protected:
	
	// utils
	//
	virtual cmString DefineOf(const cmString& className);
	virtual cmString TypeOf(enDataType dataType);
	virtual cmString OleTypeOf(enDataType dataType);
	virtual cmString IdlTypeOf(enDataType dataType);
	virtual cmString GetClassName(const cmString& elementName = _T(""));
	virtual cmString ToLowCase(const cmString& s);
	virtual cmString ToUpperCase(const cmString& s);
	virtual cmString GetCamelCase(const cmString& s);
	virtual cmString GetGenerationTimeStamp();
	virtual cmString GetControlId(CXmlBaseFormItem* formItem, CXmlClassInfo* classInfo);
	virtual cmString GetDialogId(CXmlClassInfo* classInfo, int count);
	virtual cmString GetResourceFileName();
	virtual cmString GetDlgName(CXmlClassInfo* classInfo = NULL);
	virtual cmString GetTreeControlID();
	virtual cmString GetCardinalityPostfix(CXmlBaseElement* element);
	virtual cmString BuildGeneratedSourcePath();
	virtual cmString EscapeString(const cmString& str);
	virtual cmString GetArrayDialogName(CXmlClassInfo* classInfo = NULL);
	virtual cmString GetMapDialogName(CXmlClassInfo* classInfo = NULL);
	virtual cmString GetMainDlgName();
	virtual cmString GetParentPath(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack, bool addContainers = true);

	bool SaveFile(const cmString& fileName, const cmString& fileContent, bool saveIfDifferent = true);
	bool ExistingFileHasSameContent(const cmString& fileName, const cmString& fileContent);
	cmString GetCodeFromFileContent(const string& fileContent);

protected:
	
	// class info
	//
	CXmlClassInfo* classInfo_;
	CXmlClassInfo* rootClassInfo_;
	CXmlProjectSettings* projectSettings_;
	CXmlProjectSettings_Atl* atlSettings_;
	CXmlProject* project_;
	static map<cmString, cmString> cppGeneratedFiles_;
	static map<cmString, cmString> hGeneratedFiles_;
	vector<CXmlClassInfo*> parentStack_;
};

#endif // !defined(_CATLBASEGENERATOR_H_)