ArchiveFile.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2002-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 "ArchiveFile.h"
00022 #include "IDataSource.h"
00023 
00024 DEFINE_RUNTIME_CLASSTYPE_CODE_BASE_CLASS(ArchiveFile);
00025 
00026 //static
00027 bool ArchiveFile::extractIndexFromName(const std::string& name, uint32& index)
00028 {
00029         if (name.size() == 0) return false;
00030 
00031         char* endptr;
00032         long val;
00033 
00034         val = std::strtol(name.c_str(), &endptr, 10);
00035 
00036         // if remainder of name doesn't start with a '.', invalid name
00037         if (*endptr != '\0' && *endptr != '.') return false;
00038 
00039         if (val < 0) return false;
00040 
00041         index = static_cast<uint32>(val);
00042 
00043         return true;
00044 }
00045 
00046 IDataSource* ArchiveFile::getDataSource(uint32 index, bool is_text)
00047 {
00048         uint32 size;
00049         uint8* buf = getObject(index, &size);
00050 
00051         if (!buf) return 0;
00052 
00053         return new IBufferDataSource(buf, size, is_text, true);
00054 }
00055 
00056 IDataSource* ArchiveFile::getDataSource(const std::string& name, bool is_text)
00057 {
00058         uint32 size;
00059         uint8* buf = getObject(name, &size);
00060 
00061         if (!buf) return 0;
00062 
00063         return new IBufferDataSource(buf, size, is_text, true);
00064 }
00065 

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