Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

LintProject - Improving the Usability of PC-Lint with Visual C++ Solutions and Projects

, , 29 Jan 2009
Utility to run PC-Lint on Visual C++ solutions and projects, generating XML and HTML reports of the results.
/************************************************************************
 *
 *  Description : CProjectConfiguration - class to represent a project
 *                configuration.
 *
 *     (c) Copyright 1996-2008 by Anna-Jayne Metcalfe (anna@riverblade.co.uk)
 *     and Beth Mackenzie (beth@riverblade.co.uk) / Riverblade Limited
 *
 *  Licence Terms:
 *
 *     This code may be freely reused, subject to the licence terms below.
 *     Please do let us know of any bugs you find or improvements you make,
 *     so that we can pass them on to the rest of the development community.
 *
 *     This code is free software; you can redistribute it and/or
 *     modify it under the terms of the Code Project Open License (CPOL)
 *     version 1.0 (http://www.codeproject.com/info/cpol10.aspx).
 *
 *     This code is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     Code Project Open Licence for further details.
 *
 ************************************************************************
 *    $Archive: /Projects/AddIns/Visual Lint/Development/Libraries/AddInSolutionModel/src/ProjectConfiguration.cpp $
 *   $Revision: 4 $
 *       $Date: 15/04/08 12:10 $
 *     $Author: Anna $
 * 
 * $Nokeywords: $
 ************************************************************************/

/// \file	
/// \brief CProjectConfiguration implementation.

//lint -esym(749, *::ConfigurationTypes::*, *::useOfMfc::*, *::useOfATL::*, *::charSet::*)	 (Information -- local enumeration constant not referenced)

#include "StdAfx.h"

#include "ProjectConfiguration.h"


namespace Riverblade
{
	namespace Libraries
	{
		namespace AddInSolutionModel
		{

			////////////////////////////////////////////////////////////////////////////////
			// CFileConfiguration

			/// \brief Default constructor
			///
			CFileConfiguration::CFileConfiguration(void)
				:	m_sPreprocessorDefinitions( _T("") ),
					m_sAdditionalIncludeDirectories( _T("") ),
					m_sAdditionalCommandLineOptions(_T("") )
			{
			}


			/// \brief Copy constructor
			///
			///	\param	src			The source object to copy from.
			///
			CFileConfiguration::CFileConfiguration(const CFileConfiguration& src)
				:	m_sPreprocessorDefinitions(src.m_sPreprocessorDefinitions),
					m_sAdditionalIncludeDirectories(src.m_sAdditionalIncludeDirectories),
					m_sAdditionalCommandLineOptions(src.m_sAdditionalCommandLineOptions)
			{
			}


			/// \brief Class destructor
			///
			CFileConfiguration::~CFileConfiguration(void)
			{
			}


			/// \brief Assignment operator
			///
			///	\param	src			The source object to copy from.
			///	\return				A reference to this object.
			///
			CFileConfiguration& CFileConfiguration::operator=(const CFileConfiguration& src)
			{
				if (&src != this)
				{
					m_sPreprocessorDefinitions			= src.m_sPreprocessorDefinitions;
					m_sAdditionalIncludeDirectories		= src.m_sAdditionalIncludeDirectories;
					m_sAdditionalCommandLineOptions		= src.m_sAdditionalCommandLineOptions;
				}
				return *this;
			}


			/// \brief Equality operator
			///
			///	\param	src			The source object to compare against.
			///	\return				\em true if the two objects are equivalent; \em false otherwise.
			///
			bool CFileConfiguration::operator==(const CFileConfiguration& src) const
			{
				return ( (m_sPreprocessorDefinitions		== src.m_sPreprocessorDefinitions) &&
						 (m_sAdditionalIncludeDirectories	== src.m_sAdditionalIncludeDirectories) &&
						 (m_sAdditionalCommandLineOptions	== src.m_sAdditionalCommandLineOptions) );
			}


			bool CFileConfiguration::IsEmpty(void) const
			{
				if (m_sAdditionalIncludeDirectories.IsEmpty() && 
					m_sPreprocessorDefinitions.IsEmpty() &&
					m_sAdditionalCommandLineOptions.IsEmpty() )
				{
					return true;
				}
				return false;
			}


			////////////////////////////////////////////////////////////////////////////////
			// CProjectConfiguration

			/// \brief Default constructor
			///
			CProjectConfiguration::CProjectConfiguration(void)
				:	m_sName(_T("") ),
					m_sIntermediateFolder( _T("") ),
					m_eConfigurationType(typeUnknown),
					m_eCharacterSet(charSetNotSet),
					m_bMinimiseRTL(false),
					m_eUseOfMfc(useMfcStdWin),
					m_eUseOfAtl(useATLNotSet),
					m_sPreprocessorDefinitions( _T("") ),
					m_sAdditionalIncludeDirectories( _T("") ),
					m_eRuntimeLibrary(-1),
					m_bEnableRuntimeTypeInfo(false),
					m_bForceConformanceInForLoopScope(false),
					m_bNativeWideChars(false),
					m_sAdditionalCommandLineOptions(_T("") ),
					m_mapPerFileConfiguration()
			{
			}


