ShapeArchive.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2003-2005 The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "ShapeArchive.h"
00022 #include "Shape.h"
00023 #include "Palette.h"
00024 #include "ConvertShape.h"
00025 
00026 DEFINE_RUNTIME_CLASSTYPE_CODE(ShapeArchive,Pentagram::Archive);
00027 
00028 ShapeArchive::~ShapeArchive()
00029 {
00030         Archive::uncache();
00031 }
00032 
00033 Shape* ShapeArchive::getShape(uint32 shapenum)
00034 {
00035         if (shapenum >= count) return 0;
00036         cache(shapenum);
00037 
00038         return shapes[shapenum];
00039 }
00040 
00041 void ShapeArchive::cache(uint32 shapenum)
00042 {
00043         if (shapenum >= count) return;
00044         if (shapes.empty()) shapes.resize(count);
00045 
00046         if (shapes[shapenum]) return;
00047 
00048         uint32 shpsize;
00049         uint8 *data = getRawObject(shapenum, &shpsize);
00050 
00051         if (!data || shpsize == 0) return;
00052 
00053         // Auto detect format
00054         if (!format) {
00055                 format = Shape::DetectShapeFormat(data,shpsize);
00056                 if (format) pout << "Detected Shape Format: " << format->name << std::endl;
00057         }
00058         
00059         if (!format)
00060         {
00061                 delete [] data;
00062                 perr << "Error: Unable to detect shape format for flex." << std::endl;
00063                 return;
00064         }
00065 
00066         Shape* shape = new Shape(data, shpsize, format, id, shapenum);
00067         if (palette) shape->setPalette(palette);
00068 
00069         shapes[shapenum] = shape;
00070 }
00071 
00072 void ShapeArchive::uncache(uint32 shapenum)
00073 {
00074         if (shapenum >= count) return;
00075         if (shapes.empty()) return;
00076 
00077         delete shapes[shapenum];
00078         shapes[shapenum] = 0;
00079 }
00080 
00081 bool ShapeArchive::isCached(uint32 shapenum)
00082 {
00083         if (shapenum >= count) return false;
00084         if (shapes.empty()) return false;
00085 
00086         return (shapes[shapenum] != 0);
00087 }

Generated on Fri Jul 27 22:27:36 2007 for pentagram by  doxygen 1.4.7