Languages.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <assert.h>
  17. #include <string.h>
  18. #include "Languages.h"
  19. Language::Language(){
  20. id = 0;
  21. memset(name, 0, sizeof(name));
  22. save_needed = false;
  23. }
  24. Language::Language(Language* language){
  25. id = language->id;
  26. strncpy(name, language->GetName(), sizeof(name));
  27. save_needed = language->save_needed;
  28. }
  29. MasterLanguagesList::MasterLanguagesList(){
  30. }
  31. MasterLanguagesList::~MasterLanguagesList(){
  32. Clear();
  33. }
  34. // don't bother calling this beyond its deconstructor its not thread-safe
  35. void MasterLanguagesList::Clear(){
  36. list<Language*>::iterator itr;
  37. Language* language = 0;
  38. for(itr = languages_list.begin(); itr != languages_list.end(); itr++){
  39. language = *itr;
  40. safe_delete(language);
  41. }
  42. languages_list.clear();
  43. }
  44. int32 MasterLanguagesList::Size(){
  45. return languages_list.size();
  46. }
  47. void MasterLanguagesList::AddLanguage(Language* language){
  48. assert(language);
  49. languages_list.push_back(language);
  50. }
  51. Language* MasterLanguagesList::GetLanguage(int32 id){
  52. list<Language*>::iterator itr;
  53. Language* language = 0;
  54. Language* ret = 0;
  55. for(itr = languages_list.begin(); itr != languages_list.end(); itr++){
  56. language = *itr;
  57. if(language->GetID() == id){
  58. ret = language;
  59. break;
  60. }
  61. }
  62. return ret;
  63. }
  64. Language* MasterLanguagesList::GetLanguageByName(const char* name){
  65. list<Language*>::iterator itr;
  66. Language* language = 0;
  67. Language* ret = 0;
  68. for(itr = languages_list.begin(); itr != languages_list.end(); itr++){
  69. language = *itr;
  70. if(!language)
  71. continue;
  72. if(!strncmp(language->GetName(), name, strlen(name))){
  73. ret = language;
  74. break;
  75. }
  76. }
  77. return ret;
  78. }
  79. list<Language*>* MasterLanguagesList::GetAllLanguages(){
  80. return &languages_list;
  81. }
  82. PlayerLanguagesList::PlayerLanguagesList(){
  83. }
  84. PlayerLanguagesList::~PlayerLanguagesList(){
  85. }
  86. void PlayerLanguagesList::Add(Language* language){
  87. player_languages_list.push_back(language);
  88. }
  89. Language* PlayerLanguagesList::GetLanguage(int32 id){
  90. list<Language*>::iterator itr;
  91. Language* language = 0;
  92. Language* ret = 0;
  93. for(itr = player_languages_list.begin(); itr != player_languages_list.end(); itr++){
  94. language = *itr;
  95. if(language->GetID() == id){
  96. ret = language;
  97. break;
  98. }
  99. }
  100. return ret;
  101. }
  102. Language* PlayerLanguagesList::GetLanguageByName(const char* name){
  103. list<Language*>::iterator itr;
  104. Language* language = 0;
  105. Language* ret = 0;
  106. for(itr = player_languages_list.begin(); itr != player_languages_list.end(); itr++){
  107. language = *itr;
  108. if(!language)
  109. continue;
  110. if(!strncmp(language->GetName(), name, strlen(name))){
  111. ret = language;
  112. break;
  113. }
  114. }
  115. return ret;
  116. }
  117. list<Language*>* PlayerLanguagesList::GetAllLanguages(){
  118. return &player_languages_list;
  119. }