From 3899450af16a0162aac8e91c5487c2a802c609d7 Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Tue, 25 Oct 2011 03:55:49 +0300 Subject: Config method to acquire country/state/city names. Doxygen docs --- client/Config.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'client/Config.cpp') diff --git a/client/Config.cpp b/client/Config.cpp index 472fdf4..62318df 100644 --- a/client/Config.cpp +++ b/client/Config.cpp @@ -1,4 +1,5 @@ +#include #include #include "client.h" #include "Config.h" @@ -35,6 +36,61 @@ bool Config::IsConfigValid() return configValid; } +vector Config::GetCountries() +{ + vector countries(genericProxy.size()); + for (unsigned i = 0; i < genericProxy.size(); i++) + { + countries.push_back(genericProxy[i].country); + } + sort(countries.begin(), countries.end()); + vector::iterator end = unique(countries.begin(), countries.end()); + countries.resize(end - countries.begin()); + return countries; +} + +vector Config::GetStates(std::string &country) +{ + vector states(genericProxy.size()); + for (unsigned i = 0; i < genericProxy.size(); i++) + { + if ((genericProxy[i].state != "-") && + (genericProxy[i].country == country)) + { + states.push_back(genericProxy[i].state); + } + } + if (!states.empty()) + { + sort(states.begin(), states.end()); + vector::iterator end = unique(states.begin(), states.end()); + states.resize(end - states.begin()); + } + return states; +} + +vector Config::GetCities(std::string &country) +{ + string defState = "-"; + GetCities(country, defState); +} + +vector Config::GetCities(std::string &country, std::string &state) +{ + vector cities(genericProxy.size()); + for (unsigned i = 0; i < genericProxy.size(); i++) + { + if ((genericProxy[i].state == state) && + (genericProxy[i].country == country)) + { + cities.push_back(genericProxy[i].city); + } + } + sort(cities.begin(), cities.end()); + vector::iterator end = unique(cities.begin(), cities.end()); + cities.resize(end - cities.begin()); + return cities; +} int Config::ReadGenericProxy() { -- cgit v1.2.3