Click here to Skip to main content
15,892,737 members
Articles / Desktop Programming / MFC

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

,
Rate me:
Please Sign up or sign in to vote.
4.83/5 (36 votes)
29 Jan 2009CPOL13 min read 280.9K   1.7K   52  
Utility to run PC-Lint on Visual C++ solutions and projects, generating XML and HTML reports of the results.
/************************************************************************
 *
 *  Description : CSolutionFileReaderImpl - implementation class for
 *                CSolutionFileReader.
 *
 *     (c) Copyright 2000-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/Applications/LintProject/Development/Shared/SolutionFileReaderImpl.h $
 *   $Revision: 2 $
 *       $Date: 22/02/08 20:50 $
 *     $Author: Anna $
 * 
 * $Nokeywords: $
 ************************************************************************/

/// \file	
/// \brief Implementation class for CSolutionFileReader.

#pragma once

#ifdef _UTILS_LOCAL_INCLUDE
	#include "SplitPath.h"
	#include "StringUtils.h"
	#include "PathUtils.h"
	#include "FileUtils.h"
#else
	#include <Utils\Include\SplitPath.h>
	#include <Utils\Include\StringUtils.h>
	#include <Utils\Include\PathUtils.h>
	#include <Utils\Include\FileUtils.h>
#endif

#include "ProjectFileReader.h"

#include "SolutionFileReader.h"


namespace Riverblade
{
	namespace Libraries
	{
		namespace AddInSolutionModel
		{
			//lint -esym(1925, *::CSolutionFileReaderProjectImpl::*)		(Elective Note -- Symbol 'CSolutionFileReaderProjectImpl a public data member -- Effective C++ #20)

			/// \brief Implementation class to describe the properties of a project within a solution or workspace file.
			///
			class CSolutionFileReaderProjectImpl
			{
				public:
					/// \brief Default constructor
					///
					CSolutionFileReaderProjectImpl(void)
						:	m_sProject(_T("") ),
							m_sPathName(_T("") ),
							m_sGUID(_T("") ),
							m_mapConfigurations()
					{
					}


					/// \brief Copy constructor
					///
					///	\param	src				A reference to the object to copy from.
					///
					CSolutionFileReaderProjectImpl(const CSolutionFileReaderProjectImpl& src)
						:	m_sProject(src.m_sProject),
							m_sPathName(src.m_sPathName ),
							m_sGUID(src.m_sGUID),
							m_mapConfigurations()
					{
						CopyConfigurations(src);
					}


					/// \brief Class destructor
					///
					virtual	~CSolutionFileReaderProjectImpl(void)
					{
					}


				// Data members
				public:
					CString						m_sProject;					///< The name of the project.
					CString						m_sPathName;				///< The pathname of the project.
					CString						m_sGUID;					///< The project GUID (if applicable).
					CAtlMap<CString, CString>	m_mapConfigurations;		///< Map of solution configurations to project configuration strings.


				// Operators
				public:
					/// \brief Assignment operator
					///
					///	\param	src				A reference to the object to copy from.
					///	\return					A reference to this object.
					///
					CSolutionFileReaderProjectImpl& operator=(const CSolutionFileReaderProjectImpl& src)
					{
						if (this != &src)
						{
							m_sProject	= src.m_sProject;
							m_sGUID		= src.m_sGUID;
							m_sPathName	= src.m_sPathName;

							CopyConfigurations(src);
						}
						return *this;
					}


				// Operations
				public:
					/// \brief Define the mapping between the given solution and project configurations.
					///
					/// \param	sSolutionConfig		The name of the solution configuration.
					/// \param	sProjectConfig		The name of the project configuration it uses.
					///
					void AddConfiguration(const CString& sSolutionConfig, const CString& sProjectConfig)
					{
						m_mapConfigurations[sSolutionConfig] = sProjectConfig;
					}


					/// \brief return the project configuration string associated with the given solution configuration.
					///
					/// \param	sSolutionConfig		The name of the solution configuration.
					/// \return						The name of the project configuration it uses.
					///
					CString GetProjectConfiguration(const CString& sSolutionConfig) const
					{
						CString sProjectConfig;
						(void)m_mapConfigurations.Lookup(sSolutionConfig, sProjectConfig);
						if (sProjectConfig.IsEmpty() )
						{
							// Needed for VS6 projects, unfortunately
							sProjectConfig = sSolutionConfig;
						}
						return sProjectConfig;
					}


				// Implementation
				private:
					/// \brief Implementation method to copy all configuration data from a given source object.
					///
					/// \param	src				A reference to the object to copy.
					///
					void CopyConfigurations(const CSolutionFileReaderProjectImpl& src)
					{
						m_mapConfigurations.RemoveAll();

						POSITION pos = src.m_mapConfigurations.GetStartPosition();
						while (NULL != pos)
						{
							CString sSolutionConfig, sProjectConfig;
							src.m_mapConfigurations.GetNextAssoc(pos, sSolutionConfig, sProjectConfig);

							m_mapConfigurations[sSolutionConfig] = sProjectConfig;
						}
					}
			};

