Implemented DatabasePath in DatabaseBase revision classes

This commit is contained in:
Robert Osfield 2009-06-02 16:54:34 +00:00
parent 55ae7c05bc
commit 1f878303b4
5 changed files with 76 additions and 9 deletions

View File

@ -54,6 +54,9 @@ class OSGDB_EXPORT DatabaseRevision : public osg::Object
META_Object(osgDB, DatabaseRevision)
void setDatabasePath(const std::string& path) { _databasePath = path; }
const std::string& getDatabasePath() const { return _databasePath; }
typedef std::set<std::string> FileNames;
void setFilesAdded(FileList* fileList) { _filesAdded = fileList; }
@ -74,9 +77,11 @@ class OSGDB_EXPORT DatabaseRevision : public osg::Object
virtual ~DatabaseRevision();
osg::ref_ptr<FileList> _filesAdded;
osg::ref_ptr<FileList> _filesRemoved;
osg::ref_ptr<FileList> _filesModified;
std::string _databasePath;
osg::ref_ptr<FileList> _filesAdded;
osg::ref_ptr<FileList> _filesRemoved;
osg::ref_ptr<FileList> _filesModified;
};
class OSGDB_EXPORT DatabaseRevisions : public osg::Object
@ -90,6 +95,9 @@ class OSGDB_EXPORT DatabaseRevisions : public osg::Object
typedef std::vector< osg::ref_ptr<DatabaseRevision> > DatabaseRevisionList;
void setDatabasePath(const std::string& path) { _databasePath = path; }
const std::string& getDatabasePath() const { return _databasePath; }
void addRevision(DatabaseRevision* revision);
void removeRevision(DatabaseRevision* revision);
@ -102,7 +110,8 @@ class OSGDB_EXPORT DatabaseRevisions : public osg::Object
virtual ~DatabaseRevisions();
DatabaseRevisionList _revisionList;
std::string _databasePath;
DatabaseRevisionList _revisionList;
};
}

View File

@ -52,6 +52,7 @@ class OSGDB_EXPORT FileCache : public osg::Referenced
virtual ReaderWriter::ReadResult readShader(const std::string& originalFileName, const osgDB::Options* options) const;
virtual ReaderWriter::WriteResult writeShader(const osg::Shader& shader, const std::string& originalFileName, const osgDB::Options* options) const;
bool loadDatabaseRevisionsForFile(const std::string& originanlFileName);
typedef std::list< osg::ref_ptr<DatabaseRevisions> > DatabaseRevisionsList;
DatabaseRevisionsList& getDatabaseRevisionsList() { return _databaseRevisionsList; }

View File

@ -46,6 +46,7 @@ DatabaseRevision::DatabaseRevision()
}
DatabaseRevision::DatabaseRevision(const DatabaseRevision& revision, const osg::CopyOp):
_databasePath(revision._databasePath),
_filesAdded(revision._filesAdded),
_filesRemoved(revision._filesRemoved),
_filesModified(revision._filesModified)
@ -58,8 +59,19 @@ DatabaseRevision::~DatabaseRevision()
bool DatabaseRevision::isFileBlackListed(const std::string& filename) const
{
return (_filesRemoved.valid() && _filesRemoved->contains(filename)) ||
(_filesAdded.valid() && _filesAdded->contains(filename));
osg::notify(osg::NOTICE)<<"DatabaseRevision("<<getName()<<")::isFileBlackListed("<<filename<<")"<<std::endl;
if (_databasePath.length()>=filename.length()) return false;
if (filename.compare(0,_databasePath.length(), _databasePath)!=0) return false;
std::string localPath(filename,
_databasePath.empty() ? 0 : _databasePath.length()+1,
std::string::npos);
osg::notify(osg::NOTICE)<<" localPath = "<<localPath<<std::endl;
return (_filesRemoved.valid() && _filesRemoved->contains(localPath)) ||
(_filesModified.valid() && _filesModified->contains(localPath));
}
@ -72,6 +84,7 @@ DatabaseRevisions::DatabaseRevisions()
}
DatabaseRevisions::DatabaseRevisions(const DatabaseRevisions& revisions, const osg::CopyOp):
_databasePath(revisions._databasePath),
_revisionList(revisions._revisionList)
{
}
@ -119,7 +132,11 @@ bool DatabaseRevisions::isFileBlackListed(const std::string& filename) const
itr != _revisionList.end();
++itr)
{
if ((*itr)->isFileBlackListed(filename)) return true;
if ((*itr)->isFileBlackListed(filename))
{
osg::notify(osg::NOTICE)<<"File is black listed "<<filename<<std::endl;
return true;
}
}
return false;
}

