Added new osgDB::Archive class, and osgarchive example. These are both

very early beginnings so do not function yet.
This commit is contained in:
Robert Osfield
2004-10-25 19:16:38 +00:00
parent b62ef99fd9
commit 66836ef3d0
9 changed files with 378 additions and 22 deletions

View File

@@ -135,6 +135,7 @@ endif
EXAMPLE_DIRS = \
osganimate\
osgarchive\
osgautotransform\
osgbillboard\
osgcallback\

View File

@@ -459,6 +459,27 @@ Package=<4>
###############################################################################
Project: "Example osgarchive"=.\examples\osgarchive\osgarchive.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Core osg
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgDB
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgUtil
End Project Dependency
}}}
###############################################################################
Project: "Example osgcopy"=.\examples\osgcopy\osgcopy.dsp - Package Owner=<4>
Package=<5>

View File

@@ -0,0 +1,97 @@
# Microsoft Developer Studio Project File - Name="Example osgarchive" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Example osgarchive - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "osgarchive.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "osgarchive.mak" CFG="Example osgarchive - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Example osgarchive - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Example osgarchive - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Example osgarchive - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm200 /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 OpenThreadsWin32.lib opengl32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgarchive.exe" /libpath:"../../../lib" /libpath:"../../../../OpenThreads/lib/win32" /libpath:"../../../../Producer/lib" /libpath:"../../../../3rdParty/lib"
!ELSEIF "$(CFG)" == "Example osgarchive - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 OpenThreadsWin32d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgarchived.exe" /pdbtype:sept /libpath:"../../../lib" /libpath:"../../../../OpenThreads/lib/win32" /libpath:"../../../../Producer/lib" /libpath:"../../../../3rdParty/lib"
# SUBTRACT LINK32 /incremental:no
!ENDIF
# Begin Target
# Name "Example osgarchive - Win32 Release"
# Name "Example osgarchive - Win32 Debug"
# Begin Source File
SOURCE=..\..\..\examples\osgarchive\osgarchive.cpp
# End Source File
# End Target
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Project

View File

@@ -95,6 +95,10 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\src\osgDB\Archive.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgDB\DatabasePager.cpp
# End Source File
# Begin Source File
@@ -167,6 +171,10 @@ SOURCE=..\..\Src\osgDB\WriteFile.cpp
# PROP Default_Filter ";h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\..\Include\osgDB\Archive
# End Source File
# Begin Source File
SOURCE=..\..\Include\osgDB\DatabasePager
# End Source File
# Begin Source File

View File

@@ -0,0 +1,18 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgarchive.cpp\
LIBS += -losgProducer -lProducer -losgDB -losgUtil -losg $(GDAL_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\
GNUmakefile.inst=GNUmakefile
EXEC = osgarchive
INC += $(X_INC)
include $(TOPDIR)/Make/makerules

View File

@@ -0,0 +1,13 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgarchive.cpp\
LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgarchive
INC += $(X_INC)
include $(TOPDIR)/Make/makerules

View File

@@ -0,0 +1,98 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial applications,
* as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <osg/ArgumentParser>
#include <osg/ApplicationUsage>
#include <osgDB/Archive>
#include <iostream>
int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
// set up the usage document, in case we need to print out how to use this program.
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
// create DataSet.
osgDB::Archive::Status status;
// if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help"))
{
arguments.getApplicationUsage()->write(std::cout);
return 1;
}
std::string archiveFilename;
while (arguments.read("-a",archiveFilename) || arguments.read("--archive",archiveFilename))
{
}
bool insert = false;
while (arguments.read("-i") || arguments.read("--insert"))
{
insert = true;
}
bool extract = false;
while (arguments.read("-e") || arguments.read("--extract"))
{
extract = true;
}
bool list = false;
while (arguments.read("-l") || arguments.read("--list"))
{
list = true;
}
typedef std::vector<std::string> FileNameList;
FileNameList files;
for(int pos=1;pos<arguments.argc();++pos)
{
if (!arguments.isOption(pos))
{
files.push_back(arguments[pos]);
}
}
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();
// report any errors if they have occured when parsing the program aguments.
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return 1;
}
if (archiveFilename.empty())
{
std::cout<<"Please specify an archive name using --archive filename"<<std::endl;
return 1;
}
if (!insert && !extract && !list)
{
std::cout<<"Please specify an operation on the archive, either --insert, --extract or --list"<<std::endl;
return 1;
}
return 0;
}

View File

@@ -16,49 +16,76 @@
#include <osgDB/ReaderWriter>
#include <fstream>
namespace osgDB {
/** Base class for implementing database Archives. */
class OSGDB_EXPORT Archive : public ReaderWriter
{
public:
Archive();
virtual ~Archive();
virtual const char* className() { return "Archive" };
virtual const char* libraryName() const { return "osgDB"; }
virtual const char* className() const { return "Archive"; }
virtual bool acceptsExtension(const std::string& /*extension*/) { return true; }
enum Status
{
READ,
WRITE
};
/** open the archive.*/
virtual void open(const std::string& filename) {}
virtual void create(const std::string& filename, unsigned int indexBlockSize=4096);
/** open the archive.*/
virtual void open(const std::string& filename, Status status);
/** close the archive.*/
virtual void close() {}
virtual void close();
/** return true if file exists in archive.*/
virtual bool fileExists(const std::string& filename) const {}
virtual bool fileExists(const std::string& filename) const;
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readImage(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readHeightField(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readNode(const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL);
virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readObject(std::istream& fin,const Options* options=NULL);
virtual ReadResult readImage(std::istream& fin,const Options* options=NULL);
virtual ReadResult readHeightField(std::istream& fin,const Options* options=NULL);
virtual ReadResult readNode(std::istream& fin,const Options* options=NULL);
virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeObject(const osg::Object& obj,std::ostream& fout,const Options* options=NULL);
virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options* options=NULL);
virtual WriteResult writeHeightField(const osg::HeightField& heightField,std::ostream& fout,const Options* options=NULL);
virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* options=NULL);
protected:
typedef std::istream::pos_type pos_type;
typedef std::map<std::string, pos_type> FileNamePositionMap;
Status _status;
std::ifstream _input;
std::ofstream _output;
FileNamePositionMap _indexMap;
};

73
src/osgDB/Archive.cpp Normal file
View File

@@ -0,0 +1,73 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osgDB/Archive>
using namespace osgDB;
Archive::Archive()
{
}
Archive::~Archive()
{
close();
}
void Archive::create(const std::string& filename, unsigned int indexBlockSize)
{
}
void Archive::open(const std::string& filename, Status status)
{
if (status==READ)
{
_input.open(filename.c_str());
}
else // status==WRITE
{
_input.open(filename.c_str());
}
}
void Archive::close()
{
_input.close();
_output.close();
}
bool Archive::fileExists(const std::string& filename) const
{
return (_indexMap.count(filename)!=0);
}
ReaderWriter::ReadResult Archive::readObject(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readImage(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readHeightField(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readNode(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options*) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readObject(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readImage(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readHeightField(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::ReadResult Archive::readNode(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options*) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }