root/OpenSceneGraph/trunk/src/osgDB/DatabaseRevisions.cpp @ 13041

Revision 13041, 4.7 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
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#include <osgDB/DatabaseRevisions>
15#include <osgDB/FileUtils>
16#include <osgDB/FileNameUtils>
17#include <osgDB/ReadFile>
18#include <osgDB/WriteFile>
19
20using namespace osgDB;
21
22////////////////////////////////////////////////////////////////////////////////////////////
23//
24// FilelList
25//
26FileList::FileList()
27{
28}
29
30FileList::FileList(const FileList& fileList, const osg::CopyOp):
31    _files(fileList._files)
32{
33}
34
35FileList::~FileList()
36{
37}
38
39bool FileList::removeFile(const std::string& filename)
40{
41    FileNames::iterator itr = _files.find(filename);
42    if (itr==_files.end()) return false;
43
44    _files.erase(itr);
45    return true;
46}
47
48void FileList::append(FileList* fileList)
49{
50    for(FileNames::iterator itr = fileList->_files.begin();
51        itr != fileList->_files.end();
52        ++itr)
53    {
54        _files.insert(*itr);
55    }
56}
57
58
59////////////////////////////////////////////////////////////////////////////////////////////
60//
61// DatabaseRevision
62//
63DatabaseRevision::DatabaseRevision()
64{
65}
66
67DatabaseRevision::DatabaseRevision(const DatabaseRevision& revision, const osg::CopyOp):
68    _databasePath(revision._databasePath),
69    _filesAdded(revision._filesAdded),
70    _filesRemoved(revision._filesRemoved),
71    _filesModified(revision._filesModified)
72{
73}
74
75DatabaseRevision::~DatabaseRevision()
76{
77}
78
79bool DatabaseRevision::isFileBlackListed(const std::string& filename) const
80{
81    OSG_INFO<<"DatabaseRevision("<<getName()<<")::isFileBlackListed("<<filename<<")"<<std::endl;
82
83    if (_databasePath.length()>=filename.length()) return false;
84    if (filename.compare(0,_databasePath.length(), _databasePath)!=0) return false;
85
86    std::string localPath(filename,
87                         _databasePath.empty() ? 0 : _databasePath.length()+1,
88                         std::string::npos);
89
90    return (_filesRemoved.valid() && _filesRemoved->containsFile(localPath)) ||
91           (_filesModified.valid() && _filesModified->containsFile(localPath));
92}
93
94
95bool DatabaseRevision::removeFile(const std::string& filename)
96{
97    bool removed = false;
98    if (_filesAdded.valid()) removed = _filesAdded->removeFile(filename) | removed;
99    if (_filesRemoved.valid()) removed = _filesRemoved->removeFile(filename) | removed;
100    if (_filesModified.valid()) removed = _filesModified->removeFile(filename) | removed;
101    return removed;
102}
103
104////////////////////////////////////////////////////////////////////////////////////////////
105//
106// DatabaseRevisions
107//
108DatabaseRevisions::DatabaseRevisions()
109{
110}
111
112DatabaseRevisions::DatabaseRevisions(const DatabaseRevisions& revisions, const osg::CopyOp):
113    _databasePath(revisions._databasePath),
114    _revisionList(revisions._revisionList)
115{
116}
117
118DatabaseRevisions::~DatabaseRevisions()
119{
120}
121
122void DatabaseRevisions::addRevision(DatabaseRevision* revision)
123{
124    if (!revision) return;
125
126    for(DatabaseRevisionList::iterator itr = _revisionList.begin();
127        itr != _revisionList.end();
128        ++itr)
129    {
130        if (*itr == revision) return;
131        if ((*itr)->getName()==revision->getName())
132        {
133            (*itr) = revision;
134            return;
135        }
136    }
137
138    _revisionList.push_back(revision);
139}
140
141void DatabaseRevisions::removeRevision(DatabaseRevision* revision)
142{
143    for(DatabaseRevisionList::iterator itr = _revisionList.begin();
144        itr != _revisionList.end();
145        ++itr)
146    {
147        if (*itr == revision)
148        {
149            _revisionList.erase(itr);
150            return;
151        }
152    }
153}
154
155bool DatabaseRevisions::isFileBlackListed(const std::string& filename) const
156{
157    for(DatabaseRevisionList::const_iterator itr = _revisionList.begin();
158        itr != _revisionList.end();
159        ++itr)
160    {
161        if ((*itr)->isFileBlackListed(filename))
162        {
163            OSG_INFO<<"File is black listed "<<filename<<std::endl;
164            return true;
165        }
166    }
167    return false;
168}
169
170bool DatabaseRevisions::removeFile(const std::string& filename)
171{
172    OSG_INFO<<"Remove file "<<filename<<std::endl;
173
174    bool removed = false;
175    for(DatabaseRevisionList::iterator itr = _revisionList.begin();
176        itr != _revisionList.end();
177        ++itr)
178    {
179        removed = (*itr)->removeFile(filename) | removed;
180    }
181    return removed;
182}
Note: See TracBrowser for help on using the browser.