View File

@ -53,7 +53,7 @@ std::string FileCache::createCacheFileName(const std::string& originalFileName)
bool FileCache::existsInCache(const std::string& originalFileName) const
{
if (osgDB::fileExists(createCacheFileName(originalFileName)))
{
{
return !isCachedFileBlackListed(originalFileName);
}
return false;
@ -228,6 +228,7 @@ ReaderWriter::WriteResult FileCache::writeShader(const osg::Shader& shader, cons
bool FileCache::isCachedFileBlackListed(const std::string& originalFileName) const
{
osg::notify(osg::NOTICE)<<"FileCache::isCachedFileBlackListed("<<originalFileName<<")"<<std::endl;
for(DatabaseRevisionsList::const_iterator itr = _databaseRevisionsList.begin();
itr != _databaseRevisionsList.end();
++itr)
@ -236,3 +237,28 @@ bool FileCache::isCachedFileBlackListed(const std::string& originalFileName) con
}
return false;
}
bool FileCache::loadDatabaseRevisionsForFile(const std::string& originalFileName)
{
osg::notify(osg::NOTICE)<<"FileCache::loadDatabaseRevisionsForFile("<<originalFileName<<")"<<std::endl;
std::string revisionsFileName = originalFileName;
if (getLowerCaseFileExtension(revisionsFileName)!="revisions") revisionsFileName += ".revisions";
osg::notify(osg::NOTICE)<<" revisionsFileName("<<revisionsFileName<<")"<<std::endl;
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(revisionsFileName);
DatabaseRevisions* dr = dynamic_cast<DatabaseRevisions*>(object.get());
if (dr)
{
osg::notify(osg::NOTICE)<<" loaded revisions File("<<revisionsFileName<<")"<<std::endl;
_databaseRevisionsList.push_back(dr);
return true;
}
else
{
osg::notify(osg::NOTICE)<<" failed to read revisions File, object.get()="<<object.get()<<std::endl;
return false;
}
}

View File

@ -50,6 +50,8 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
ReadResult readFileList(std::istream& fin, const std::string& name, const osgDB::ReaderWriter::Options* options) const
{
osg::notify(osg::NOTICE)<<" readFileList="<<name<<std::endl;
osg::ref_ptr<osgDB::FileList> fileList = new osgDB::FileList;
fileList->setName(name);
@ -57,6 +59,8 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
{
std::string filename;
fin >> filename;
osg::notify(osg::NOTICE)<<" ="<<filename<<std::endl;
if (!filename.empty()) fileList->getFileNames().insert(filename);
}
@ -74,24 +78,34 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
std::string revisions_path;
if (options && !(options->getDatabasePathList().empty())) revisions_path = options->getDatabasePathList().front();
revisions->setDatabasePath(revisions_path);
osg::notify(osg::NOTICE)<<"readRevisions="<<name<<std::endl;
osg::notify(osg::NOTICE)<<" revisions_path="<<revisions_path<<std::endl;
while(fin)
{
std::string filename;
fin >> filename;
osg::notify(osg::NOTICE)<<" filename="<<filename<<std::endl;
if (!filename.empty())
{
std::string ext = osgDB::getLowerCaseFileExtension(filename);
std::string revisionName = osgDB::getNameLessExtension(filename);
if (revisionName.empty())
if (!revisionName.empty())
{
osg::ref_ptr<osgDB::DatabaseRevision>& dbRevision = revisionMap[revisionName];
if (!dbRevision)
{
dbRevision = new osgDB::DatabaseRevision;
dbRevision->setName(revisionName);
dbRevision->setDatabasePath(revisions_path);
}
std::string complete_path = osgDB::concatPaths(revisions_path, filename);
osg::notify(osg::NOTICE)<<" complete_path="<<complete_path<<std::endl;
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(complete_path, options);
osgDB::FileList* fileList = dynamic_cast<osgDB::FileList*>(object.get());