Skip to content

Commit

Permalink
refactor: change science class to namespace (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal authored Jun 27, 2024
1 parent 55ae90d commit 59f91e3
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 161 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ set(FAKER_SOURCES
src/modules/medicine/Medicine.cpp
src/modules/movie/Movie.cpp
src/modules/music/Music.cpp
src/modules/number/Number.cpp
src/modules/person/Person.cpp
src/modules/phone/Phone.cpp
src/modules/plant/Plant.cpp
Expand Down
175 changes: 85 additions & 90 deletions include/faker-cxx/Science.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,99 @@

#include <string_view>

namespace faker
namespace faker::science
{
class Science
struct ChemicalElement
{
public:
struct ChemicalElement
{
std::string_view name;
std::string_view symbol;
int atomicNumber;
};

/**
* @brief Returns a random chemical element from the periodic table.
*
* @returns ChemicalElement
*
* @code
* Science::chemicalElement() // Object of ChemicalElement containing info about a random element in the periodic
* table.
* @endcode
*/
static ChemicalElement chemicalElement();
std::string_view name;
std::string_view symbol;
int atomicNumber;
};

struct Unit
{
std::string_view name;
std::string_view symbol;
std::string_view usedToMeasure;
};
/**
* @brief Returns a random chemical element from the periodic table.
*
* @returns ChemicalElement
*
* @code
* Science::chemicalElement() // Object of ChemicalElement containing info about a random element in the periodic
* table.
* @endcode
*/
ChemicalElement chemicalElement();

/**
* @brief Returns a unit of measurement for either distance, mass, time, temp, current.
*
* @returns Unit
*
* @code
* Science::unit() // Object of Unit containing info about a random unit of measurement.
* @endcode
*/
static Unit unit();
struct Unit
{
std::string_view name;
std::string_view symbol;
std::string_view usedToMeasure;
};

/**
* @brief Returns a unit of measurement for either distance.
*
* @returns Unit
*
* @code
* Science::distanceUnit() // Object of Unit containing info about a random unit of measurement used to measure
* distance.
* @endcode
*/
static Unit distanceUnit();
/**
* @brief Returns a unit of measurement for either distance, mass, time, temp, current.
*
* @returns Unit
*
* @code
* Science::unit() // Object of Unit containing info about a random unit of measurement.
* @endcode
*/
Unit unit();

/**
* @brief Returns a unit of measurement for either time.
*
* @returns Unit
*
* @code
* Science::timeUnit() // Object of Unit containing info about a random unit of measurement used to measure time.
* @endcode
*/
static Unit timeUnit();
/**
* @brief Returns a unit of measurement for either distance.
*
* @returns Unit
*
* @code
* Science::distanceUnit() // Object of Unit containing info about a random unit of measurement used to measure
* distance.
* @endcode
*/
Unit distanceUnit();

/**
* @brief Returns a unit of measurement for either mass.
*
* @returns Unit
*
* @code
* Science::massUnit() // Object of Unit containing info about a random unit of measurement used to measure mass.
* @endcode
*/
static Unit massUnit();
/**
* @brief Returns a unit of measurement for either time.
*
* @returns Unit
*
* @code
* Science::timeUnit() // Object of Unit containing info about a random unit of measurement used to measure time.
* @endcode
*/
Unit timeUnit();

/**
* @brief Returns a unit of measurement for either temp.
*
* @returns Unit
*
* @code
* Science::tempUnit() // Object of Unit containing info about a random unit of measurement used to measure temp.
* @endcode
*/
static Unit tempUnit();
/**
* @brief Returns a unit of measurement for either mass.
*
* @returns Unit
*
* @code
* Science::massUnit() // Object of Unit containing info about a random unit of measurement used to measure mass.
* @endcode
*/
Unit massUnit();

/**
* @brief Returns a unit of measurement for either current.
*
* @returns Unit
*
* @code
* Science::currentUnit() // Object of Unit containing info about a random unit of measurement used to measure
* current.
* @endcode
*/
static Unit currentUnit();
};
/**
* @brief Returns a unit of measurement for either temp.
*
* @returns Unit
*
* @code
* Science::tempUnit() // Object of Unit containing info about a random unit of measurement used to measure temp.
* @endcode
*/
Unit tempUnit();

/**
* @brief Returns a unit of measurement for either current.
*
* @returns Unit
*
* @code
* Science::currentUnit() // Object of Unit containing info about a random unit of measurement used to measure
* current.
* @endcode
*/
Unit currentUnit();
}
1 change: 0 additions & 1 deletion src/modules/number/Number.cpp

This file was deleted.

21 changes: 11 additions & 10 deletions src/modules/science/Science.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,47 @@
#include "faker-cxx/Helper.h"
#include "ScienceData.h"

namespace faker
namespace faker::science
{
Science::ChemicalElement Science::chemicalElement()
ChemicalElement chemicalElement()
{
return helper::arrayElement(chemicalElements);
}

Science::Unit Science::unit()
Unit unit()
{
std::vector<faker::Science::Unit> units;
std::vector<Unit> units;

units.insert(units.end(), distanceUnits.begin(), distanceUnits.end());
units.insert(units.end(), massUnits.begin(), massUnits.end());
units.insert(units.end(), timeUnits.begin(), timeUnits.end());
units.insert(units.end(), currentUnits.begin(), currentUnits.end());
units.insert(units.end(), temperatureUnits.begin(), temperatureUnits.end());

return helper::arrayElement<Science::Unit>(units);
return helper::arrayElement<Unit>(units);
}

Science::Unit Science::distanceUnit()
Unit distanceUnit()
{
return helper::arrayElement(distanceUnits);
}

Science::Unit Science::timeUnit()
Unit timeUnit()
{
return helper::arrayElement(timeUnits);
}

Science::Unit Science::massUnit()
Unit massUnit()
{
return helper::arrayElement(massUnits);
}

Science::Unit Science::tempUnit()
Unit tempUnit()
{
return helper::arrayElement(temperatureUnits);
}

Science::Unit Science::currentUnit()
Unit currentUnit()
{
return helper::arrayElement(currentUnits);
}
Expand Down
75 changes: 37 additions & 38 deletions src/modules/science/ScienceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@

#include "faker-cxx/Science.h"

namespace faker
namespace faker::science
{
const auto chemicalElements = std::to_array<Science::ChemicalElement>({
{"Hydrogen", "H", 1}, {"Helium", "He", 2}, {"Lithium", "Li", 3}, {"Beryllium", "Be", 4},
{"Boron", "B", 5}, {"Carbon", "C", 6}, {"Nitrogen", "N", 7}, {"Oxygen", "O", 8},
{"Fluorine", "F", 9}, {"Neon", "Ne", 10}, {"Sodium", "Na", 11}, {"Magnesium", "Mg", 12},
{"Aluminum", "Al", 13}, {"Silicon", "Si", 14}, {"Phosphorus", "P", 15}, {"Sulfur", "S", 16},
{"Chlorine", "Cl", 17}, {"Argon", "Ar", 18}, {"Potassium", "K", 19}, {"Calcium", "Ca", 20},
{"Scandium", "Sc", 21}, {"Titanium", "Ti", 22}, {"Vanadium", "V", 23}, {"Chromium", "Cr", 24},
{"Manganese", "Mn", 25}, {"Iron", "Fe", 26}, {"Cobalt", "Co", 27}, {"Nickel", "Ni", 28},
{"Copper", "Cu", 29}, {"Zinc", "Zn", 30}, {"Gallium", "Ga", 31}, {"Germanium", "Ge", 32},
{"Arsenic", "As", 33}, {"Selenium", "Se", 34}, {"Bromine", "Br", 35}, {"Krypton", "Kr", 36},
{"Rubidium", "Rb", 37}, {"Strontium", "Sr", 38}, {"Yttrium", "Y", 39}, {"Zirconium", "Zr", 40},
{"Niobium", "Nb", 41}, {"Molybdenum", "Mo", 42}, {"Technetium", "Tc", 43}, {"Ruthenium", "Ru", 44},
{"Rhodium", "Rh", 45}, {"Palladium", "Pd", 46}, {"Silver", "Ag", 47}, {"Cadmium", "Cd", 48},
{"Indium", "In", 49}, {"Tin", "Sn", 50}, {"Antimony", "Sb", 51}, {"Tellurium", "Te", 52},
{"Iodine", "I", 53}, {"Xenon", "Xe", 54}, {"Cesium", "Cs", 55}, {"Barium", "Ba", 56},
{"Lanthanum", "La", 57}, {"Cerium", "Ce", 58}, {"Praseodymium", "Pr", 59}, {"Neodymium", "Nd", 60},
{"Promethium", "Pm", 61}, {"Samarium", "Sm", 62}, {"Europium", "Eu", 63}, {"Gadolinium", "Gd", 64},
{"Terbium", "Tb", 65}, {"Dysprosium", "Dy", 66}, {"Holmium", "Ho", 67}, {"Erbium", "Er", 68},
{"Thulium", "Tm", 69}, {"Ytterbium", "Yb", 70}, {"Lutetium", "Lu", 71}, {"Hafnium", "Hf", 72},
{"Tantalum", "Ta", 73}, {"Tungsten", "W", 74}, {"Rhenium", "Re", 75}, {"Osmium", "Os", 76},
{"Iridium", "Ir", 77}, {"Platinum", "Pt", 78}, {"Gold", "Au", 79}, {"Mercury", "Hg", 80},
{"Thallium", "Tl", 81}, {"Lead", "Pb", 82}, {"Bismuth", "Bi", 83}, {"Polonium", "Po", 84},
{"Astatine", "At", 85}, {"Radon", "Rn", 86}, {"Francium", "Fr", 87}, {"Radium", "Ra", 88},
{"Actinium", "Ac", 89}, {"Thorium", "Th", 90}, {"Protactinium", "Pa", 91}, {"Uranium", "U", 92},
{"Neptunium", "Np", 93}, {"Plutonium", "Pu", 94}, {"Americium", "Am", 95}, {"Curium", "Cm", 96},
{"Berkelium", "Bk", 97}, {"Californium", "Cf", 98}, {"Einsteinium", "Es", 99}, {"Fermium", "Fm", 100},
{"Mendelevium", "Md", 101}, {"Nobelium", "No", 102}, {"Lawrencium", "Lr", 103}, {"Rutherfordium", "Rf", 104},
{"Dubnium", "Db", 105}, {"Seaborgium", "Sg", 106}, {"Bohrium", "Bh", 107}, {"Hassium", "Hs", 108},
{"Meitnerium", "Mt", 109}, {"Darmstadtium", "Ds", 110}, {"Roentgenium", "Rg", 111}, {"Copernicium", "Cn", 112},
{"Nihonium", "Nh", 113}, {"Flerovium", "Fl", 114}, {"Moscovium", "Mc", 115}, {"Livermorium", "Lv", 116},
{"Tennessine", "Ts", 117}, {"Oganesson", "Og", 118}
});
const auto chemicalElements = std::to_array<ChemicalElement>(
{{"Hydrogen", "H", 1}, {"Helium", "He", 2}, {"Lithium", "Li", 3}, {"Beryllium", "Be", 4},
{"Boron", "B", 5}, {"Carbon", "C", 6}, {"Nitrogen", "N", 7}, {"Oxygen", "O", 8},
{"Fluorine", "F", 9}, {"Neon", "Ne", 10}, {"Sodium", "Na", 11}, {"Magnesium", "Mg", 12},
{"Aluminum", "Al", 13}, {"Silicon", "Si", 14}, {"Phosphorus", "P", 15}, {"Sulfur", "S", 16},
{"Chlorine", "Cl", 17}, {"Argon", "Ar", 18}, {"Potassium", "K", 19}, {"Calcium", "Ca", 20},
{"Scandium", "Sc", 21}, {"Titanium", "Ti", 22}, {"Vanadium", "V", 23}, {"Chromium", "Cr", 24},
{"Manganese", "Mn", 25}, {"Iron", "Fe", 26}, {"Cobalt", "Co", 27}, {"Nickel", "Ni", 28},
{"Copper", "Cu", 29}, {"Zinc", "Zn", 30}, {"Gallium", "Ga", 31}, {"Germanium", "Ge", 32},
{"Arsenic", "As", 33}, {"Selenium", "Se", 34}, {"Bromine", "Br", 35}, {"Krypton", "Kr", 36},
{"Rubidium", "Rb", 37}, {"Strontium", "Sr", 38}, {"Yttrium", "Y", 39}, {"Zirconium", "Zr", 40},
{"Niobium", "Nb", 41}, {"Molybdenum", "Mo", 42}, {"Technetium", "Tc", 43}, {"Ruthenium", "Ru", 44},
{"Rhodium", "Rh", 45}, {"Palladium", "Pd", 46}, {"Silver", "Ag", 47}, {"Cadmium", "Cd", 48},
{"Indium", "In", 49}, {"Tin", "Sn", 50}, {"Antimony", "Sb", 51}, {"Tellurium", "Te", 52},
{"Iodine", "I", 53}, {"Xenon", "Xe", 54}, {"Cesium", "Cs", 55}, {"Barium", "Ba", 56},
{"Lanthanum", "La", 57}, {"Cerium", "Ce", 58}, {"Praseodymium", "Pr", 59}, {"Neodymium", "Nd", 60},
{"Promethium", "Pm", 61}, {"Samarium", "Sm", 62}, {"Europium", "Eu", 63}, {"Gadolinium", "Gd", 64},
{"Terbium", "Tb", 65}, {"Dysprosium", "Dy", 66}, {"Holmium", "Ho", 67}, {"Erbium", "Er", 68},
{"Thulium", "Tm", 69}, {"Ytterbium", "Yb", 70}, {"Lutetium", "Lu", 71}, {"Hafnium", "Hf", 72},
{"Tantalum", "Ta", 73}, {"Tungsten", "W", 74}, {"Rhenium", "Re", 75}, {"Osmium", "Os", 76},
{"Iridium", "Ir", 77}, {"Platinum", "Pt", 78}, {"Gold", "Au", 79}, {"Mercury", "Hg", 80},
{"Thallium", "Tl", 81}, {"Lead", "Pb", 82}, {"Bismuth", "Bi", 83}, {"Polonium", "Po", 84},
{"Astatine", "At", 85}, {"Radon", "Rn", 86}, {"Francium", "Fr", 87}, {"Radium", "Ra", 88},
{"Actinium", "Ac", 89}, {"Thorium", "Th", 90}, {"Protactinium", "Pa", 91}, {"Uranium", "U", 92},
{"Neptunium", "Np", 93}, {"Plutonium", "Pu", 94}, {"Americium", "Am", 95}, {"Curium", "Cm", 96},
{"Berkelium", "Bk", 97}, {"Californium", "Cf", 98}, {"Einsteinium", "Es", 99}, {"Fermium", "Fm", 100},
{"Mendelevium", "Md", 101}, {"Nobelium", "No", 102}, {"Lawrencium", "Lr", 103}, {"Rutherfordium", "Rf", 104},
{"Dubnium", "Db", 105}, {"Seaborgium", "Sg", 106}, {"Bohrium", "Bh", 107}, {"Hassium", "Hs", 108},
{"Meitnerium", "Mt", 109}, {"Darmstadtium", "Ds", 110}, {"Roentgenium", "Rg", 111}, {"Copernicium", "Cn", 112},
{"Nihonium", "Nh", 113}, {"Flerovium", "Fl", 114}, {"Moscovium", "Mc", 115}, {"Livermorium", "Lv", 116},
{"Tennessine", "Ts", 117}, {"Oganesson", "Og", 118}});

const auto distanceUnits = std::to_array<Science::Unit>({
const auto distanceUnits = std::to_array<Unit>({
{"Millimeter", "mm", "Length"},
{"Centimeter", "cm", "Length"},
{"Meter", "m", "Length"},
Expand All @@ -50,7 +49,7 @@ const auto distanceUnits = std::to_array<Science::Unit>({
{"Mile", "mi", "Length"},
});

const auto massUnits = std::to_array<Science::Unit>({
const auto massUnits = std::to_array<Unit>({
{"Gram", "g", "Mass"},
{"Kilogram", "kg", "Mass"},
{"Milligram", "mg", "Mass"},
Expand All @@ -61,7 +60,7 @@ const auto massUnits = std::to_array<Science::Unit>({
{"Slug", "sl", "Mass"},
});

const auto timeUnits = std::to_array<Science::Unit>({
const auto timeUnits = std::to_array<Unit>({
{"Second", "s", "Time"},
{"Minute", "min", "Time"},
{"Hour", "hr", "Time"},
Expand All @@ -71,13 +70,13 @@ const auto timeUnits = std::to_array<Science::Unit>({
{"Year", "yr", "Time"},
});

const auto currentUnits = std::to_array<Science::Unit>({
const auto currentUnits = std::to_array<Unit>({
{"Ampere", "A", "Electric Current"},
{"Milliampere", "mA", "Electric Current"},
{"Microampere", "μA", "Electric Current"},
});

const auto temperatureUnits = std::to_array<Science::Unit>({
const auto temperatureUnits = std::to_array<Unit>({
{"Celcius", "°C", "Temperature"},
{"Fahrenheit", "°F", "Temperature"},
{"Kelvin", "K", "Temperature"},
Expand Down
1 change: 0 additions & 1 deletion src/modules/system/System.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "faker-cxx/System.h"

#include <iostream>
#include <optional>
#include <set>
#include <string>
Expand Down
1 change: 0 additions & 1 deletion src/modules/vehicle/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace faker::vehicle
{

std::string_view bicycle()
{
return helper::arrayElement(bicycle_types);
Expand Down
Loading

0 comments on commit 59f91e3

Please sign in to comment.