Skip to content

Commit 26f7ecd

Browse files
committed
Stopping using variables names shorter than 3 characters
1 parent b9c58ca commit 26f7ecd

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

include/inch/converter.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Converter
3030
Converter(const Converter&) = default;
3131
Converter(Converter&&) = default;
3232

33-
Converter& operator=(Converter&&) = default;
33+
Converter& operator=(Converter&&) = default;
3434
Converter& operator=(const Converter&) = default;
3535

3636
~Converter() = default;
@@ -48,7 +48,7 @@ class Converter
4848
using seconds = std::chrono::duration<double, std::ratio<1, 1>>;
4949
using minutes = std::chrono::duration<double, std::ratio<60, 1>>;
5050
using hours = std::chrono::duration<double, std::ratio<3600, 1>>;
51-
using days = std::chrono::duration<double, std::ratio<24 * 3600, 1>>;
51+
using days = std::chrono::duration<double, std::ratio<static_cast<intmax_t>(24 * 3600), 1>>;
5252
using years = std::chrono::duration<double, std::ratio<year, 1>>;
5353
using kiloyears = std::chrono::duration<double, std::ratio<1000 * year, 1>>;
5454
using millionyears = std::chrono::duration<double, std::ratio<1000000 * year, 1>>;
@@ -122,7 +122,7 @@ class Converter
122122
*
123123
* \return std::tuple of std:string containing Ax10^{BC} where B is either +/-, A and C are decimal numbers
124124
*/
125-
[[nodiscard]] static std::tuple<std::string, std::string, std::string> FloatToExponent(const double in);
125+
[[nodiscard]] static std::tuple<std::string, std::string, std::string> FloatToExponent(const double value);
126126

127127
/**
128128
* Convert a floating point number to a std::string with the specified number of dp
@@ -145,7 +145,7 @@ class Converter
145145
*
146146
* \return A std::string of the given number with required precision and sensible units
147147
*/
148-
[[nodiscard]] static std::string IsomerEnergyToHuman(const double in, const int numDP = 1);
148+
[[nodiscard]] static std::string IsomerEnergyToHuman(const double number, const int numDP = 1);
149149

150150
/**
151151
* Convert a time, in units of seconds, into scientific parlance i.e. 2.3ms rather than 0.0023s
@@ -170,7 +170,7 @@ class Converter
170170
*
171171
* \return The symbol as a std:string
172172
*/
173-
[[nodiscard]] static std::string ZToSymbol(const int Z);
173+
[[nodiscard]] static std::string ZToSymbol(const int proton_number);
174174

175175
/**
176176
* Convert elemental symbol to proton number

src/converter.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ int Converter::StringToInt(const std::string& var)
2525
}
2626

2727

28-
std::string Converter::ZToSymbol(const int Z)
28+
std::string Converter::ZToSymbol(const int proton_number)
2929
{
30-
const auto it = std::find_if(symbolZmap.cbegin(), symbolZmap.cend(), [Z](const std::pair<std::string, int>& element) {
31-
return element.second == Z;
30+
const auto match = std::find_if(symbolZmap.cbegin(), symbolZmap.cend(), [proton_number](const auto element) {
31+
return element.second == proton_number;
3232
});
3333

3434
return [&]() {
35-
if (it == symbolZmap.end())
35+
if (match == symbolZmap.end())
3636
{
37-
fmt::print("\n**WARNING**: {} is not a valid proton number\n", Z);
37+
fmt::print("\n**WARNING**: {} is not a valid proton number\n", proton_number);
3838
return std::string{ "Xy" };
3939
}
4040

41-
return it->first;
41+
return match->first;
4242
}();
4343
}
4444

@@ -47,19 +47,17 @@ int Converter::SymbolToZ(std::string _symbol)
4747
{
4848
const std::string symbol = caseCorrection(std::move(_symbol));
4949

50-
const auto it =
51-
std::find_if(symbolZmap.cbegin(), symbolZmap.cend(), [&symbol](const std::pair<std::string, int>& element) {
52-
return element.first == symbol;
53-
});
50+
const auto match = std::find_if(
51+
symbolZmap.cbegin(), symbolZmap.cend(), [&symbol](const auto element) { return element.first == symbol; });
5452

5553
return [&]() {
56-
if (it == symbolZmap.end())
54+
if (match == symbolZmap.end())
5755
{
5856
fmt::print("\n**WARNING**: {} is not a valid symbol\n", symbol);
5957
return 200;
6058
}
6159

62-
return it->second;
60+
return match->second;
6361
}();
6462
}
6563

@@ -86,29 +84,30 @@ std::string Converter::caseCorrection(std::string symbol)
8684
}
8785

8886

89-
std::tuple<std::string, std::string, std::string> Converter::FloatToExponent(const double in)
87+
std::tuple<std::string, std::string, std::string> Converter::FloatToExponent(const double value)
9088
{
9189
// Force the number to be scientific, i.e. follow the regex: -?\d*\.?\d+e[+-]?\d+
92-
const std::string number = fmt::format("{0:e}", in);
90+
const auto number = fmt::format("{0:e}", value);
9391

9492
const std::regex pieces_regex(R"((-?\d*\.?\d+)e([+-]?)(\d+))");
9593
std::smatch matches;
9694

9795
// Always get 1dp from the first number
9896
// If it's negative take an extra char for the sign
99-
const int digits = (in < 0.0) ? 4 : 3;
97+
const int digits = (value < 0.0) ? 4 : 3;
10098

10199
return (std::regex_match(number, matches, pieces_regex))
102100
// coefficient(1dp) exponent sign exponent
103101
? std::make_tuple(
104-
std::string(matches[1]).substr(0, digits), std::string(matches[2]), std::string(matches[3]))
105-
: std::make_tuple(std::string(), std::string(), std::string());
102+
std::string{ matches[1] }.substr(0, digits), std::string{ matches[2] }, std::string{ matches[3] })
103+
: std::make_tuple(std::string{}, std::string{}, std::string{});
106104
}
107105

108106

109-
std::string Converter::IsomerEnergyToHuman(const double in, const int numDP)
107+
std::string Converter::IsomerEnergyToHuman(const double number, const int numDP)
110108
{
111-
return (in < 1000.0) ? fmt::format("{0:0.{1}f} keV", in, numDP) : fmt::format("{0:0.{1}f} MeV", in / 1000.0, numDP);
109+
return (number < 1000.0) ? fmt::format("{0:0.{1}f} keV", number, numDP)
110+
: fmt::format("{0:0.{1}f} MeV", number / 1000.0, numDP);
112111
}
113112

114113

0 commit comments

Comments
 (0)