Don't pass objects ( particularly vectors ) by value unless absolutely necessary. Also applied some const-correctness

svn path=/branches/xmlbuildsystem/; revision=12878
This commit is contained in:
Royce Mitchell III 2005-01-08 02:33:09 +00:00
parent 5f69cb429e
commit de7c566b05
6 changed files with 61 additions and 54 deletions

View file

@ -100,7 +100,7 @@ MingwBackend::ProcessModule ( Module& module )
}
void
MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers )
MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const
{
moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) );
moduleHandlers.push_back ( new MingwStaticLibraryModuleHandler ( fMakefile ) );

View file

@ -7,6 +7,9 @@
class MingwModuleHandlerList : public std::vector<MingwModuleHandler*>
{
public:
MingwModuleHandlerList()
{
}
~MingwModuleHandlerList()
{
for ( size_t i = 0; i < size(); i++ )
@ -14,6 +17,10 @@ public:
delete (*this)[i];
}
}
private:
// disable copy semantics
MingwModuleHandlerList ( const MingwModuleHandlerList& );
MingwModuleHandlerList& operator = ( const MingwModuleHandlerList& );
};
@ -24,7 +31,7 @@ public:
virtual void Process ();
private:
void ProcessModule ( Module& module );
void GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers );
void GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const;
void CreateMakefile ();
void CloseMakefile ();
void GenerateHeader ();

View file

