Changeset 13041 for OpenSceneGraph/trunk/src/osgPlugins/osga/OSGA_Archive.h
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/osga/OSGA_Archive.h
r12638 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 19 19 #include <OpenThreads/ReentrantMutex> 20 20 21 #define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) 21 #define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) 22 22 23 23 class OSGA_Archive : public osgDB::Archive … … 25 25 public: 26 26 OSGA_Archive(); 27 virtual ~OSGA_Archive(); 27 virtual ~OSGA_Archive(); 28 28 29 29 virtual const char* libraryName() const { return "osga"; } … … 35 35 return osgDB::equalCaseInsensitive(extension,"osga"); 36 36 } 37 37 38 38 /** open the archive.*/ 39 39 virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096); … … 47 47 /** Get the file name which represents the archived file.*/ 48 48 virtual std::string getArchiveFileName() const { return _archiveFileName; } 49 49 50 50 /** Get the file name which represents the master file recorded in the Archive.*/ 51 51 virtual std::string getMasterFileName() const; 52 52 53 53 /** return true if file exists in archive.*/ 54 54 virtual bool fileExists(const std::string& filename) const; … … 90 90 /** Write an osg::Shader with specified file name to the Archive.*/ 91 91 virtual WriteResult writeShader(const osg::Shader& shader,const std::string& fileName,const Options* options=NULL) const; 92 92 93 93 #if defined(_MSC_VER) 94 94 typedef __int64 pos_type; … … 98 98 typedef unsigned long long size_type; 99 99 #endif 100 100 101 101 typedef std::pair<pos_type, size_type> PositionSizePair; 102 102 typedef std::map<std::string, PositionSizePair> FileNamePositionMap; 103 103 104 104 protected: 105 105 106 106 mutable OpenThreads::ReentrantMutex _serializerMutex; 107 107 … … 113 113 public: 114 114 IndexBlock(unsigned int blockSize=0); 115 115 116 116 inline pos_type getPosition() const { return _filePosition; } 117 117 … … 120 120 121 121 void setPositionNextIndexBlock(pos_type position); 122 122 123 123 inline pos_type getPositionNextIndexBlock() const { return _filePositionNextIndexBlock; } 124 124 125 125 126 126 static IndexBlock* read(std::istream& in, bool doEndianSwap); 127 127 128 128 std::string getFirstFileName() const; 129 129 130 130 bool getFileReferences(FileNamePositionMap& indexMap) const; 131 131 132 132 133 133 inline bool requiresWrite() const { return _requiresWrite; } 134 134 135 135 void write(std::ostream& out); 136 136 137 137 inline bool spaceAvailable(pos_type, size_type, const std::string& filename) const 138 138 { … … 140 140 return (_offsetOfNextAvailableSpace + requiredSize)<_blockSize; 141 141 } 142 142 143 143 bool addFileReference(pos_type position, size_type size, const std::string& filename); 144 144 145 145 146 146 147 147 protected: 148 148 149 149 void allocateData(unsigned int blockSize); 150 150 151 151 virtual ~IndexBlock(); 152 152 bool _requiresWrite; … … 158 158 char* _data; 159 159 }; 160 161 public: 160 161 public: 162 162 /** Functor used in internal implementations.*/ 163 163 struct ReadFunctor … … 187 187 const osgDB::ReaderWriter::Options* _options; 188 188 }; 189 189 190 190 protected: 191 191 struct ReadObjectFunctor; … … 205 205 osgDB::ReaderWriter::ReadResult read(const ReadFunctor& readFunctor); 206 206 osgDB::ReaderWriter::WriteResult write(const WriteFunctor& writeFunctor); 207 207 208 208 typedef std::list< osg::ref_ptr<IndexBlock> > IndexBlockList; 209 209 210 210 bool _open(std::istream& fin); 211 211 212 212 void writeIndexBlocks(); 213 213 214 214 bool addFileReference(pos_type position, size_type size, const std::string& fileName); 215 215 216 216 static float s_currentSupportedVersion; 217 217 float _version; … … 224 224 IndexBlockList _indexBlockList; 225 225 FileNamePositionMap _indexMap; 226 226 227 227 228 228 template <typename T> … … 231 231 std::copy(reinterpret_cast<const char*>(&value),reinterpret_cast<const char*>(&value)+sizeof(value),ptr); 232 232 } 233 233 234 234 template <typename T> 235 235 static inline void _read(char* ptr, T& value)
