#include "support/ExceptionMessage.h"
#include "support/debug.h"
-#include "support/filetools.h"
#include "support/FileName.h"
+#include "support/FileNameList.h"
+#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/Package.h"
}
-vector<string> const BufferList::getFileNames() const
+FileNameList const & BufferList::fileNames() const
{
- vector<string> nvec;
+ static FileNameList nvec;
+ nvec.clear();
transform(bstore.begin(), bstore.end(),
back_inserter(nvec),
- boost::bind(&Buffer::absFileName, _1));
+ boost::bind(&Buffer::fileName, _1));
return nvec;
}
bstore.end(), buf);
LASSERT(it != bstore.end(), /**/);
++it;
- if (it == bstore.end())
- return bstore.front();
- else
- return *it;
+ Buffer * nextbuf = (it == bstore.end()) ? bstore.front() : *it;
+ if (nextbuf->fileName().extension() == "internal")
+ return next(nextbuf);
+ return nextbuf;
}
BufferStorage::const_iterator it = find(bstore.begin(),
bstore.end(), buf);
LASSERT(it != bstore.end(), /**/);
- if (it == bstore.begin())
- return bstore.back();
- else
- return *(it - 1);
+
+ Buffer * previousbuf = (it == bstore.begin()) ? bstore.back() : *(it - 1);
+ if (previousbuf->fileName().extension() == "internal")
+ return previous(previousbuf);
+ return previousbuf;
}
bool BufferList::exists(FileName const & fname) const
{
- //FIXME: use Buffer::fileName()!
- string const s = fname.absFilename();
- return find_if(bstore.begin(), bstore.end(),
- bind(equal_to<string>(),
- bind(&Buffer::absFileName, _1),
- s))
- != bstore.end();
+ return getBuffer(fname) != 0;
}
}
-Buffer * BufferList::getBuffer(string const & s)
+Buffer * BufferList::getBuffer(support::FileName const & fname) const
{
- BufferStorage::iterator it =
- find_if(bstore.begin(), bstore.end(),
- bind(equal_to<string>(),
- bind(&Buffer::absFileName, _1),
- s));
-
+ BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(),
+ bind(equal_to<FileName>(), bind(&Buffer::fileName, _1), fname));
return it != bstore.end() ? (*it) : 0;
}
}
-int BufferList::bufferNum(string const & name) const
+int BufferList::bufferNum(FileName const & fname) const
{
- vector<string> buffers = getFileNames();
- vector<string>::const_iterator cit =
- find(buffers.begin(), buffers.end(), name);
+ FileNameList const & buffers = fileNames();
+ FileNameList::const_iterator cit =
+ find(buffers.begin(), buffers.end(), fname);
if (cit == buffers.end())
return 0;
return int(cit - buffers.begin());