			/// \brief Copy constructor
			///
			///	\param	src			The source object to copy from.
			///
			CProjectConfiguration::CProjectConfiguration(const CProjectConfiguration& src)
				:	m_sName(src.m_sName),
					m_sIntermediateFolder(src.m_sIntermediateFolder),
					m_eConfigurationType(src.m_eConfigurationType),
					m_eCharacterSet(src.m_eCharacterSet),
					m_bMinimiseRTL(src.m_bMinimiseRTL),
					m_eUseOfMfc(src.m_eUseOfMfc),
					m_eUseOfAtl(src.m_eUseOfAtl),
					m_sPreprocessorDefinitions(src.m_sPreprocessorDefinitions),
					m_sAdditionalIncludeDirectories(src.m_sAdditionalIncludeDirectories),
					m_eRuntimeLibrary(src.m_eRuntimeLibrary),
					m_bEnableRuntimeTypeInfo(src.m_bEnableRuntimeTypeInfo),
					m_bForceConformanceInForLoopScope(src.m_bForceConformanceInForLoopScope),
					m_bNativeWideChars(src.m_bNativeWideChars),
					m_sAdditionalCommandLineOptions(src.m_sAdditionalCommandLineOptions),
					m_mapPerFileConfiguration()
			{
				POSITION pos = src.m_mapPerFileConfiguration.GetStartPosition();
				while (NULL != pos)
				{
					CString sFileName;
					CFileConfiguration config;

					src.m_mapPerFileConfiguration.GetNextAssoc(pos, sFileName, config);

					m_mapPerFileConfiguration[sFileName] = config;
				}
			}


			/// \brief Class destructor
			///
			CProjectConfiguration::~CProjectConfiguration(void)
			{
				m_mapPerFileConfiguration.RemoveAll();
			}


			/// \brief Assignment operator
			///
			///	\param	src			The source object to copy from.
			///	\return				A reference to this object.
			///
			CProjectConfiguration& CProjectConfiguration::operator=(const CProjectConfiguration& src)
			{
				if (&src != this)
				{
					m_sName								= src.m_sName;
					m_sIntermediateFolder				= src.m_sIntermediateFolder;
					m_eConfigurationType				= src.m_eConfigurationType;
					m_eCharacterSet						= src.m_eCharacterSet;
					m_bMinimiseRTL						= src.m_bMinimiseRTL;
					m_eUseOfMfc							= src.m_eUseOfMfc;
					m_eUseOfAtl							= src.m_eUseOfAtl;
					m_sPreprocessorDefinitions			= src.m_sPreprocessorDefinitions;
					m_sAdditionalIncludeDirectories		= src.m_sAdditionalIncludeDirectories;
					m_eRuntimeLibrary					= src.m_eRuntimeLibrary;
					m_bEnableRuntimeTypeInfo			= src.m_bEnableRuntimeTypeInfo;
					m_bForceConformanceInForLoopScope	= src.m_bForceConformanceInForLoopScope;
					m_bNativeWideChars					= src.m_bNativeWideChars;
					m_sAdditionalCommandLineOptions		= src.m_sAdditionalCommandLineOptions;

					m_mapPerFileConfiguration.RemoveAll();

					POSITION pos = src.m_mapPerFileConfiguration.GetStartPosition();
					while (NULL != pos)
					{
						CString sFileName;
						CFileConfiguration config;

						src.m_mapPerFileConfiguration.GetNextAssoc(pos, sFileName, config);

						m_mapPerFileConfiguration[sFileName] = config;
					}
				}
				return *this;
			}


			/// \brief Equality operator
			///
			///	\param	src			The source object to compare against.
			///	\return				\em true if the two objects are equivalent; \em false otherwise.
			///
			bool CProjectConfiguration::operator==(const CProjectConfiguration& src) const
			{
				// TODO: Compare file maps
				return ( (m_sName							== src.m_sName) &&
						(m_sIntermediateFolder				== src.m_sIntermediateFolder) &&
						(m_eConfigurationType				== src.m_eConfigurationType) &&
						(m_eCharacterSet					== src.m_eCharacterSet) &&
						(m_bMinimiseRTL						== src.m_bMinimiseRTL) &&
						(m_eUseOfMfc						== src.m_eUseOfMfc) &&
						(m_eUseOfAtl						== src.m_eUseOfAtl) &&
						(m_sPreprocessorDefinitions			== src.m_sPreprocessorDefinitions) &&
						(m_sAdditionalIncludeDirectories	== src.m_sAdditionalIncludeDirectories) &&
						(m_eRuntimeLibrary					== src.m_eRuntimeLibrary) &&
						(m_bEnableRuntimeTypeInfo			== src.m_bEnableRuntimeTypeInfo) &&
						(m_bForceConformanceInForLoopScope	== src.m_bForceConformanceInForLoopScope) &&
						(m_bNativeWideChars					== src.m_bNativeWideChars) &&
						(m_sAdditionalCommandLineOptions	== src.m_sAdditionalCommandLineOptions) );
			}


