Archive 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef OSGDB_ARCHIVE
  14. #define OSGDB_ARCHIVE 1
  15. #include <osgDB/ReaderWriter>
  16. #include <osgDB/Registry>
  17. #include <osgDB/FileUtils>
  18. #include <fstream>
  19. #include <list>
  20. namespace osgDB {
  21. /** Base class for implementing database Archives. See src/osgPlugins/osga for an example of a concrete implementation. */
  22. class OSGDB_EXPORT Archive : public ReaderWriter
  23. {
  24. public:
  25. Archive();
  26. virtual ~Archive();
  27. virtual const char* libraryName() const { return "osgDB"; }
  28. virtual const char* className() const { return "Archive"; }
  29. virtual bool acceptsExtension(const std::string& /*extension*/) const { return true; }
  30. /** close the archive.*/
  31. virtual void close() = 0;
  32. /** Get the file name which represents the archived file.*/
  33. virtual std::string getArchiveFileName() const = 0;
  34. /** Get the file name which represents the master file recorded in the Archive.*/
  35. virtual std::string getMasterFileName() const = 0;
  36. /** return true if file exists in archive.*/
  37. virtual bool fileExists(const std::string& filename) const = 0;
  38. /** return type of file. */
  39. virtual FileType getFileType(const std::string& filename) const = 0;
  40. typedef osgDB::DirectoryContents FileNameList;
  41. /** Get the full list of file names available in the archive.*/
  42. virtual bool getFileNames(FileNameList& fileNames) const = 0;
  43. /** return the contents of a directory.
  44. * returns an empty array on any error.*/
  45. virtual DirectoryContents getDirectoryContents(const std::string& dirName) const;
  46. virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) const = 0;
  47. virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const = 0;
  48. virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) const = 0;
  49. virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) const = 0;
  50. virtual ReadResult readShader(const std::string& /*fileName*/,const Options* =NULL) const = 0;
  51. virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
  52. virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
  53. virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
  54. virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
  55. virtual WriteResult writeShader(const osg::Shader& /*shader*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
  56. };
  57. /** Open an archive for reading or writing.*/
  58. OSGDB_EXPORT Archive* openArchive(const std::string& filename, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint=4096);
  59. /** Open an archive for reading or writing.*/
  60. OSGDB_EXPORT Archive* openArchive(const std::string& filename, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint,Options* options);
  61. }
  62. #endif // OSGDB_ARCHIVE