Click here to Skip to main content
11,705,762 members (45,384 online)
Click here to Skip to main content
Add your own
alternative version

Include File Hierarchy Viewer

, 29 Jul 2003 CPOL 263.2K 3.3K 151
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.
//
//====================================================================

#if !defined( _DS_OBJECTS_H_DEFINED_ )
#define _DS_OBJECTS_H_DEFINED_

#include "Status.h"
#include "global.h"
#include "FILEStream.h"

//////////////////////////////////////////////////////////////////////
// Typedefs.  Make it easier to work with STL type names.
//
//////////////////////////////////////////////////////////////////////

class CDSSetting;
class CDSSettings;
class CDSFile;
class CDSConfiguration;
class CDSProject;

typedef map<CTCharString,CDSSettings*,CTCharStringLess>  CDSMapConfigToSettings;
typedef vector<CDSFile*>                                 CDSFileArray;
typedef vector<CDSConfiguration*>                        CDSConfigurationArray;
typedef vector<CDSProject*>                              CDSProjectArray;
typedef vector<CDSSetting>                               CDSSettingArray;

//////////////////////////////////////////////////////////////////////
// CDSSetting - Defines an individual compiler setting.
//
//////////////////////////////////////////////////////////////////////

class CDSSetting
{
public:
   typedef enum
   {
      SETTING_FLAG,
      SETTING_INCLUDE,
      SETTING_DEFINE,
      SETTING_UNDEFINE,
   }DSSettingType;

   CDSSetting( DSSettingType p_eType,
               const TCHAR * p_pszText );
   virtual ~CDSSetting();
   
   inline DSSettingType    GetType() const;
   inline const TCHAR *    GetText() const;
   
   inline bool             operator==( const CDSSetting & p_roTest ) const;

protected:
   DSSettingType           c_eType;
   CTCharString            c_sText;
};