			typedef	CAtlMap<CString, CSolutionFileReaderProjectImpl> CMapStringToProject;		///< Maps project name to the corresponding CProjectInfo object.


			/// \brief An abstract base class used by by CSolutionFileReader for classes used to parse individual solution/workspace file formats.
			///
			class CSolutionFileReaderImpl
			{
				public:
					/// \brief Default constructor.
					///
					CSolutionFileReaderImpl(void)
						:	m_sPathName(),
							m_arrayProjectFilePathNames(),
							m_mapProjects(),
							m_arraySolutionConfigs()
					{
					}

					
					/// \brief Class destructor.
					///
					virtual ~CSolutionFileReaderImpl(void)
					{
					}


					/// \brief Read the given solution or workspace file.
					///
					/// \param	sPathName		The pathname of the file.
					/// \return					\em true if the file was parsed successfully; \em false otherwise.
					///
					virtual bool Read(const CString& sPathName)
					{
						m_sPathName = sPathName;

						// First read the entire file into a buffer for processing
						CAtlArray<CString> arrayLines;
						const HRESULT hr = Utils::ReadTextFile(sPathName, arrayLines);
						DBG_UNREFERENCED_LOCAL_VARIABLE(hr);

						ATLASSERT(SUCCEEDED(hr) );

						if (arrayLines.GetCount() > 0)
						{
							// The file exists and has been read successfully
							// From here on in its up to the parser...
							return Parse(arrayLines);
						}
						return false;
					}


					/// \brief Parse the contents of a solution or workspace file.
					///
					/// Derived classes must implement this method.
					///
					/// \param	arrayLines		The contents of the file.
					/// \return					\em true if the file was parsed successfully; \em false otherwise.
					///
					virtual bool Parse(const CAtlArray<CString>& arrayLines) = 0;


					/// \brief Return an array of the pathnames of the projects found in the solution
					///
					/// \param	rarrayProjectFilePathNames	A reference to an array which will receive the pathnames of
					///										the projects found.
					/// \return								The number of pathnames returned in rarrayProjectFilePathNames.
					///
					virtual size_t GetProjectFilePathNames(CAtlArray<CString>& rarrayProjectFilePathNames) const
					{
						(void)rarrayProjectFilePathNames.Append(m_arrayProjectFilePathNames);

						return rarrayProjectFilePathNames.GetCount();
					}


					/// \brief Return an array of the names of the configurations found in the solution
					///
					/// \param	rarrayConfigurations	A reference to an array which will receive the names of
					///									the configurations found.
					/// \return							The number of configuration names returned in rarrayConfigurations.
					///
					virtual size_t GetConfigurations(CAtlArray<CString>& rarrayConfigurations) const
					{
						rarrayConfigurations.RemoveAll();

						(void)rarrayConfigurations.Append(m_arraySolutionConfigs);

						return rarrayConfigurations.GetCount();
					}


					/// \brief Determine whether the given solution configuration name is valid.
					///
					///	\param	sConfiguration	A string identifying the solution configuration.
					/// \return					\em true if the configuration is valid; \em false otherwise.
					///
					virtual bool IsValidConfiguration(const CString& sConfiguration) const
					{
						for (size_t n = 0; n < m_arraySolutionConfigs.GetCount(); n++)
						{
							if (sConfiguration == m_arraySolutionConfigs[n])
							{
								return true;
							}
						}
						return false;
					}


					/// \brief Retrieve the configuration string for the configuration of a project corresponding to the given solution/workspace configuration.
					///
					/// \param	sPathName			The pathname of the project.
					/// \param	sSolutionConfig		The name of the solution configuration.
					/// \return						The configuration string corresponding to sSolutionConfig, 
					///								or an empty string if one cannot be found.
					///
					virtual CString GetProjectConfigurationFromPathName(const CString& sPathName, const CString& sSolutionConfig) const
					{
						POSITION pos = m_mapProjects.GetStartPosition();
						while (NULL != pos)
						{
							CString sProjectName;
							CSolutionFileReaderProjectImpl info;
							m_mapProjects.GetNextAssoc(pos, sProjectName, info);

							if (0 == sPathName.CompareNoCase(info.m_sPathName) )
							{
								return info.GetProjectConfiguration(sSolutionConfig);
							}
						}
						return _T("");
					}



				protected:
					CString				m_sPathName;						///< The pathname of the solution or workspace
					CAtlArray<CString>	m_arrayProjectFilePathNames;		///< An array of project file pathnames
					CMapStringToProject	m_mapProjects;						///< Map of project pathames to CProjectInfo objects.
					CAtlArray<CString>	m_arraySolutionConfigs;				///< Array of solution configuration names.
			};


		};	// 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)


Written By
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!

Written By
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.

Comments and Discussions