Skip to content

Commit

Permalink
Update location.cpp
Browse files Browse the repository at this point in the history
made changes according to the continent module
  • Loading branch information
charan-003 authored Nov 16, 2024
1 parent 58d922c commit 463cc42
Showing 1 changed file with 96 additions and 63 deletions.
159 changes: 96 additions & 63 deletions src/modules/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
#include <string>
#include <string_view>
#include <unordered_map>

#include <unordered_set>
#include <stdexcept> // For std::runtime_error
#include "faker-cxx/types/locale.h"
#include "common/algo_helper.h"
#include "common/format_helper.h"
#include "faker-cxx/helper.h"
#include "faker-cxx/number.h"
#include "faker-cxx/person.h"
#include "faker-cxx/types/locale.h"
#include "faker-cxx/types/precision.h"
#include "location_data.h"


#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
Expand All @@ -21,73 +23,104 @@ namespace faker::location
{
namespace
{
CountryAddressesInfo getAddresses(const Locale& locale)
CountryAddressesInfo getAddresses(const faker::Locale& locale)
{
switch (locale)
{
case faker::Locale::en_US:
case faker::Locale::es_US:
return usaAddresses;
case faker::Locale::pl_PL:
return polandAddresses;
case faker::Locale::ru_RU:
return russiaAddresses;
case faker::Locale::fr_FR:
return franceAddresses;
case faker::Locale::uk_UA:
return ukraineAddresses;
case faker::Locale::it_IT:
return italyAddresses;
case faker::Locale::de_DE:
return germanyAddresses;
case faker::Locale::cs_CZ:
return czechAddresses;
case faker::Locale::en_AU:
return australiaAddresses;
case faker::Locale::as_IN:
case faker::Locale::bn_IN:
case faker::Locale::en_IN:
case faker::Locale::gu_IN:
case faker::Locale::hi_IN:
case faker::Locale::kn_IN:
case faker::Locale::ks_IN:
case faker::Locale::ml_IN:
case faker::Locale::mr_IN:
case faker::Locale::or_IN:
case faker::Locale::pa_IN:
case faker::Locale::sa_IN:
case faker::Locale::ta_IN:
case faker::Locale::te_IN:
return indiaAddresses;
case faker::Locale::da_DK:
return denmarkAddresses;
case faker::Locale::ca_ES:
case faker::Locale::es_ES:
return spainAddresses;
case faker::Locale::pt_BR:
return brazilAddresses;
case faker::Locale::fi_FI:
return finlandAddresses;
case faker::Locale::et_EE:
return estoniaAddresses;
case faker::Locale::en_GB:
return unitedkingdomAddresses;
case faker::Locale::sk_SK:
return slovakiaAddresses;
case faker::Locale::pt_PT:
return portugalAddresses;
case faker::Locale::he_IL:
return israelAddresses;
case faker::Locale::ar_PS:
return palestineAddresses;
case faker::Locale::es_MX:
return mexicoAddresses;
default:
return usaAddresses;
}
}
}

std::string_view continent()
{
switch (locale)
// Select a random country
std::string_view randomCountry = helper::randomElement(allCountries);

// Lookup the corresponding continent
const auto it = countryToContinent.find(randomCountry);
if (it != countryToContinent.end())
{
case Locale::en_US:
case Locale::es_US:
return usaAddresses;
case Locale::pl_PL:
return polandAddresses;
case Locale::ru_RU:
return russiaAddresses;
case Locale::fr_FR:
return franceAddresses;
case Locale::uk_UA:
return ukraineAddresses;
case Locale::it_IT:
return italyAddresses;
case Locale::de_DE:
return germanyAddresses;
case Locale::cs_CZ:
return czechAddresses;
case Locale::en_AU:
return australiaAddresses;
case Locale::as_IN:
case Locale::bn_IN:
case Locale::en_IN:
case Locale::gu_IN:
case Locale::hi_IN:
case Locale::kn_IN:
case Locale::ks_IN:
case Locale::ml_IN:
case Locale::mr_IN:
case Locale::or_IN:
case Locale::pa_IN:
case Locale::sa_IN:
case Locale::ta_IN:
case Locale::te_IN:
return indiaAddresses;
case Locale::da_DK:
return denmarkAddresses;
case Locale::ca_ES:
case Locale::es_ES:
return spainAddresses;
case Locale::pt_BR:
return brazilAddresses;
case Locale::fi_FI:
return finlandAddresses;
case Locale::et_EE:
return estoniaAddresses;
case Locale::en_GB:
return unitedkingdomAddresses;
case Locale::sk_SK:
return slovakiaAddresses;
case Locale::pt_PT:
return portugalAddresses;
case Locale::he_IL:
return israelAddresses;
case Locale::ar_PS:
return palestineAddresses;
case Locale::es_MX:
return mexicoAddresses;
default:
return usaAddresses;
return it->second; // Return the continent
}

// Return "Unknown" if no mapping is found
return "Unknown";
}

// Optional: Validation function
void validateCountryMapping()
{
for (const auto& country : allCountries)
{
if (countryToContinent.find(country) == countryToContinent.end())
{
throw std::runtime_error("Country not mapped: " + std::string(country));
}
}
}




std::string_view country()
{
return helper::randomElement(allCountries);
Expand Down

0 comments on commit 463cc42

Please sign in to comment.