mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	Added WFOs to the county database c++ code
This commit is contained in:
		
							parent
							
								
									412c85647c
								
							
						
					
					
						commit
						6b4045081e
					
				
					 2 changed files with 46 additions and 0 deletions
				
			
		|  | @ -31,6 +31,7 @@ typedef std::unordered_map<char, StateMap>           FormatMap; | ||||||
| static bool                                         initialized_ {false}; | static bool                                         initialized_ {false}; | ||||||
| static FormatMap                                    countyDatabase_; | static FormatMap                                    countyDatabase_; | ||||||
| static std::unordered_map<std::string, std::string> stateMap_; | static std::unordered_map<std::string, std::string> stateMap_; | ||||||
|  | static std::unordered_map<std::string, std::string> wfoMap_; | ||||||
| 
 | 
 | ||||||
| void Initialize() | void Initialize() | ||||||
| { | { | ||||||
|  | @ -168,6 +169,39 @@ void Initialize() | ||||||
|       sqlite3_free(errorMessage); |       sqlite3_free(errorMessage); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    // Query database for WFOs
 | ||||||
|  |    rc = sqlite3_exec( | ||||||
|  |       db, | ||||||
|  |       "SELECT id, city_state FROM wfos", | ||||||
|  |       [](void* /* param */, | ||||||
|  |          int    columns, | ||||||
|  |          char** columnText, | ||||||
|  |          char** /* columnName */) -> int | ||||||
|  |       { | ||||||
|  |          int status = 0; | ||||||
|  | 
 | ||||||
|  |          if (columns == 2) | ||||||
|  |          { | ||||||
|  |             wfoMap_.emplace(columnText[0], columnText[1]); | ||||||
|  |          } | ||||||
|  |          else | ||||||
|  |          { | ||||||
|  |             logger_->error( | ||||||
|  |                "WFO database format error, invalid number of columns: {}", | ||||||
|  |                columns); | ||||||
|  |             status = -1; | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          return status; | ||||||
|  |       }, | ||||||
|  |       nullptr, | ||||||
|  |       &errorMessage); | ||||||
|  |    if (rc != SQLITE_OK) | ||||||
|  |    { | ||||||
|  |       logger_->error("SQL error: {}", errorMessage); | ||||||
|  |       sqlite3_free(errorMessage); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    // Close database
 |    // Close database
 | ||||||
|    sqlite3_close(db); |    sqlite3_close(db); | ||||||
| 
 | 
 | ||||||
|  | @ -230,6 +264,16 @@ const std::unordered_map<std::string, std::string>& GetStates() | ||||||
|    return stateMap_; |    return stateMap_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | const std::unordered_map<std::string, std::string>& GetWFOs() | ||||||
|  | { | ||||||
|  |    return wfoMap_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const std::string& GetWFOName(const std::string& wfoId) | ||||||
|  | { | ||||||
|  |    return wfoMap_.at(wfoId); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace CountyDatabase
 | } // namespace CountyDatabase
 | ||||||
| } // namespace config
 | } // namespace config
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
|  |  | ||||||
|  | @ -19,6 +19,8 @@ std::string GetCountyName(const std::string& id); | ||||||
| std::unordered_map<std::string, std::string> | std::unordered_map<std::string, std::string> | ||||||
| GetCounties(const std::string& state); | GetCounties(const std::string& state); | ||||||
| const std::unordered_map<std::string, std::string>& GetStates(); | const std::unordered_map<std::string, std::string>& GetStates(); | ||||||
|  | const std::unordered_map<std::string, std::string>& GetWFOs(); | ||||||
|  | const std::string& GetWFOName(const std::string& wfoId); | ||||||
| 
 | 
 | ||||||
| } // namespace CountyDatabase
 | } // namespace CountyDatabase
 | ||||||
| } // namespace config
 | } // namespace config
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak