Click here to Skip to main content
15,896,481 members
Articles / Desktop Programming / MFC

The Diffraction Grating Calculator

Rate me:
Please Sign up or sign in to vote.
4.40/5 (5 votes)
30 Oct 2010GPL38 min read 41.5K   678   6  
An MFC Windows program related to Concave Diffraction Gratings using VTK libraries.
// SingleLogger.h: interface for the singleton CSingleLogger class.
//
//////////////////////////////////////////////////////////////////////

#ifndef SINGLELOGGER_H
#define SINGLELOGGER_H

/* disable MSVC warnings about STL in debug mode */
#if _MSC_VER > 1000
#pragma warning (disable: 4786)
#pragma warning (disable: 4748)
#pragma warning (disable: 4103)
#endif /* _MSC_VER > 1000 */

#include "TraceLevels.h"
#include "TGuard.h"
#include "MSMutex.h"
#include "NullMutex.h"

#define LOCK_SYNC_NAME _T("TheTracingMutex")
/* System wide default global Sync Object (e.g. Mutex) name */

class CSingleLogger /* this class is a (Meyer) Singleton! */
{
public:
	static CSingleLogger* GetInstance();
	static bool IsCSingleLoggerEnabled;
	void Trace(unsigned short nTraceLevel, const TCHAR * pszFormat, ...);
	// The client MUST set parameters before using the logger, but we just
	// use defaults otherwise.
	void EnableTracing(bool bEnable);
	void SetParameters(unsigned long nTimeOut, const TCHAR* sFileName, int nTraceLvl);
	bool AreParametersSet(void);
	void LoadDefaults();
	void CheckAndSetTraceFileName(const TCHAR *sFileName);

private:
	CSingleLogger();
	~CSingleLogger();

	static CSingleLogger* SingleInstance; /* this class is a Singleton! */

	unsigned long CheckLockTimeOut(unsigned long nTimeOut);
	int           CheckTraceLevel(int nTraceLvl);

	bool          DiscriminateLevel(int nTraceLevel);

	CString m_szTraceFileName;
	unsigned long m_nLockTimeOut;
	int m_nTraceLevel;

	bool m_bAreParametersSet;

/* Strategized Scoped Locking pattern (equivalent to MFC CSingleLock) */
/* Note: DO use a mutex for the LOCK object */
// Lock object used for sync access to shared logger
#ifdef _WIN32
	CMSMutex* m_aLock;
#else
	CNullMutex* m_aLock;
#endif
};

#endif /* ! defined SINGLELOGGER_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, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Italy Italy
Senior Software Developer in C/C++ and Oracle.
Ex-physicist holding a Ph.D. on x-ray lasers.

Comments and Discussions