Click here to Skip to main content
12,239,997 members (66,522 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads

Stats

55.9K views
1.4K downloads
35 bookmarked
Posted

PostgreSQL/libpqxx Class Generator

, 18 Aug 2006
Automated generation of PostgreSQL data transfer classes.
#pragma once

/***************************************************************************
 stdafx.h  -  Standard precompiled header file. Things to observe are:
              (a) The definition of _WTL_NO_WTYPES and _WTL_NO_CSTRING.
			      These prevent confusion with the ATL and WTL types.
			  (b) The order of inclusions, particularly where atlstr.h is
			      included with respect to atlapp.h and atltypes.h.
			  (c) I've included PWinDataExchange.h which is my own
			      extended version of the DDX handling. In particular, it
				  implements DDX_Text for CURRENCY and COleDate time. It
				  also contains IMPLEMENT_COMBOTEXTEXCH which is a macro
				  that implements text exchange for combo boxes.
			  (d) The inclusion of <pqxx/pqxx> includes all the standard
			      headers for dealing with the libpqxx functionality.
			  (e) The Singleton template is included at the end. I lifted
			      this from someone ... I wish I could remember who!
		      (f) libpqxx doesn't like the min and max macros. These
			      need to be replaced by a couple of inline template
				  functions.

 begin     : December 2004
 copyright : (C) 2004-2006 by Phil Cairns
 email     : oti169@hotmail.com
 $Id: stdafx.h 2080 2006-08-18 01:53:19Z phil $

 This code may be used in compiled form in any way you desire (including
 commercial use). The code may be redistributed unmodified by any means
 providing it is not sold for profit without the authors written consent,
 and providing that this notice and the authors name and all copyright
 notices remains intact.

 This software is provided "as is" without express or implied warranty. Use
 it at your own risk!
 ***************************************************************************/

// Change these values to use different versions
#define WINVER			0x0500
#define _WIN32_WINNT	0x0501
#define _WIN32_IE		0x0501
#define _RICHEDIT_VER	0x0100

// This is for the silly conflict between libpqxx and MSVC
#define NOMINMAX
template <typename T> T max(T a, T b) { return (a > b) ? a : b; }
template <typename T> T min(T a, T b) { return (a < b) ? a : b; }

#define WIN32_LEAN_AND_MEAN

#define _WTL_NO_WTYPES
#define _WTL_NO_CSTRING

#include <atlbase.h>
#include <atlstr.h>
#include <atlapp.h>

extern CAppModule _Module;

#include <shellapi.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atldlgs.h>
#include <atlddx.h>
#include <atlctrls.h>
#include <atlctrlx.h>
#include <atlcomtime.h>
#include <atltheme.h>

#include "PWinDataExchange.h"	// extended DDX handling

#include <pqxx/pqxx>

template <typename TYPE> 
class Singleton
{
public:
	/// Global access point to the Singleton.
	static TYPE& instance(void)
	{
		Singleton<TYPE>& singleton = Singleton<TYPE>::instance_i();

		if (singleton._instance == 0)
		{
			singleton._instance = new TYPE;
		}

		return *singleton._instance;
	}

	/// Explicitly delete the Singleton instance.
	static void close(void)
	{
		Singleton<TYPE>& singleton = Singleton<TYPE>::instance_i();
		if (singleton._instance) 
		{
			delete singleton._instance;
		}
	}

protected:
	/// Contained instance.
	TYPE* _instance;

	/// Get pointer to the Singleton instance.
	static Singleton<TYPE> &instance_i (void)
	{
		static Singleton<TYPE> _singleton;
		return _singleton;
	}
};

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

_oti
Australia Australia
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 18 Aug 2006
Article Copyright 2005 by _oti
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid