NamedArchiveFile.h

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 #ifndef NAMEDARCHIVEFILE_H
00020 #define NAMEDARCHIVEFILE_H
00021 
00022 #include "ArchiveFile.h"
00023 
00024 class NamedArchiveFile : public ArchiveFile {
00025 public:
00026         ENABLE_RUNTIME_CLASSTYPE();
00027 
00028         NamedArchiveFile() : indexCount(0) { }
00029         virtual ~NamedArchiveFile() { }
00030 
00031         virtual bool exists(uint32 index) {
00032                 std::string name;
00033                 return (indexToName(index, name));
00034         }
00035         virtual bool exists(const std::string& name)=0;
00036 
00037         virtual uint8* getObject(uint32 index, uint32* size=0) {
00038                 std::string name;
00039                 if (!indexToName(index, name)) return 0;
00040                 return getObject(name, size);
00041         }
00042         virtual uint8* getObject(const std::string& name, uint32* size=0)=0;
00043 
00044         virtual uint32 getSize(uint32 index) {
00045                 std::string name;
00046                 if (!indexToName(index, name)) return 0;
00047                 return getSize(name);
00048         }
00049         virtual uint32 getSize(const std::string& name)=0;
00050 
00051         virtual uint32 getCount()=0;
00052 
00053         virtual uint32 getIndexCount() { return indexCount; }
00054 
00055         virtual bool isIndexed() const { return false; }
00056         virtual bool isNamed() const { return true; }
00057 
00058 protected:
00059         bool indexToName(uint32 index, std::string& name) {
00060                 std::map<uint32, std::string>::iterator iter;
00061                 iter = indexedNames.find(index);
00062                 if (iter == indexedNames.end()) return false;
00063                 name = iter->second;
00064                 return true;
00065         }
00066 
00067         void storeIndexedName(const std::string& name) {
00068                 uint32 index;
00069                 bool hasIndex = extractIndexFromName(name, index);
00070                 if (hasIndex) {
00071                         indexedNames[index] = name;
00072                         if (index >= indexCount) indexCount = index+1;
00073                 }
00074         }
00075 
00076         std::map<uint32, std::string> indexedNames;
00077         uint32 indexCount;
00078 };
00079 
00080 
00081 #endif

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