Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

PostgreSQL/libpqxx Class Generator

, 18 Aug 2006
Automated generation of PostgreSQL data transfer classes.
#ifndef __ATLCURR_H__
#define __ATLCURR_H__

#pragma once

namespace ATL
{

class COleCurrency
{
	// Constructors
public:
	COleCurrency();

	COleCurrency(CURRENCY cySrc);
	COleCurrency(const COleCurrency& curSrc);
	COleCurrency(const VARIANT& varSrc);
	COleCurrency(long nUnits, long nFractionalUnits);

	// Attributes
public:
	enum CurrencyStatus
	{
		valid = 0,
		invalid = 1,    // Invalid currency (overflow, div 0, etc.)
		null = 2,       // Literally has no value
	};

	CURRENCY m_cur;
	CurrencyStatus m_status;
	static const COleCurrency zero;

	void SetStatus(CurrencyStatus status);
	CurrencyStatus GetStatus() const;

	// Operations
public:
	const COleCurrency& operator=(CURRENCY cySrc);
	const COleCurrency& operator=(const COleCurrency& curSrc);
	const COleCurrency& operator=(const VARIANT& varSrc);

	BOOL operator==(const COleCurrency& cur) const;
	BOOL operator!=(const COleCurrency& cur) const;
	BOOL operator<(const COleCurrency& cur) const;
	BOOL operator>(const COleCurrency& cur) const;
	BOOL operator<=(const COleCurrency& cur) const;
	BOOL operator>=(const COleCurrency& cur) const;

	// Currency math
	COleCurrency operator+(const COleCurrency& cur) const;
	COleCurrency operator-(const COleCurrency& cur) const;
	const COleCurrency& operator+=(const COleCurrency& cur);
	const COleCurrency& operator-=(const COleCurrency& cur);
	COleCurrency operator-() const;

	COleCurrency operator*(long nOperand) const;
	COleCurrency operator/(long nOperand) const;
	const COleCurrency& operator*=(long nOperand);
	const COleCurrency& operator/=(long nOperand);

	operator CURRENCY() const;

	// Currency definition
	void SetCurrency(long nUnits, long nFractionalUnits);
	BOOL ParseCurrency(LPCTSTR lpszCurrency, DWORD dwFlags = 0,
		LCID = LANG_USER_DEFAULT);

	// formatting
	CString Format(DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT) const;
	CString Format(LPCTSTR lpszMask) const;
};
inline COleCurrency::COleCurrency()
{
	m_cur.Hi = 0;
	m_cur.Lo = 0; 
	SetStatus(valid);
}
inline COleCurrency::COleCurrency(CURRENCY cySrc)
{
	m_cur = cySrc;
	SetStatus(valid);
}
inline COleCurrency::COleCurrency(const COleCurrency& curSrc)
{
	m_cur = curSrc.m_cur;
	m_status = curSrc.m_status;
}
inline COleCurrency::COleCurrency(const VARIANT& varSrc)
{
	*this = varSrc;
}
inline COleCurrency::CurrencyStatus COleCurrency::GetStatus() const
{
	return m_status;
}
inline void COleCurrency::SetStatus(CurrencyStatus status)
{
	m_status = status;
}
inline const COleCurrency& COleCurrency::operator+=(const COleCurrency& cur)
{
	*this = *this + cur;
	return *this;
}
inline const COleCurrency& COleCurrency::operator-=(const COleCurrency& cur)
{
	*this = *this - cur;
	return *this;
}
inline const COleCurrency& COleCurrency::operator*=(long nOperand)
{
	*this = *this * nOperand;
	return *this;
}
inline const COleCurrency& COleCurrency::operator/=(long nOperand)
{
	*this = *this / nOperand;
	return *this;
}
inline BOOL COleCurrency::operator==(const COleCurrency& cur) const
{
	return (m_status == cur.m_status
		&& m_cur.Hi == cur.m_cur.Hi
		&& m_cur.Lo == cur.m_cur.Lo);
}
inline BOOL COleCurrency::operator!=(const COleCurrency& cur) const
{
	return(m_status != cur.m_status
		|| m_cur.Hi != cur.m_cur.Hi
		|| m_cur.Lo != cur.m_cur.Lo);
}
inline COleCurrency::operator CURRENCY() const
{
	return m_cur;
}

}	// namespace ATL

#endif // __ATLCURR_H__

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

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