LangImpl.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <lang/LangImpl.h>
00022 #include <lang/ResourceBundleEntryImpl.h>
00023 #include <common/Defines.h>
00024 #include <SDL/SDL.h>
00025 #include <SDL/SDL_thread.h>
00026 
00027 static SDL_mutex *langMutex = 0;
00028 
00029 LangImpl::LangImpl()
00030 {
00031         langMutex = SDL_CreateMutex();
00032         init();
00033 }
00034 
00035 void LangImpl::init()
00036 {
00037         SDL_LockMutex(langMutex);
00038         ResourceBundle *langBundle = new ResourceBundle();
00039         langBundle->loadFromFile(S3D::getDataFile("data/lang/lang.resource"));
00040         bundles_.push_back(langBundle);
00041 
00042         bundles_.push_back(&undefinedBundle_);
00043         SDL_UnlockMutex(langMutex);
00044 }
00045 
00046 void LangImpl::saveUndefined()
00047 {
00048         undefinedBundle_.writeToFile(S3D::getDataFile("data/lang/lang_undefined.resource"));
00049 }
00050 
00051 ResourceBundleEntry *LangImpl::getEntry(
00052         const std::string &key, const std::string &value)
00053 {
00054         return getEntry(key, LANG_STRING(value));
00055 }
00056 
00057 ResourceBundleEntry *LangImpl::getEntry(
00058         const std::string &key, const LangString &value)
00059 {
00060         SDL_LockMutex(langMutex);
00061 
00062         ResourceBundleEntry *entry = 0;
00063         std::vector<ResourceBundle *>::iterator itor;
00064         for (itor = bundles_.begin();
00065                 itor != bundles_.end();
00066                 itor++)
00067         {
00068                 ResourceBundle *bundle = *itor;
00069                 entry = bundle->getEntry(key);
00070                 if (entry) break;
00071         }
00072         if (!entry) 
00073         {
00074                 entry = new ResourceBundleEntryImpl(key, value);
00075                 undefinedBundle_.addEntry(entry);
00076         }
00077 
00078         SDL_UnlockMutex(langMutex);
00079         return entry;
00080 }

Generated on Mon Feb 16 15:14:50 2009 for Scorched3D by  doxygen 1.5.3