| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 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 |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGDB_FILECACHE |
|---|
| 15 | #define OSGDB_FILECACHE 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/Node> |
|---|
| 18 | |
|---|
| 19 | #include <osgDB/ReaderWriter> |
|---|
| 20 | #include <osgDB/DatabaseRevisions> |
|---|
| 21 | |
|---|
| 22 | #include <set> |
|---|
| 23 | |
|---|
| 24 | namespace osgDB { |
|---|
| 25 | |
|---|
| 26 | class OSGDB_EXPORT FileCache : public osg::Referenced |
|---|
| 27 | { |
|---|
| 28 | public: |
|---|
| 29 | |
|---|
| 30 | FileCache(const std::string& path); |
|---|
| 31 | |
|---|
| 32 | const std::string& getFileCachePath() const { return _fileCachePath; } |
|---|
| 33 | |
|---|
| 34 | virtual bool isFileAppropriateForFileCache(const std::string& originalFileName) const; |
|---|
| 35 | |
|---|
| 36 | virtual std::string createCacheFileName(const std::string& originalFileName) const; |
|---|
| 37 | |
|---|
| 38 | virtual bool existsInCache(const std::string& originalFileName) const; |
|---|
| 39 | |
|---|
| 40 | virtual ReaderWriter::ReadResult readImage(const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 41 | virtual ReaderWriter::WriteResult writeImage(const osg::Image& image, const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 42 | |
|---|
| 43 | virtual ReaderWriter::ReadResult readObject(const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 44 | virtual ReaderWriter::WriteResult writeObject(const osg::Object& object, const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 45 | |
|---|
| 46 | virtual ReaderWriter::ReadResult readHeightField(const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 47 | virtual ReaderWriter::WriteResult writeHeightField(const osg::HeightField& hf, const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 48 | |
|---|
| 49 | virtual ReaderWriter::ReadResult readNode(const std::string& originalFileName, const osgDB::Options* options, bool buildKdTreeIfRequired=true) const; |
|---|
| 50 | virtual ReaderWriter::WriteResult writeNode(const osg::Node& node, const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 51 | |
|---|
| 52 | virtual ReaderWriter::ReadResult readShader(const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 53 | virtual ReaderWriter::WriteResult writeShader(const osg::Shader& shader, const std::string& originalFileName, const osgDB::Options* options) const; |
|---|
| 54 | |
|---|
| 55 | bool loadDatabaseRevisionsForFile(const std::string& originanlFileName); |
|---|
| 56 | |
|---|
| 57 | typedef std::list< osg::ref_ptr<DatabaseRevisions> > DatabaseRevisionsList; |
|---|
| 58 | DatabaseRevisionsList& getDatabaseRevisionsList() { return _databaseRevisionsList; } |
|---|
| 59 | |
|---|
| 60 | bool isCachedFileBlackListed(const std::string& originalFileName) const; |
|---|
| 61 | |
|---|
| 62 | protected: |
|---|
| 63 | |
|---|
| 64 | virtual ~FileCache(); |
|---|
| 65 | |
|---|
| 66 | std::string _fileCachePath; |
|---|
| 67 | |
|---|
| 68 | DatabaseRevisionsList _databaseRevisionsList; |
|---|
| 69 | |
|---|
| 70 | FileList* readFileList(const std::string& originalFileName) const; |
|---|
| 71 | bool removeFileFromBlackListed(const std::string& originalFileName) const; |
|---|
| 72 | |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | #endif |
|---|