@ -15,14 +15,14 @@ MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile )
}
string
MingwModuleHandler::GetWorkingDirectory ()
MingwModuleHandler::GetWorkingDirectory () const
{
return ".";
}
string
MingwModuleHandler::ReplaceExtension ( string filename,
string newExtension )
MingwModuleHandler::ReplaceExtension ( const string& filename,
const string& newExtension ) const
{
size_t index = filename.find_last_of ( '.' );
if (index != string::npos)
@ -31,14 +31,14 @@ MingwModuleHandler::ReplaceExtension ( string filename,
}
string
MingwModuleHandler::GetModuleArchiveFilename ( Module& module )
MingwModuleHandler::GetModuleArchiveFilename ( const Module& module ) const
{
return ReplaceExtension ( module.GetPath ().c_str (),
".a" );
}
string
MingwModuleHandler::GetImportLibraryDependencies ( Module& module )
MingwModuleHandler::GetImportLibraryDependencies ( const Module& module ) const
{
if ( module.libraries.size () == 0 )
return "";
@ -56,7 +56,7 @@ MingwModuleHandler::GetImportLibraryDependencies ( Module& module )
}
string
MingwModuleHandler::GetSourceFilenames ( Module& module )
MingwModuleHandler::GetSourceFilenames ( const Module& module ) const
{
if ( module.files.size () == 0 )
return "";
@ -72,14 +72,14 @@ MingwModuleHandler::GetSourceFilenames ( Module& module )
}
string
MingwModuleHandler::GetObjectFilename ( string sourceFilename )
MingwModuleHandler::GetObjectFilename ( const string& sourceFilename ) const
{
return ReplaceExtension ( sourceFilename,
".o" );
}
string
MingwModuleHandler::GetObjectFilenames ( Module& module )
MingwModuleHandler::GetObjectFilenames ( const Module& module ) const
{
if ( module.files.size () == 0 )
return "";
@ -95,7 +95,7 @@ MingwModuleHandler::GetObjectFilenames ( Module& module )
}
string
MingwModuleHandler::GenerateGccDefineParametersFromVector ( vector<Define*> defines )
MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector<Define*>& defines ) const
{
string parameters;
for (size_t i = 0; i < defines.size (); i++)
@ -115,7 +115,7 @@ MingwModuleHandler::GenerateGccDefineParametersFromVector ( vector<Define*> defi
}
string
MingwModuleHandler::GenerateGccDefineParameters ( Module& module )
MingwModuleHandler::GenerateGccDefineParameters ( const Module& module ) const
{
string parameters = GenerateGccDefineParametersFromVector ( module.project->defines );
string s = GenerateGccDefineParametersFromVector ( module.defines );
@ -128,8 +128,8 @@ MingwModuleHandler::GenerateGccDefineParameters ( Module& module )
}
string
MingwModuleHandler::ConcatenatePaths ( string path1,
string path2 )
MingwModuleHandler::ConcatenatePaths ( const string& path1,
const string& path2 ) const
{
if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
return path2;
@ -140,8 +140,8 @@ MingwModuleHandler::ConcatenatePaths ( string path1,
}
string
MingwModuleHandler::GenerateGccIncludeParametersFromVector ( string basePath,
vector<Include*> includes )
MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const string& basePath,
const vector<Include*>& includes ) const
{
string parameters;
for (size_t i = 0; i < includes.size (); i++)
@ -157,7 +157,7 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( string basePath,
}
string
MingwModuleHandler::GenerateGccIncludeParameters ( Module& module )
MingwModuleHandler::GenerateGccIncludeParameters ( const Module& module ) const
{
string parameters = GenerateGccIncludeParametersFromVector ( ".",
module.project->includes );
@ -172,7 +172,7 @@ MingwModuleHandler::GenerateGccIncludeParameters ( Module& module )
}
string
MingwModuleHandler::GenerateGccParameters ( Module& module )
MingwModuleHandler::GenerateGccParameters ( const Module& module ) const
{
string parameters = GenerateGccDefineParameters ( module );
string s = GenerateGccIncludeParameters ( module );
@ -185,7 +185,7 @@ MingwModuleHandler::GenerateGccParameters ( Module& module )
}
void
MingwModuleHandler::GenerateObjectFileTargets ( Module& module )
MingwModuleHandler::GenerateObjectFileTargets ( const Module& module ) const
{
if ( module.files.size () == 0 )
return;
@ -209,7 +209,7 @@ MingwModuleHandler::GenerateObjectFileTargets ( Module& module )
}
void
MingwModuleHandler::GenerateArchiveTarget ( Module& module )
MingwModuleHandler::GenerateArchiveTarget ( const Module& module ) const
{
string archiveFilename = GetModuleArchiveFilename ( module );
string sourceFilenames = GetSourceFilenames ( module );
@ -233,19 +233,19 @@ MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile )
}
bool
MingwKernelModuleHandler::CanHandleModule ( Module& module )
MingwKernelModuleHandler::CanHandleModule ( const Module& module ) const
{
return module.type == KernelModeDLL;
}
void
MingwKernelModuleHandler::Process ( Module& module )
MingwKernelModuleHandler::Process ( const Module& module )
{
GenerateKernelModuleTarget ( module );
}
void
MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module )
MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
{
string workingDirectory = GetWorkingDirectory ( );
string archiveFilename = GetModuleArchiveFilename ( module );
@ -292,19 +292,19 @@ MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( FILE* fMakefi
}
bool
MingwStaticLibraryModuleHandler::CanHandleModule ( Module& module )
MingwStaticLibraryModuleHandler::CanHandleModule ( const Module& module ) const
{
return module.type == StaticLibrary;
}
void
MingwStaticLibraryModuleHandler::Process ( Module& module )
MingwStaticLibraryModuleHandler::Process ( const Module& module )
{
GenerateStaticLibraryModuleTarget ( module );
}
void
MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( Module& module )
MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module& module )
{
GenerateArchiveTarget ( module );
GenerateObjectFileTargets ( module );

View file

@ -7,29 +7,29 @@ class MingwModuleHandler
{
public:
MingwModuleHandler ( FILE* fMakefile );
virtual bool CanHandleModule ( Module& module ) = 0;
virtual void Process ( Module& module ) = 0;
virtual bool CanHandleModule ( const Module& module ) const = 0;
virtual void Process ( const Module& module ) = 0;
protected:
std::string MingwModuleHandler::GetWorkingDirectory ();
std::string ReplaceExtension ( std::string filename,
std::string newExtension );
std::string GetModuleArchiveFilename ( Module& module );
std::string GetImportLibraryDependencies ( Module& module );
std::string GetSourceFilenames ( Module& module );
std::string GetObjectFilename ( std::string sourceFilename );
std::string GetObjectFilenames ( Module& module );
void GenerateObjectFileTargets ( Module& module );
void GenerateArchiveTarget ( Module& module );
std::string MingwModuleHandler::GetWorkingDirectory () const;
std::string ReplaceExtension ( const std::string& filename,
const std::string& newExtension ) const;
std::string GetModuleArchiveFilename ( const Module& module ) const;
std::string GetImportLibraryDependencies ( const Module& module ) const;
std::string GetSourceFilenames ( const Module& module ) const;
std::string GetObjectFilename ( const std::string& sourceFilename ) const;
std::string GetObjectFilenames ( const Module& module ) const;
void GenerateObjectFileTargets ( const Module& module ) const;
void GenerateArchiveTarget ( const Module& module ) const;
FILE* fMakefile;
private:
std::string ConcatenatePaths ( std::string path1,
std::string path2 );
std::string GenerateGccDefineParametersFromVector ( std::vector<Define*> defines );
std::string GenerateGccDefineParameters ( Module& module );
std::string GenerateGccIncludeParametersFromVector ( std::string basePath,
std::vector<Include*> includes );
std::string GenerateGccIncludeParameters ( Module& module );
std::string GenerateGccParameters ( Module& module );
std::string ConcatenatePaths ( const std::string& path1,
const std::string& path2 ) const;
std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines ) const;
std::string GenerateGccDefineParameters ( const Module& module ) const;
std::string GenerateGccIncludeParametersFromVector ( const std::string& basePath,
const std::vector<Include*>& includes ) const;
std::string GenerateGccIncludeParameters ( const Module& module ) const;
std::string GenerateGccParameters ( const Module& module ) const;
};
@ -37,10 +37,10 @@ class MingwKernelModuleHandler : public MingwModuleHandler
{
public:
MingwKernelModuleHandler ( FILE* fMakefile );
virtual bool CanHandleModule ( Module& module );
virtual void Process ( Module& module );
virtual bool CanHandleModule ( const Module& module ) const;
virtual void Process ( const Module& module );
private:
void GenerateKernelModuleTarget ( Module& module );
void GenerateKernelModuleTarget ( const Module& module );
};
@ -48,10 +48,10 @@ class MingwStaticLibraryModuleHandler : public MingwModuleHandler
{
public:
MingwStaticLibraryModuleHandler ( FILE* fMakefile );
virtual bool CanHandleModule ( Module& module );
virtual void Process ( Module& module );
virtual bool CanHandleModule ( const Module& module ) const;
virtual void Process ( const Module& module );
private:
void GenerateStaticLibraryModuleTarget ( Module& module );
void GenerateStaticLibraryModuleTarget ( const Module& module );
};
#endif /* MINGW_MODULEHANDLER_H */

View file

@ -118,7 +118,7 @@ Module::GetDefaultModuleExtension ()
}
string
Module::GetPath ()
Module::GetPath () const
{
return FixSeparator (path) + CSEP + name + extension;
}

View file

@ -77,7 +77,7 @@ public:
const std::string& modulePath );
~Module ();
ModuleType GetModuleType (const XMLAttribute& attribute );
std::string GetPath ();
std::string GetPath () const;
void ProcessXML ( const XMLElement& e, const std::string& path );
private:
std::string GetDefaultModuleExtension ();