inline CDSSetting::DSSettingType CDSSetting::GetType() const
{
   return c_eType;
}
//
// ------------------------------------------------------------------
//
inline const TCHAR * CDSSetting::GetText() const
{
   return c_sText.c_str();
}
//
// ------------------------------------------------------------------
//
inline bool CDSSetting::operator==( const CDSSetting & p_roTest ) const 
{
   return (c_eType == p_roTest.c_eType) && (c_sText.compare( p_roTest.c_sText ) == 0);
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSParsedSettings - Stores the parsed compile settings that we are
//                     interested in, for each configuration.
//////////////////////////////////////////////////////////////////////

class CDSParsedSettings
{
public:
   CDSParsedSettings();
   virtual ~CDSParsedSettings();
   
   inline CStdStringArray &   GetIncludes();
   inline CStdStringArray &   GetDefines();
   
   void                       Clear();

protected:
   CStdStringArray            c_oIncludes;
   CStdStringArray            c_oDefines;
};

inline CStdStringArray & CDSParsedSettings::GetIncludes()
{
   return c_oIncludes;
}
//
// ------------------------------------------------------------------
//
inline CStdStringArray & CDSParsedSettings::GetDefines()
{
   return c_oDefines;
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSSettings - Stores the compile settings that we are interested in,
//               for each configuration.
//////////////////////////////////////////////////////////////////////

class CDSSettings
{
public:
   CDSSettings();
   virtual ~CDSSettings();
   
   CDSSettings( const CDSSettings & p_roCopy );
   CDSSettings & operator=( const CDSSettings & p_roCopy );
   
   virtual void               ParseSettings( CDSSettings * p_poFileSettings, CDSParsedSettings & p_roSettings ) const = 0;

   void                       Clear();

protected:
   CDSSettingArray            c_oAddSettings;
   CDSSettingArray            c_oSubtractSettings;
   
   bool                       IsSubtractedSetting( const CDSSetting & p_roSetting );
};


//////////////////////////////////////////////////////////////////////
// CDSConfigurationHolder - Stores a map of configuration names to
//                          compiler settings objects.
//////////////////////////////////////////////////////////////////////

class CDSConfigurationHolder
{
public:
   CDSConfigurationHolder();
   virtual ~CDSConfigurationHolder();
   
   inline CDSMapConfigToSettings &     GetSettings();

protected:
   // Settings to be removed on a per-file, per-configuration basis.
   CDSMapConfigToSettings              c_oSettings;
};

inline CDSMapConfigToSettings & CDSConfigurationHolder::GetSettings()
{
   return c_oSettings;
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSFile - Represents one source file.
//           Stores the compiler settings for per-file configuration changes.
//////////////////////////////////////////////////////////////////////

class CDSFile
{
public:
   CDSFile();
   virtual ~CDSFile();
   
   inline const TCHAR *       GetPath();
   bool                       DoesMatchMask( const TCHAR * p_pszMask );
   
   void                       GetFileSettings( CDSConfiguration * p_poConfiguration,
                                               CDSParsedSettings & p_roSettings );

protected:
   CDSConfigurationHolder *   c_poConfigHolder;
   CTCharString               c_sPath;
   CTCharString               c_sName;

   void                       DetermineName();
};

inline const TCHAR * CDSFile::GetPath()
{
   return c_sPath.c_str();
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSConfiguration - Represents one project configuration.
//                    Stores the compiler settings for the configuration.
//////////////////////////////////////////////////////////////////////

class CDSConfiguration
{
public:
   CDSConfiguration( const TCHAR * p_pszName,
                     CDSSettings * p_poSettings );
   virtual ~CDSConfiguration();
   
   inline const TCHAR *       GetName();
   inline const TCHAR *       GetDisplayName();
   inline const CDSSettings * GetSettings();

protected:
   CTCharString               c_sName;
   CTCharString               c_sDisplayName;
   CDSSettings *              c_poSettings;
};

inline const TCHAR * CDSConfiguration::GetName()
{
   return c_sName.c_str();
}
//
// ------------------------------------------------------------------
//
inline const TCHAR * CDSConfiguration::GetDisplayName()
{
   return c_sDisplayName.c_str();
}
//
// ------------------------------------------------------------------
//
inline const CDSSettings * CDSConfiguration::GetSettings()
{
   return c_poSettings;
}
//
// ------------------------------------------------------------------
//


//////////////////////////////////////////////////////////////////////
// CDSProject - Represents one project.
//              Stores the list of files and configurations.
//////////////////////////////////////////////////////////////////////

class CDSProject
{
public:
   CDSProject();
   virtual ~CDSProject();
   
   virtual ParseStatus        ReadProject( const TCHAR * p_pszPath ) = 0;

   void                       GetAllConfigurations( CDSConfigurationArray & p_roConfigurations );
   void                       GetAllMatchingFiles( CDSFileArray &          p_roFiles,
                                                   const CStdStringArray & p_roFileMasks );
   CDSConfiguration *         GetConfiguration( const TCHAR * p_pszName );

protected:
   CTCharString               c_sName;
   CDSFileArray               c_oFiles;
   CDSConfigurationArray      c_oConfigurations;
};


//////////////////////////////////////////////////////////////////////
// CDSWorkspace - Represents one workspace.
//                Stores the list of projects.
//////////////////////////////////////////////////////////////////////

class CDSWorkspace
{
public:
   CDSWorkspace();
   virtual ~CDSWorkspace();
   
   // Derived classes should override either ReadWorkspace or ParseLine.
   virtual ParseStatus        ReadWorkspace( const TCHAR * p_pszPath );
   
   virtual ParseStatus        ReadOneProject( const TCHAR * p_pszProjectPath ) = 0;
   
   void                       GetAllConfigurations( CDSConfigurationArray & p_roConfigurations );
   void                       GetAllProjects( CDSProjectArray & p_roProjects );
   
   static void                GetStdIncludes( CStdStringArray & p_roIncludes );

protected:
   CDSProjectArray            c_oProjects;
   CTCharString               c_sPath;
   CTCharString               c_sDirectory;
   
   static CStdStringArray     s_oStdIncludes;

   virtual ParseStatus        ParseLine( TCHAR * p_pszLine );
};

#endif // _DS_OBJECTS_H_DEFINED_

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.150819.1 | Last Updated 30 Jul 2003
Article Copyright 2003 by Chris Richardson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid