RawArchive.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2005 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (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 "RawArchive.h"
00022 #include "IDataSource.h"
00023 #include "ArchiveFile.h"
00024 
00025 DEFINE_RUNTIME_CLASSTYPE_CODE(RawArchive,Pentagram::Archive);
00026 
00027 RawArchive::~RawArchive()
00028 {
00029         Archive::uncache();
00030 }
00031 
00032 void RawArchive::cache(uint32 index)
00033 {
00034         if (index >= count) return;
00035         if (objects.empty()) objects.resize(count);
00036 
00037         if (objects[index]) return;
00038 
00039         objects[index] = getRawObject(index);
00040 }
00041 
00042 void RawArchive::uncache(uint32 index)
00043 {
00044         if (index >= count) return;
00045         if (objects.empty()) return;
00046 
00047         if (objects[index]) {
00048                 delete[] objects[index];
00049                 objects[index] = 0;
00050         }
00051 }
00052 
00053 bool RawArchive::isCached(uint32 index)
00054 {
00055         if (index >= count) return false;
00056         if (objects.empty()) return false;
00057 
00058         return (objects[index] != 0);
00059 }
00060 
00061 const uint8* RawArchive::get_object_nodel(uint32 index)
00062 {
00063         if (index >= count) return 0;
00064         cache(index);
00065         return objects[index];
00066 }
00067 
00068 uint8* RawArchive::get_object(uint32 index)
00069 {
00070         if (index >= count) return 0;
00071 
00072         if (index < objects.size() && objects[index]) {
00073                 // already cached
00074                 uint32 size = getRawSize(index);
00075                 if (size == 0) return 0;
00076                 uint8* object = new uint8[size];
00077                 std::memcpy(object, objects[index], size);
00078                 return object;
00079         }
00080 
00081         return getRawObject(index);
00082 }
00083 
00084 uint32 RawArchive::get_size(uint32 index)
00085 {
00086         if (index >= count) return 0;
00087         return getRawSize(index);
00088 }
00089 
00090 IDataSource* RawArchive::get_datasource(uint32 index)
00091 {
00092         if (index >= count) return 0;
00093         cache(index);
00094 
00095         if (!objects[index]) return 0;
00096 
00097         return new IBufferDataSource(objects[index], getRawSize(index));
00098 }

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