// CAtlGenerationManager.h
//

#if !defined(_ATLGENERATIONMANAGER_H_)
#define _ATLGENERATIONMANAGER_H_

//#include <string>
#include <set>
#include "AtlBaseGenerator.h"
#include "cmString.h"

using namespace std;

class CXmlProject;
class CXmlClassInfo;
class CXmlProjectSettings;
class IGeneratorListener;
class CXmlProjectPostGen;

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

public:
	void RegisterListener(IGeneratorListener* listener);

	virtual bool Generate(const cmString& currentDirectory, CXmlProject* project);
	cmString GetCurDirectory();

	void RunCompiler();
	void RunTestProject();

protected:
	void GenerateClass(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack);
	void GenerateComClass(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack);
	void GenerateClassContainer(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack);
	void GenerateGuiClass(CXmlClassInfo* classInfo, vector<CXmlClassInfo*> parentStack);
	void GenerateGuiManager();
	void GenerateGuiResources();
	void GenerateGuiTreeNodeInfo();
	void GenerateIdl(CXmlClassInfo* rootClassInfo);
	void GenerateIdlForwardDeclaration(CXmlClassInfo* classInfo);
	void GenerateClassIdl(CXmlClassInfo* rootClassInfo);
	void GenerateMainDialogIdl();
	void GenerateClassRgsFile(CXmlClassInfo* classinfo);
	void GenerateRgsFile(const cmString& progId, const cmString& className, const cmString& guid);
	void GenerateMainDialogRgsFile();
	void GenerateMainModuleFile();
	void CreateFolders(CXmlProjectSettings* projectSettings);
	void CopyFiles();
	void CopySingleFile(const cmString& source, const cmString& destination = _T(""));
	void CopyComponentsFiles();
	void CopyDllProjectFiles();
	void GenerateCppFileList();
	void GenerateDllBatch();
	void CopyHeaders();

	cmString GetTypeLibraryGuid();
	cmString GetInterfaceGuid(CXmlClassInfo* classInfo);
	cmString GetClassGuid(CXmlClassInfo* classInfo);
	cmString CreateGuid();
	void GenerateClassResource(cmString& code, int& index, CXmlClassInfo* classInfo);
	void GenerateResourceHFile();
	void GenerateObjectMapEntry(CXmlClassInfo* classInfo, cmString& code);
	void CopyDirectory(cmString sourcePath, cmString destinationPath);
	void GenerateCppComponentsFile();
	void BuildComponentFileList(const cmString& pathName, const cmString& destinationPathName, map<cmString, cmString>& fileList);
	void GetDirectoryFiles(cmString pathName, const cmString& pattern, vector<cmString>& fileList);
	void GeneratePostBuildFile(const cmString& fileName, const cmString& sourceFolder, const cmString& filePostfix);
	void GenerateDefFiles();
	void GenerateTestProject();

	CXmlProject* project_;
	cmString currentDirectory_;
	cmString interfaceCode_;
	cmString idlEnumsCode_;
	cmString coclassCode_;
	IGeneratorListener* listener_;

	bool buildDebug_;
	bool buildRelease_;

	set<cmString> enums_;
};

#endif //!defined(_ATLGENERATIONMANAGER_H_)