			/// \brief Retrieve the additional include folder configuration for the specified file.
			///
			/// Note that if the file does not have a specific per-file configuration, an empty string will
			/// be returned and the project additional include folder configuration should be used instead.
			///
			/// \param	sPathName	The pathname of the file.
			///	\return				A string containing the additional includes for the specified file.
			///
			CString CProjectConfiguration::GetFileAdditionalIncludes(const CString& sPathName) const
			{
				const CFileConfiguration config = GetFileConfiguration(sPathName);

				return config.m_sAdditionalIncludeDirectories;
			}


			/// \brief Set the additional include folder configuration for the specified file.
			///
			/// \param	sPathName					The pathname of the file.
			///	\param	sAdditionalIncludes			A string containing the additional includes for the specified file.
			///	\return								\em true if the includes were set correctly; \em false otherwise.
			///
			bool CProjectConfiguration::SetFileAdditionalIncludes(const CString& sPathName, const CString& sAdditionalIncludes)
			{
				CFileConfiguration config = GetFileConfiguration(sPathName);

				config.m_sAdditionalIncludeDirectories = sAdditionalIncludes;

				return SetFileConfiguration(sPathName, config);
			}


			/// \brief Retrieve the preprocessor definitions for the specified file.
			///
			/// Note that if the file does not have a specific per-file configuration, an empty string will
			/// be returned and the project preprocessor definitions should be used instead.
			///
			/// \param	sPathName	The pathname of the file.
			///	\return				A string containing the preprocessor definitions for the specified file.
			///
			CString CProjectConfiguration::GetFilePreprocessorDefinitions(const CString& sPathName) const
			{
				const CFileConfiguration config = GetFileConfiguration(sPathName);

				return config.m_sPreprocessorDefinitions;
			}


			/// \brief Set the preprocessor definitions for the specified file.
			///
			/// \param	sPathName					The pathname of the file.
			///	\param	sPreprocessorDefinitions	A string containing the preprocessor definitions for the specified file.
			///	\return								\em true if the directives were set correctly; \em false otherwise.
			///
			bool CProjectConfiguration::SetFilePreprocessorDefinitions(const CString& sPathName, const CString& sPreprocessorDefinitions)
			{
				CFileConfiguration config = GetFileConfiguration(sPathName);

				config.m_sPreprocessorDefinitions = sPreprocessorDefinitions;

				return SetFileConfiguration(sPathName, config);
			}


			/// \brief Retrieve the configuration for the specified file.
			///
			/// Note that if the file does not have a specific per-file configuration, an empty CFileConfiguration
			/// object will be returned and the project configuration should be used instead.
			///
			/// \param	sPathName					The pathname of the file.
			///	\return								A CFileConfiguration containing the configuration for the specified file.
			///
			CFileConfiguration CProjectConfiguration::GetFileConfiguration(const CString& sPathName) const
			{
				CFileConfiguration config;
				(void)m_mapPerFileConfiguration.Lookup(sPathName, config);

				return config;
			}


			/// \brief Set the configuration for the specified file.
			///
			/// \param	sPathName					The pathname of the file.
			///	\param	config						A reference to a CFileConfiguration object containing the file configuration.
			///	\return								\em true if the configuration was set correctly; \em false otherwise.
			///
			bool CProjectConfiguration::SetFileConfiguration(const CString& sPathName, const CFileConfiguration& config)
			{
				m_mapPerFileConfiguration[sPathName] = config;

				return true;
			}


		};	// namespace AddInSolutionModel
	};	// namespace Libraries
};	//namespace Riverblade

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 Code Project Open License (CPOL)

Share

About the Authors

Anna-Jayne Metcalfe
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.
 
One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.
 
I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:
 
I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!
Follow on   Twitter

-+- Beth Mackenzie -+-
Software Developer Riverblade Ltd
United Kingdom United Kingdom
I'm a software developer and/or tester with Riverblade Ltd (www.riverblade.co.uk) developing our core product range including our Visual Lint integration product and Lint Project Professional.
 
I incorporate a number of technologies into a daily basis including Windows API, C++ (VS2008), Managed C++, CLI, Databases, Java, JNI, Eclipse Framework, CDT and of course Visual Studio Extensibility (VSIP VSX).
 
In my spare time I enjoy cooking (prepping ingredients from scratch!), running, cycling, swimming, reading, interested in experimental electronic music (such as ClockDVA), movies, volunteering my IT skills where I can.

| Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 29 Jan 2009
Article Copyright 2004 by Anna-Jayne Metcalfe, -+- Beth Mackenzie -+-
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid