Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

iconrepository.cpp

Go to the documentation of this file.
00001 
00005 /*
00006     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00007     Copyright (C) 1994-2003  Martin Bickel  and  Marc Schellenberger
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; see the file COPYING. If not, write to the 
00021     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00022     Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include <stdio.h>                           
00026 #include <cstring>
00027 #include <stdlib.h>
00028 #include <SDL_image.h>
00029 
00030 #include "iconrepository.h"
00031 #include "basestrm.h"
00032 #include "messaginghub.h"
00033 
00034 
00035 IconRepository::Repository IconRepository::repository;
00036 
00037 Surface& IconRepository::getIcon( const ASCString& name )
00038 {
00039   Repository::iterator i = repository.find( name );
00040   if ( i != repository.end() ) 
00041      return *i->second;
00042   else {
00043      try {
00044         tnfilestream fs ( name, tnstream::reading );
00045         if ( name.endswith(".raw") ) {
00046            repository[name] = new Surface();
00047            repository[name]->read( fs );
00048         } else {
00049            repository[name] = new Surface ( IMG_Load_RW ( SDL_RWFromStream( &fs ), 1));
00050         }
00051         return *repository[name];
00052      }
00053      catch ( tfileerror err ) {
00054         errorMessage("could not load " + err.getFileName() );
00055         if ( name != "dummy.png" )
00056            return getIcon( "dummy.png" );
00057         else
00058            throw;
00059      }
00060   }
00061 }
00062 
00063 IconRepository::Repository::~Repository()
00064 {
00065    for (   Repository::iterator i = repository.begin(); i != repository.end(); ++i )
00066       delete i->second;
00067 }
00068 
00069 bool IconRepository::exists( const ASCString& name )
00070 {
00071    return repository.find(name) != repository.end();
00072 }
00073 
00074 void IconRepository::insert( const ASCString& name, Surface* s )
00075 {
00076    repository[name] = s;
00077 }
00078 
00079 int IconRepository::getMemoryFootprint()
00080 {
00081    int size = 0;
00082    for ( Repository::iterator i = repository.begin(); i != repository.end(); ++i  )
00083       size += i->second->getMemoryFootprint();
00084    return size;
00085 }
00086 

Generated on Tue Jun 24 01:27:44 2008 for Advanced Strategic Command by  doxygen 1.4.2