Commit 6af2e592 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'update-cmake-variable-names'

6621b069 STYLE: Use range-based loops from C++11
cc8fc323 STYLE: Use auto for variable type matches the type of the initializer
91429382 PERF: emplace_back method results in potentially more efficient code
6d20e7c9 STYLE: Prefer = default to explicitly trivial implementations
d07092a0 STYLE: Use default member initialization
4c7f64eb COMP: Prefer const member functions
acc916ed COMP: Prefer const pointer when value does not change
7be4043f

 STYLE: Prefer c++11 'using' to 'typedef'
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !169
parents 0e34fbcf 6621b069
This diff is collapsed.
......@@ -66,26 +66,21 @@ class CommandLineArgumentsMapOfStrucs
class CommandLineArgumentsInternal
{
public:
CommandLineArgumentsInternal()
: UnknownArgumentCallback{ nullptr }
, ClientData{ nullptr }
, LastArgument{ 0 }
{
}
CommandLineArgumentsInternal() = default;
typedef CommandLineArgumentsVectorOfStrings VectorOfStrings;
typedef CommandLineArgumentsMapOfStrucs CallbacksMap;
typedef kwsys::String String;
typedef CommandLineArgumentsSetOfStrings SetOfStrings;
using VectorOfStrings = CommandLineArgumentsVectorOfStrings;
using CallbacksMap = CommandLineArgumentsMapOfStrucs;
using String = kwsys::String;
using SetOfStrings = CommandLineArgumentsSetOfStrings;
VectorOfStrings Argv;
String Argv0;
CallbacksMap Callbacks;
CommandLineArguments::ErrorCallbackType UnknownArgumentCallback;
void* ClientData;
CommandLineArguments::ErrorCallbackType UnknownArgumentCallback{ nullptr };
void* ClientData{ nullptr };
VectorOfStrings::size_type LastArgument;
VectorOfStrings::size_type LastArgument{ 0 };
VectorOfStrings UnusedArguments;
};
......@@ -424,8 +419,7 @@ void CommandLineArguments::SetUnknownArgumentCallback(
const char* CommandLineArguments::GetHelp(const char* arg)
{
CommandLineArguments::Internal::CallbacksMap::iterator it =
this->Internals->Callbacks.find(arg);
auto it = this->Internals->Callbacks.find(arg);
if (it == this->Internals->Callbacks.end()) {
return nullptr;
}
......@@ -434,8 +428,7 @@ const char* CommandLineArguments::GetHelp(const char* arg)
// one point to if this one is pointing to another argument.
CommandLineArgumentsCallbackStructure* cs = &(it->second);
for (;;) {
CommandLineArguments::Internal::CallbacksMap::iterator hit =
this->Internals->Callbacks.find(cs->Help);
auto hit = this->Internals->Callbacks.find(cs->Help);
if (hit == this->Internals->Callbacks.end()) {
break;
}
......@@ -470,9 +463,8 @@ void CommandLineArguments::GenerateHelp()
// Collapse all arguments into the map of vectors of all arguments that do
// the same thing.
CommandLineArguments::Internal::CallbacksMap::iterator it;
typedef std::map<CommandLineArguments::Internal::String,
CommandLineArguments::Internal::SetOfStrings>
MapArgs;
using MapArgs = std::map<CommandLineArguments::Internal::String,
CommandLineArguments::Internal::SetOfStrings>;
MapArgs mp;
MapArgs::iterator mpit, smpit;
for (it = this->Internals->Callbacks.begin();
......@@ -709,7 +701,7 @@ bool CommandLineArguments::PopulateVariable(
if (cs->Callback) {
if (!cs->Callback(cs->Argument, value, cs->CallData)) {
this->Internals->LastArgument--;
return 0;
return false;
}
}
CommandLineArguments_DEBUG("Set argument: " << cs->Argument << " to "
......@@ -759,10 +751,10 @@ bool CommandLineArguments::PopulateVariable(
std::cerr << "Got unknown variable type: \"" << cs->VariableType
<< "\"" << std::endl;
this->Internals->LastArgument--;
return 0;
return false;
}
}
return 1;
return true;
}
} // namespace KWSYS_NAMESPACE
......@@ -204,15 +204,15 @@ bool Directory::Load(const std::string& name)
DIR* dir = opendir(name.c_str());
if (!dir) {
return 0;
return false;
}
for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) {
this->Internal->Files.push_back(d->d_name);
this->Internal->Files.emplace_back(d->d_name);
}
this->Internal->Path = name;
closedir(dir);
return 1;
return true;
}
unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
......
MESSAGE("*** This message is generated by message inside a file that is included in DartTestfile.txt ***")
message("*** This message is generated by message inside a file that is included in DartTestfile.txt ***")
......@@ -415,8 +415,7 @@ bool Glob::FindFiles(const std::string& inexpr, GlobMessages* messages)
void Glob::AddExpression(const std::string& expr)
{
this->Internals->Expressions.push_back(
kwsys::RegularExpression(this->PatternToRegex(expr)));
this->Internals->Expressions.emplace_back(this->PatternToRegex(expr));
}
void Glob::SetRelative(const char* dir)
......
......@@ -180,8 +180,8 @@ kwsysEXPORT void kwsysProcess_SetPipeShared(kwsysProcess* cp, int pipe,
* write end of the pipe will be closed in the parent process and the
* read end will be closed in the child process.
*/
kwsysEXPORT void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe,
kwsysProcess_Pipe_Handle p[2]);
kwsysEXPORT void kwsysProcess_SetPipeNative(
kwsysProcess* cp, int pipe, const kwsysProcess_Pipe_Handle p[2]);
/**
* Get/Set a possibly platform-specific option. Possible options are:
......
......@@ -152,10 +152,11 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
static void kwsysProcessDestroy(kwsysProcess* cp);
static int kwsysProcessSetupOutputPipeFile(int* p, const char* name);
static int kwsysProcessSetupOutputPipeNative(int* p, int des[2]);
static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
static int kwsysProcessGetTimeoutTime(kwsysProcess* cp,
const double* userTimeout,
kwsysProcessTime* timeoutTime);
static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
double* userTimeout,
const double* userTimeout,
kwsysProcessTimeNative* timeoutLength,
int zeroIsExpired);
static kwsysProcessTime kwsysProcessTimeGetCurrent(void);
......@@ -571,7 +572,7 @@ void kwsysProcess_SetPipeShared(kwsysProcess* cp, int prPipe, int shared)
}
}
void kwsysProcess_SetPipeNative(kwsysProcess* cp, int prPipe, int p[2])
void kwsysProcess_SetPipeNative(kwsysProcess* cp, int prPipe, const int p[2])
{
int* pPipeNative = 0;
......@@ -1959,7 +1960,8 @@ static int kwsysProcessSetupOutputPipeNative(int* p, int des[2])
/* Get the time at which either the process or user timeout will
expire. Returns 1 if the user timeout is first, and 0 otherwise. */
static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
static int kwsysProcessGetTimeoutTime(kwsysProcess* cp,
const double* userTimeout,
kwsysProcessTime* timeoutTime)
{
/* The first time this is called, we need to calculate the time at
......@@ -1991,7 +1993,7 @@ static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, double* userTimeout,
/* Get the length of time before the given timeout time arrives.
Returns 1 if the time has already arrived, and 0 otherwise. */
static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
double* userTimeout,
const double* userTimeout,
kwsysProcessTimeNative* timeoutLength,
int zeroIsExpired)
{
......
......@@ -761,7 +761,7 @@ void kwsysProcess_SetPipeShared(kwsysProcess* cp, int pipe, int shared)
}
}
void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe, HANDLE p[2])
void kwsysProcess_SetPipeNative(kwsysProcess* cp, int pipe, const HANDLE p[2])
{
HANDLE* pPipeNative = 0;
......
......@@ -22,7 +22,7 @@ typedef ptrdiff_t kwsysSystem_ptrdiff_t;
typedef int kwsysSystem_ptrdiff_t;
#endif
static int kwsysSystem__AppendByte(char* local, char** begin, char** end,
static int kwsysSystem__AppendByte(const char* local, char** begin, char** end,
int* size, char c)
{
/* Allocate space for the character. */
......
......@@ -132,7 +132,7 @@ typedef int siginfo_t;
# endif
# endif
# if defined(KWSYS_CXX_HAS_RLIMIT64)
typedef struct rlimit64 ResourceLimitType;
using ResourceLimitType = struct rlimit64;
# define GetResourceLimit getrlimit64
# else
typedef struct rlimit ResourceLimitType;
......@@ -303,34 +303,34 @@ T min(T a, T b)
}
extern "C" {
typedef void (*SigAction)(int, siginfo_t*, void*);
using SigAction = void (*)(int, siginfo_t*, void*);
}
// Define SystemInformationImplementation class
typedef void (*DELAY_FUNC)(unsigned int uiMS);
using DELAY_FUNC = void (*)(unsigned int);
class SystemInformationImplementation
{
public:
typedef SystemInformation::LongLong LongLong;
using LongLong = SystemInformation::LongLong;
SystemInformationImplementation();
~SystemInformationImplementation();
~SystemInformationImplementation() = default;
const char* GetVendorString();
const char* GetVendorString() const;
const char* GetVendorID();
std::string GetTypeID();
std::string GetFamilyID();
std::string GetModelID();
std::string GetModelName();
std::string GetSteppingCode();
const char* GetExtendedProcessorName();
const char* GetProcessorSerialNumber();
int GetProcessorCacheSize();
unsigned int GetLogicalProcessorsPerPhysical();
float GetProcessorClockFrequency();
int GetProcessorAPICID();
int GetProcessorCacheXSize(long int);
bool DoesCPUSupportFeature(long int);
std::string GetTypeID() const;
std::string GetFamilyID() const;
std::string GetModelID() const;
std::string GetModelName() const;
std::string GetSteppingCode() const;
const char* GetExtendedProcessorName() const;
const char* GetProcessorSerialNumber() const;
int GetProcessorCacheSize() const;
unsigned int GetLogicalProcessorsPerPhysical() const;
float GetProcessorClockFrequency() const;
int GetProcessorAPICID() const;
int GetProcessorCacheXSize(long int) const;
bool DoesCPUSupportFeature(long int) const;
const char* GetOSName();
const char* GetHostname();
......@@ -339,24 +339,24 @@ public:
const char* GetOSVersion();
const char* GetOSPlatform();
bool Is64Bits();
bool Is64Bits() const;
unsigned int GetNumberOfLogicalCPU(); // per physical cpu
unsigned int GetNumberOfPhysicalCPU();
unsigned int GetNumberOfLogicalCPU() const; // per physical cpu
unsigned int GetNumberOfPhysicalCPU() const;
bool DoesCPUSupportCPUID();
// Retrieve memory information in MiB.
size_t GetTotalVirtualMemory();
size_t GetAvailableVirtualMemory();
size_t GetTotalPhysicalMemory();
size_t GetAvailablePhysicalMemory();
size_t GetTotalVirtualMemory() const;
size_t GetAvailableVirtualMemory() const;
size_t GetTotalPhysicalMemory() const;
size_t GetAvailablePhysicalMemory() const;
LongLong GetProcessId();
// Retrieve memory information in KiB.
LongLong GetHostMemoryTotal();
LongLong GetHostMemoryAvailable(const char* envVarName);
LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName);
LongLong GetHostMemoryUsed();
LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName,
......@@ -377,60 +377,103 @@ public:
void RunMemoryCheck();
public:
typedef struct tagID
using ID = struct tagID
{
int Type;
int Family;
int Model;
int Revision;
int ExtendedFamily;
int ExtendedModel;
std::string ProcessorName;
std::string Vendor;
std::string SerialNumber;
std::string ModelName;
} ID;
};
using CPUPowerManagement = struct tagCPUPowerManagement
typedef struct tagCPUPowerManagement
{
bool HasVoltageID;
bool HasFrequencyID;
bool HasTempSenseDiode;
} CPUPowerManagement;
};
using CPUExtendedFeatures = struct tagCPUExtendedFeatures
typedef struct tagCPUExtendedFeatures
{
bool Has3DNow;
bool Has3DNowPlus;
bool SupportsMP;
bool HasMMXPlus;
bool HasSSEMMX;
unsigned int LogicalProcessorsPerPhysical;
int APIC_ID;
CPUPowerManagement PowerManagement;
} CPUExtendedFeatures;
};
using CPUFeatures = struct CPUtagFeatures
typedef struct CPUtagFeatures
{
bool HasFPU;
bool HasTSC;
bool HasMMX;
bool HasSSE;
bool HasSSEFP;
bool HasSSE2;
bool HasIA64;
bool HasAPIC;
bool HasCMOV;
bool HasMTRR;
bool HasACPI;
bool HasSerial;
bool HasThermal;
int CPUSpeed;
int L1CacheSize;
int L2CacheSize;
int L3CacheSize;
CPUExtendedFeatures ExtendedFeatures;
} CPUFeatures;
};
enum Manufacturer
{
......@@ -476,7 +519,7 @@ protected:
void CPUCountWindows(); // For windows
unsigned char GetAPICId(); // For windows
bool IsSMTSupported();
bool IsSMTSupported() const;
static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For windows
// For Linux and Cygwin, /proc/cpuinfo formats are slightly different
......@@ -885,7 +928,7 @@ int LoadLines(FILE* file, std::vector<std::string>& lines)
*pBuf = '\0';
pBuf += 1;
}
lines.push_back(buf);
lines.emplace_back(buf);
++nRead;
}
if (ferror(file)) {
......@@ -899,7 +942,7 @@ int LoadLines(FILE* file, std::vector<std::string>& lines)
int LoadLines(const char* fileName, std::vector<std::string>& lines)
{
FILE* file = fopen(fileName, "r");
if (file == 0) {
if (file == nullptr) {
return 0;
}
int nRead = LoadLines(file, lines);
......@@ -1464,10 +1507,6 @@ SystemInformationImplementation::SystemInformationImplementation()
this->OSIs64Bit = (sizeof(void*) == 8);
}
SystemInformationImplementation::~SystemInformationImplementation()
{
}
void SystemInformationImplementation::RunCPUCheck()
{
#ifdef _WIN32
......@@ -1564,7 +1603,7 @@ void SystemInformationImplementation::RunMemoryCheck()
}
/** Get the vendor string */
const char* SystemInformationImplementation::GetVendorString()
const char* SystemInformationImplementation::GetVendorString() const
{
return this->ChipID.Vendor.c_str();
}
......@@ -1760,7 +1799,7 @@ const char* SystemInformationImplementation::GetVendorID()
}
/** Return the type ID of the CPU */
std::string SystemInformationImplementation::GetTypeID()
std::string SystemInformationImplementation::GetTypeID() const
{
std::ostringstream str;
str << this->ChipID.Type;
......@@ -1768,7 +1807,7 @@ std::string SystemInformationImplementation::GetTypeID()
}
/** Return the family of the CPU present */
std::string SystemInformationImplementation::GetFamilyID()
std::string SystemInformationImplementation::GetFamilyID() const
{
std::ostringstream str;
str << this->ChipID.Family;
......@@ -1776,7 +1815,7 @@ std::string SystemInformationImplementation::GetFamilyID()
}
// Return the model of CPU present */
std::string SystemInformationImplementation::GetModelID()
std::string SystemInformationImplementation::GetModelID() const
{
std::ostringstream str;
str << this->ChipID.Model;
......@@ -1784,13 +1823,13 @@ std::string SystemInformationImplementation::GetModelID()
}
// Return the model name of CPU present */
std::string SystemInformationImplementation::GetModelName()
std::string SystemInformationImplementation::GetModelName() const
{
return this->ChipID.ModelName;
}
/** Return the stepping code of the CPU present. */
std::string SystemInformationImplementation::GetSteppingCode()
std::string SystemInformationImplementation::GetSteppingCode() const
{
std::ostringstream str;
str << this->ChipID.Revision;
......@@ -1798,44 +1837,46 @@ std::string SystemInformationImplementation::GetSteppingCode()
}
/** Return the stepping code of the CPU present. */
const char* SystemInformationImplementation::GetExtendedProcessorName()
const char* SystemInformationImplementation::GetExtendedProcessorName() const
{
return this->ChipID.ProcessorName.c_str();
}
/** Return the serial number of the processor
* in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */
const char* SystemInformationImplementation::GetProcessorSerialNumber()
const char* SystemInformationImplementation::GetProcessorSerialNumber() const
{
return this->ChipID.SerialNumber.c_str();
}
/** Return the logical processors per physical */
unsigned int SystemInformationImplementation::GetLogicalProcessorsPerPhysical()
const
{
return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical;
}
/** Return the processor clock frequency. */
float SystemInformationImplementation::GetProcessorClockFrequency()
float SystemInformationImplementation::GetProcessorClockFrequency() const
{
return this->CPUSpeedInMHz;
}
/** Return the APIC ID. */
int SystemInformationImplementation::GetProcessorAPICID()
int SystemInformationImplementation::GetProcessorAPICID() const
{
return this->Features.ExtendedFeatures.APIC_ID;
}
/** Return the L1 cache size. */
int SystemInformationImplementation::GetProcessorCacheSize()
int SystemInformationImplementation::GetProcessorCacheSize() const
{
return this->Features.L1CacheSize;
}
/** Return the chosen cache size. */
int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID)
int SystemInformationImplementation::GetProcessorCacheXSize(
long int dwCacheID) const
{
switch (dwCacheID) {
case SystemInformation::CPU_FEATURE_L1CACHE:
......@@ -1848,7 +1889,8 @@ int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID)
return -1;
}
bool SystemInformationImplementation::DoesCPUSupportFeature(long int dwFeature)
bool SystemInformationImplementation::DoesCPUSupportFeature(
long int dwFeature) const
{
bool bHasFeature = false;
......@@ -3409,7 +3451,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
// We want to record the total number of cores in this->NumberOfPhysicalCPU
// (checking only the first proc)
std::string Cores = this->ExtractValueFromCpuInfoFile(buffer, "cpu cores");
unsigned int NumberOfCoresPerSocket = (unsigned int)atoi(Cores.c_str());
auto NumberOfCoresPerSocket = (unsigned int)atoi(Cores.c_str());
NumberOfCoresPerSocket = std::max(NumberOfCoresPerSocket, 1u);
this->NumberOfPhysicalCPU =
NumberOfCoresPerSocket * (unsigned int)NumberOfSockets;
......@@ -3441,7 +3483,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
// Linux Sparc: CPU speed is in Hz and encoded in hexadecimal
CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer, "Cpu0ClkTck");
this->CPUSpeedInMHz =
static_cast<float>(strtoull(CPUSpeed.c_str(), 0, 16)) / 1000000.0f;
static_cast<float>(strtoull(CPUSpeed.c_str(), nullptr, 16)) / 1000000.0f;
}
#endif
......@@ -3502,9 +3544,8 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
cachename.push_back("D-cache"); // e.g. PA-RISC
this->Features.L1CacheSize = 0;
for (size_t index = 0; index < cachename.size(); index++) {
std::string cacheSize =
this->ExtractValueFromCpuInfoFile(buffer, cachename[index]);
for (auto& index : cachename) {
std::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer, index);
if (!cacheSize.empty()) {
pos = cacheSize.find(" KB");
if (pos != std::string::npos) {
......@@ -4249,24 +4290,24 @@ bool SystemInformationImplementation::QueryMemory()
}
/** */
size_t SystemInformationImplementation::GetTotalVirtualMemory()
size_t SystemInformationImplementation::GetTotalVirtualMemory() const
{
return this->TotalVirtualMemory;
}
/** */
size_t SystemInformationImplementation::GetAvailableVirtualMemory()
size_t SystemInformationImplementation::GetAvailableVirtualMemory() const
{
return this->AvailableVirtualMemory;
}
size_t SystemInformationImplementation::GetTotalPhysicalMemory()
size_t SystemInformationImplementation::GetTotalPhysicalMemory() const
{
return this->TotalPhysicalMemory;
}
/** */
size_t SystemInformationImplementation::GetAvailablePhysicalMemory()
size_t SystemInformationImplementation::GetAvailablePhysicalMemory() const
{
return this->AvailablePhysicalMemory;
}
......@@ -4350,7 +4391,7 @@ void SystemInformationImplementation::DelayOverhead(unsigned int uiMS)
}
/** Works only for windows */
bool SystemInformationImplementation::IsSMTSupported()
bool SystemInformationImplementation::IsSMTSupported() const
{
return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical > 1;
}
......@@ -4432,13 +4473,13 @@ void SystemInformationImplementation::CPUCountWindows()
}
/** Return the number of logical CPUs on the system */
unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU()
unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU() const
{
return this->NumberOfLogicalCPU;
}
/** Return the number of physical CPUs on the system */
unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU()