Click here to Skip to main content
11,437,713 members (50,614 online)
Click here to Skip to main content
Add your own
alternative version

WTL Helper

, 27 Aug 2007
Add-in for Microsoft VC++.NET 2003 that helps to insert message handlers for WTL.
wtlhelper.zip
WTLHelper.exe
wtlhelper_exe.zip
WTLHelper.exe
wtlhelper_src.zip
source
AddIn.def
Dialog
vssver.scc
Options
res
a1.ico
AddIn.rgs
addin8.rgs
closefld.ico
Clsdfold.ico
DDX.bmp
dialog.bmp
functoolbar.bmp
icons.bmp
message.ico
msg.bmp
mysmall4.bmp
openfld.ico
Openfold.ico
option.bmp
vartoolbar.bmp
vssver.scc
wizard.bmp
Wizard.ico
WtlHelper.dll.manifest
resources
Setup.nsi
WtlHelperRes
res
DDX.bmp
dialog.bmp
msg.bmp
option.bmp
reflect.bmp
wizard.bmp
WtlHelperRes.aps
WtlHelperRes8.vcproj.MINSK.solozhentsev.user
#pragma	  once

class CStdSaveLoad
{
public:
	template<typename Storage, typename ObjectClass>
	inline static bool SaveVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		return Archive.SaveVariable(lpName, object);
	}

	template<typename Storage, typename ObjectClass>
	inline static bool LoadVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		return Archive.LoadVariable(lpName, object);
	}
};

class CObjectSaveLoad
{
public:
	template<typename Storage, typename ObjectClass>
	inline static bool SaveVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		return object.SaveSettings(Archive, lpName);
	}

	template<typename Storage, typename ObjectClass>
	inline static bool LoadVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		return object.LoadSettings(Archive, lpName);
	}
};

class CPObjectSaveLoad
{
public:
	template<typename Storage, typename ObjectClass>
	inline static bool SaveVariable(LPCTSTR lpName, Storage& Archive, ObjectClass* pObject)
	{
		return pObject->SaveSettings(Archive, lpName);
	}

	template<typename Storage, typename ObjectClass>
	inline static bool LoadVariable(LPCTSTR lpName, Storage& Archive, ObjectClass*& pObject)
	{
		pObject = new ObjectClass;
		if (!pObject->LoadSettings(Archive, lpName))
		{
			delete pObject;
			pObject = NULL;
			return false;
		}
		return true;
	}
};

template<typename BaseClass, typename SaveLoadClass = CStdSaveLoad>
class CArraySerializer
{
public:
	template<typename Storage, typename ObjectClass>
	static bool SaveVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		if (!Archive.StartObject(lpName))
			return false;

		size_t Count = BaseClass::GetCount(object);
		for (size_t i = 0; i < Count; i++)
		{
			TCHAR buf[512];
			wsprintf(buf, _T("Item%d"), i);
			if (!SaveLoadClass::SaveVariable(buf, Archive, object[i]))
			{
				Archive.EndObject();
				return false;
			}
		}
		Archive.EndObject();
		return true;
	}

	template<typename Storage, typename ObjectClass>
	static bool LoadVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		if (!Archive.StartObject(lpName))
			return false;

		int i = 0;
		while(true)
		{
			TCHAR buf[512];
			wsprintf(buf, _T("Item%d"), i);
			typename BaseClass::ElementType Var;
			if (!SaveLoadClass::LoadVariable(buf, Archive, Var))
			{
				break;
			}
			BaseClass::Add(object, Var);
			i++;
		}
		Archive.EndObject();
		return true;
	}
};

template <typename T, typename SaveLoadClass = CStdSaveLoad>
class CAtlArraySerializerCustom : public CArraySerializer<CAtlArraySerializerCustom<T, SaveLoadClass>, SaveLoadClass >
{
public:
	typedef T ElementType;
	inline static size_t GetCount(const CAtlArray<T>& object)
	{
		return object.GetCount();
	}
	inline static void Add(CAtlArray<T>& object, T var)
	{
		object.Add(var);
	}
};

template<typename T>
class CAtlArraySerializer : public CAtlArraySerializerCustom<T, CStdSaveLoad>
{

};

template<typename T>
class CAtlArrayObjectSerializer : public CAtlArraySerializerCustom<T, CObjectSaveLoad> {};

template<typename T>
class CAtlArrayPObjectSerializer : public CAtlArraySerializerCustom<T*, CPObjectSaveLoad> {};


template <typename T, typename SaveLoadClass = CStdSaveLoad>
class CSimpleArraySerializerCustom : public CArraySerializer<CSimpleArraySerializerCustom<T, SaveLoadClass>, SaveLoadClass >
{
public:
	typedef T ElementType;
	template <typename ArrayClass>
	inline static size_t GetCount(const ArrayClass& object)
	{
		return object.GetSize();
	}

	template <typename ArrayClass>
	inline static void Add(ArrayClass& object, T var)
	{
		object.Add(var);
	}
};

template <typename T>
class CSimpleArraySerializer : public CSimpleArraySerializerCustom<T, CStdSaveLoad>{};

template <typename T>
class CSimpleArrayObjectSerializer : public CSimpleArraySerializerCustom<T, CObjectSaveLoad>{};

template <typename T>
class CSimpleArrayPObjectSerializer : public CSimpleArraySerializerCustom<T*, CPObjectSaveLoad>{};

// Use for vector, list, deque
template <typename T, typename SaveLoadClass = CStdSaveLoad>
class CSTLSerializerCustom
{
public:
	template<typename Storage, typename ObjectClass>
	static bool SaveVariable(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		if (!Archive.StartObject(lpName))
			return false;

		int n = 0;
		for (ObjectClass::iterator i = object.begin(); i != object.end(); i++, n++)
		{
			TCHAR buf[512];
			wsprintf(buf, _T("Item%d"), n);
			if (SaveLoadClass::SaveVariable(buf, Archive, (*i)))
			{
				Archive.EndObject();
				return false;
			}
		}
		Archive.EndObject();
		return true;
	}

	template<typename Storage, typename ObjectClass>
	static bool LoadVariables(LPCTSTR lpName, Storage& Archive, ObjectClass& object)
	{
		if (!Archive.StartObject(lpName))
			return false;

		int i = 0;
		while(true)
		{
			TCHAR buf[512];
			wsprintf(buf, _T("Item%d"), i);
			typename T Var;
			if (!SaveLoadClass::LoadVariable(buf, Archive, Var))
			{
				break;
			}
			object.push_back(Var);
			
			i++;
		}
		Archive.EndObject();
		return true;
	}
};

template <typename T>
class CSTLSerializer : public CSTLSerializerCustom<T, CStdSaveLoad>{};

template <typename T>
class CSTLObjectSerializer : public CSTLSerializerCustom<T, CObjectSaveLoad>{};

template <typename T>
class CSTLPObjectSerializer : public CSTLSerializerCustom<T*, CPObjectSaveLoad>{};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sergey Solozhentsev
Web Developer
Belarus Belarus
I am a software developer for 3 years.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150506.1 | Last Updated 27 Aug 2007
Article Copyright 2004 by Sergey Solozhentsev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid