Languages.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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::Clear() {
  87. list<Language*>::iterator itr;
  88. Language* language = 0;
  89. Language* ret = 0;
  90. for(itr = player_languages_list.begin(); itr != player_languages_list.end(); itr++){
  91. language = *itr;
  92. safe_delete(language);
  93. }
  94. player_languages_list.clear();
  95. }
  96. void PlayerLanguagesList::Add(Language* language){
  97. player_languages_list.push_back(language);
  98. }
  99. Language* PlayerLanguagesList::GetLanguage(int32 id){
  100. list<Language*>::iterator itr;
  101. Language* language = 0;
  102. Language* ret = 0;
  103. for(itr = player_languages_list.begin(); itr != player_languages_list.end(); itr++){
  104. language = *itr;
  105. if(language->GetID() == id){
  106. ret = language;
  107. break;
  108. }
  109. }
  110. return ret;
  111. }
  112. Language* PlayerLanguagesList::GetLanguageByName(const char* name){
  113. list<Language*>::iterator itr;
  114. Language* language = 0;
  115. Language* ret = 0;
  116. for(itr = player_languages_list.begin(); itr != player_languages_list.end(); itr++){
  117. language = *itr;
  118. if(!language)
  119. continue;
  120. if(!strncmp(language->GetName(), name, strlen(name))){
  121. ret = language;
  122. break;
  123. }
  124. }
  125. return ret;
  126. }
  127. list<Language*>* PlayerLanguagesList::GetAllLanguages(){
  128. return &player_languages_list;
  129. }