Click here to Skip to main content
12,301,418 members (54,660 online)
Click here to Skip to main content

Stats

271.5K views
3.4K downloads
151 bookmarked
Posted

Include File Hierarchy Viewer

, 29 Jul 2003 CPOL
A tool to view the include file hierarchy of your source code.
//====================================================================
// Although great care has gone into developing this software,
// it is provided without any guarantee of reliability, accuracy
// of information, or correctness of operation.  I am not responsible
// for any damages that may occur as a result of using this software.
// Use this software entirely at your own risk.
// Copyright 2003, Chris Richardson
//
// Description: Base classes used to read devstudio projects and workspaces.
//
//====================================================================

#include "stdafx.h"
#include "DSObjects.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////////////
// CDSSetting Implementation.
//////////////////////////////////////////////////////////////////////

CDSSetting::CDSSetting( DSSettingType p_eType,
                        const TCHAR * p_pszText ) :
   c_eType( p_eType ),
   c_sText( p_pszText )
{
}
//
// ------------------------------------------------------------------
//
CDSSetting::~CDSSetting()
{
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSParsedSettings Implementation.
//////////////////////////////////////////////////////////////////////

CDSParsedSettings::CDSParsedSettings()
{
}
//
// ------------------------------------------------------------------
//
CDSParsedSettings::~CDSParsedSettings()
{
}
//
// ------------------------------------------------------------------
//
void CDSParsedSettings::Clear()
{
   c_oDefines.clear();
   c_oIncludes.clear();
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSSettings Implementation.
//////////////////////////////////////////////////////////////////////

CDSSettings::CDSSettings()
{
}
//
// ------------------------------------------------------------------
//
CDSSettings::~CDSSettings()
{
}
//
// ------------------------------------------------------------------
//
CDSSettings::CDSSettings( const CDSSettings & p_roCopy )
{
   *this = p_roCopy;
}
//
// ------------------------------------------------------------------
//
CDSSettings & CDSSettings::operator=( const CDSSettings & p_roCopy )
{
   c_oAddSettings       = p_roCopy.c_oAddSettings;
   c_oSubtractSettings  = p_roCopy.c_oSubtractSettings;

   return *this;
}
//
// ------------------------------------------------------------------
//
void CDSSettings::Clear()
{
   c_oAddSettings.clear();
   c_oSubtractSettings.clear();
}
//
// ------------------------------------------------------------------
//
bool CDSSettings::IsSubtractedSetting( const CDSSetting & p_roSetting )
{
   CDSSettingArray::iterator a_oSubIter = c_oSubtractSettings.begin();
   while( a_oSubIter != c_oSubtractSettings.end() )
   {
      if( *a_oSubIter == p_roSetting )
         return true;

      a_oSubIter++;
   }
   
   return false;
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSConfigurationHolder Implementation.
//////////////////////////////////////////////////////////////////////

CDSConfigurationHolder::CDSConfigurationHolder()
{
}
//
// ------------------------------------------------------------------
//
CDSConfigurationHolder::~CDSConfigurationHolder()
{
   CDSMapConfigToSettings::iterator a_oIter = c_oSettings.begin();
   while( a_oIter != c_oSettings.end() )
   {
      CDSSettings * a_poSettings = a_oIter->second;

      delete a_poSettings;

      a_oIter++;
   }
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSFile Implementation.
//////////////////////////////////////////////////////////////////////

CDSFile::CDSFile()
{
}
//
// ------------------------------------------------------------------
//
CDSFile::~CDSFile()
{
}
//
// ------------------------------------------------------------------
//
void CDSFile::DetermineName()
{
   // Extract the name from the path.
   const TCHAR * a_pszName = _tcsrchr( c_sPath.c_str(), _T('\\') );
   if( !a_pszName )
      a_pszName = _tcsrchr( c_sPath.c_str(), _T('/') );
   
   if( a_pszName )
      a_pszName++;

   c_sName = a_pszName;
}
//
// ------------------------------------------------------------------
//
bool CDSFile::DoesMatchMask( const TCHAR * p_pszMask )
{
   return WildcardCompare( c_sName.c_str(), p_pszMask );
}
//
// ------------------------------------------------------------------
//
void CDSFile::GetFileSettings( CDSConfiguration * p_poConfiguration,
                               CDSParsedSettings & p_roSettings )
{
   CDSMapConfigToSettings & a_roSettings = c_poConfigHolder->GetSettings();
   CDSMapConfigToSettings::iterator a_oIter = a_roSettings.find( p_poConfiguration->GetName() );

   const CDSSettings *  a_poConfigSettings = p_poConfiguration->GetSettings();
   CDSSettings *        a_poFileSettings = NULL;
   if( a_oIter != a_roSettings.end() )
   {
      // Have the ParseSettings combine our (per file) settings with the configuration's settings.
      a_poFileSettings = a_oIter->second;
   }
   
   a_poConfigSettings->ParseSettings( a_poFileSettings, p_roSettings );
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSConfiguration Implementation.
//////////////////////////////////////////////////////////////////////

CDSConfiguration::CDSConfiguration( const TCHAR * p_pszName,
                                    CDSSettings * p_poSettings ) :
   c_sName( p_pszName ),
   c_poSettings( p_poSettings )
{
   // Try to parse out the display name.
   // The full name should look like this: "ProjectName - ConfigurationName".
   TCHAR * a_pszSep = _tcschr( c_sName.c_str(), _T('-') );
   if( !a_pszSep )
      c_sDisplayName = c_sName;
   else
   {
      a_pszSep += 2;
      c_sDisplayName = a_pszSep;
   }
}
//
// ------------------------------------------------------------------
//
CDSConfiguration::~CDSConfiguration()
{
   if( c_poSettings )
   {
      delete c_poSettings;
      c_poSettings = NULL;
   }
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSProject Implementation.
//////////////////////////////////////////////////////////////////////

CDSProject::CDSProject()
{
}
//
// ------------------------------------------------------------------
//
CDSProject::~CDSProject()
{
   int i = 0;

   // Delete our file.
   for( i = 0; i<c_oFiles.size(); ++i )
      delete c_oFiles[i];
   
   // Delete our configurations.
   for( i = 0; i<c_oConfigurations.size(); ++i )
      delete c_oConfigurations[i];
}
//
// ------------------------------------------------------------------
//
void CDSProject::GetAllConfigurations( CDSConfigurationArray & p_roConfigurations )
{
   p_roConfigurations.insert( p_roConfigurations.end(), c_oConfigurations.begin(), c_oConfigurations.end() );
}
//
// ------------------------------------------------------------------
//
void CDSProject::GetAllMatchingFiles( CDSFileArray & p_roFiles,
                                      const CStdStringArray & p_roFileMasks )
{
   for( int file = 0; file<c_oFiles.size(); ++file )
   {
      CDSFile * a_poFile = c_oFiles[file];
      for( int mask = 0; mask < p_roFileMasks.size(); ++mask )
      {
         if( a_poFile->DoesMatchMask( p_roFileMasks[mask].c_str() ) )
            p_roFiles.push_back( a_poFile );
      }
   }
}
//
// ------------------------------------------------------------------
//
CDSConfiguration * CDSProject::GetConfiguration( const TCHAR * p_pszName )
{
   if( c_oConfigurations.size() == 0 )
      return NULL;

   for( int config = 0; config < c_oConfigurations.size(); ++config )
   {
      CDSConfiguration * a_poConfig = c_oConfigurations[config];
      
      if( !_tcscmp( a_poConfig->GetDisplayName(), p_pszName ) )
         return a_poConfig;
   }

   // We didn't find a configuration by the specified name, so return the first configuration.
   return c_oConfigurations[0];
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSWorkspace Implementation.
//////////////////////////////////////////////////////////////////////

CStdStringArray CDSWorkspace::s_oStdIncludes;

CDSWorkspace::CDSWorkspace()
{
}
//
// ------------------------------------------------------------------
//
CDSWorkspace::~CDSWorkspace()
{
   for( int i = 0; i<c_oProjects.size(); ++i )
      delete c_oProjects[i];
}
//
// ------------------------------------------------------------------
//
ParseStatus CDSWorkspace::ReadWorkspace( const TCHAR * p_pszPath )
{
   ParseStatus a_eStatus = PARSE_STATUS_OK;
   CFILEStream a_oStream;

   // First open a stream on the file.
   a_eStatus = a_oStream.Open( p_pszPath );
   if( a_eStatus != PARSE_STATUS_OK )
      return a_eStatus;
   
   // Get the directory and drive information out of the workspace path.
   TCHAR a_szDriveAndDir[MAX_PATH + 1] = {0};
   TCHAR a_szDirectory[MAX_PATH + 1] = {0};
   _tsplitpath( p_pszPath, a_szDriveAndDir, a_szDirectory, NULL, NULL );
   _tcscat( a_szDriveAndDir, a_szDirectory );
   c_sDirectory = a_szDriveAndDir;

   TCHAR a_szLine[2048] = {0};
   while( a_oStream.GetS( a_szLine, 2048 ) )
   {
      a_eStatus = ParseLine( a_szLine );
      if( a_eStatus != PARSE_STATUS_OK )
         break;
      
      // Probably should handle errors here.
   }

   return PARSE_STATUS_OK;
}
//
// ------------------------------------------------------------------
//
ParseStatus CDSWorkspace::ParseLine( TCHAR * p_pszLine )
{
   return PARSE_STATUS_OK;
}
//
// ------------------------------------------------------------------
//
void CDSWorkspace::GetAllConfigurations( CDSConfigurationArray & p_roConfigurations )
{
   for( int i = 0; i<c_oProjects.size(); ++i )
   {
      c_oProjects[i]->GetAllConfigurations( p_roConfigurations );
   }
}
//
// ------------------------------------------------------------------
//
void CDSWorkspace::GetAllProjects( CDSProjectArray & p_roProjects )
{
   p_roProjects.insert( p_roProjects.begin(), c_oProjects.begin(), c_oProjects.end() );
}
//
// ------------------------------------------------------------------
//
void CDSWorkspace::GetStdIncludes( CStdStringArray & p_roIncludes )
{
   p_roIncludes.insert( p_roIncludes.begin(), s_oStdIncludes.begin(), s_oStdIncludes.end() );
}
//
// ------------------------------------------------------------------
//

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 Author

Chris Richardson
Software Developer (Senior)
United States United States
I like to program, I like to sail.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160525.2 | Last Updated 30 Jul 2003
Article Copyright 2003 by Chris Richardson
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid