summaryrefslogtreecommitdiffstats
path: root/fastlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-01-27 23:10:03 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-01-27 23:10:03 +0000
commit117cd771441cf1b8cc1f93541f8868e0b1b8e46e (patch)
tree3fc27f8c6233648cb65693ca4bc61120b5033a3e /fastlib
parent184f37836ae30b7c468dd4b1305695939ed92357 (diff)
Hide Fast_BufferedFile better.
Diffstat (limited to 'fastlib')
-rw-r--r--fastlib/src/vespa/fastlib/io/bufferedfile.cpp73
-rw-r--r--fastlib/src/vespa/fastlib/io/bufferedfile.h29
2 files changed, 35 insertions, 67 deletions
diff --git a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
index d93dbd74ee1..56ffbf40eca 100644
--- a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
+++ b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
@@ -13,7 +13,7 @@ const size_t MIN_ALIGNMENT = 0x1000;
}
void
-Fast_BufferedFile::flushWriteBuf(void)
+Fast_BufferedFile::flushWriteBuf()
{
if (_bufi != buf()) {
_file->WriteBuf(buf(), _bufi - buf());
@@ -31,7 +31,7 @@ Fast_BufferedFile::flushWriteBuf(void)
}
void
-Fast_BufferedFile::fillReadBuf(void)
+Fast_BufferedFile::fillReadBuf()
{
size_t toread = std::min(static_cast<int64_t>(_buf.size()), _fileleft);
if (toread > 0) {
@@ -71,20 +71,14 @@ Fast_BufferedFile::addNum(unsigned int num, int fieldw, char fill)
}
}
-uint64_t
-Fast_BufferedFile::BytesLeft(void) const
-{
- return _fileleft + (_bufe - _bufi);
-}
-
bool
-Fast_BufferedFile::Eof(void) const
+Fast_BufferedFile::Eof() const
{
return _fileleft == 0 && _bufi == _bufe;
}
int64_t
-Fast_BufferedFile::GetSize (void)
+Fast_BufferedFile::GetSize()
{
return _file->GetSize();
}
@@ -101,41 +95,41 @@ Fast_BufferedFile::SetSize (int64_t s)
}
bool
-Fast_BufferedFile::IsOpened (void) const
+Fast_BufferedFile::IsOpened () const
{
return _file->IsOpened();
}
bool
-Fast_BufferedFile::Sync(void)
+Fast_BufferedFile::Sync()
{
Flush();
return _file->Sync();
}
time_t
-Fast_BufferedFile::GetModificationTime(void)
+Fast_BufferedFile::GetModificationTime()
{
time_t retval = _file->GetModificationTime();
return retval;
}
void
-Fast_BufferedFile::EnableDirectIO(void)
+Fast_BufferedFile::EnableDirectIO()
{
_file->EnableDirectIO();
_directIOEnabled = true;
}
void
-Fast_BufferedFile::EnableSyncWrites(void)
+Fast_BufferedFile::EnableSyncWrites()
{
FastOS_FileInterface::EnableSyncWrites();
_file->EnableSyncWrites();
}
int64_t
-Fast_BufferedFile::GetPosition(void)
+Fast_BufferedFile::GetPosition()
{
if (_file->IsWriteMode()) {
int64_t filePosition = _file->GetPosition();
@@ -147,7 +141,7 @@ Fast_BufferedFile::GetPosition(void)
void
-Fast_BufferedFile::Flush(void)
+Fast_BufferedFile::Flush()
{
if (_file->IsWriteMode()) {
flushWriteBuf();
@@ -202,7 +196,7 @@ Fast_BufferedFile::SetPosition(const int64_t s)
}
const char *
-Fast_BufferedFile::GetFileName(void) const
+Fast_BufferedFile::GetFileName() const
{
return _file ? _file->GetFileName() : "";
}
@@ -233,7 +227,7 @@ Fast_BufferedFile::ReadLine(char *line, size_t buflen)
continue;
}
*p++ = *_bufi++;
- *p++ = 0;
+ *p = 0;
return line;
}
}
@@ -294,22 +288,11 @@ Fast_BufferedFile::WriteByte(char byte)
*_bufi++ = byte;
}
-int
-Fast_BufferedFile::GetByte(void)
-{
- if (_bufi < _bufe)
- return *reinterpret_cast<unsigned char *>(_bufi++);
- fillReadBuf();
- if (_bufi < _bufe)
- return *reinterpret_cast<unsigned char *>(_bufi++);
- return -1;
-}
-
void
Fast_BufferedFile::ReadOpenExisting(const char *name)
{
- Close();
- bool ok = _file->OpenReadOnlyExisting(true, name);
+ bool ok = Close();
+ ok &= _file->OpenReadOnlyExisting(true, name);
if (!ok) {
fprintf(stderr, "ERROR opening %s for read: %s",
_file->GetFileName(), getLastErrorString().c_str());
@@ -325,8 +308,8 @@ Fast_BufferedFile::ReadOpenExisting(const char *name)
void
Fast_BufferedFile::ReadOpen(const char *name)
{
- Close();
- bool ok = _file->OpenReadOnly(name);
+ bool ok = Close();
+ ok &= _file->OpenReadOnly(name);
if (!ok) {
fprintf(stderr, "ERROR opening %s for read: %s",
_file->GetFileName(), getLastErrorString().c_str());
@@ -345,8 +328,8 @@ Fast_BufferedFile::ReadOpen(const char *name)
void
Fast_BufferedFile::WriteOpen(const char *name)
{
- Close();
- bool ok = _file->OpenWriteOnly(name);
+ bool ok = Close();
+ ok &= _file->OpenWriteOnly(name);
if (!ok) {
fprintf(stderr, "ERROR opening %s for write: %s",
_file->GetFileName(), getLastErrorString().c_str());
@@ -377,7 +360,7 @@ namespace {
size_t computeBufLen(size_t buflen)
{
- size_t bitCount(0);
+ size_t bitCount;
for ( bitCount = 1; buflen >> bitCount; bitCount++);
buflen = 1 << (bitCount - 1);
@@ -402,21 +385,21 @@ Fast_BufferedFile::Fast_BufferedFile(FastOS_FileInterface *file, size_t bufferSi
ResetBuf();
}
-Fast_BufferedFile::~Fast_BufferedFile(void)
+Fast_BufferedFile::~Fast_BufferedFile()
{
bool close_ok = Close();
assert(close_ok);
}
void
-Fast_BufferedFile::ResetBuf(void)
+Fast_BufferedFile::ResetBuf()
{
_bufi = buf();
_bufe = _bufi;
}
bool
-Fast_BufferedFile::Close(void)
+Fast_BufferedFile::Close()
{
Flush();
_openFlags = 0;
@@ -426,14 +409,14 @@ Fast_BufferedFile::Close(void)
bool Fast_BufferedFile::Open(unsigned int openFlags, const char * name)
{
- bool ok = false;
+ bool ok;
if (openFlags & FASTOS_FILE_OPEN_READ) {
- Close();
+ ok = Close();
_filepos = 0;
_fileleft = 0;
ResetBuf();
- ok = _file->Open(openFlags, name);
+ ok &= _file->Open(openFlags, name);
if (ok) {
_openFlags = openFlags;
//CASTWARN
@@ -442,10 +425,10 @@ bool Fast_BufferedFile::Open(unsigned int openFlags, const char * name)
// caller will have to check return value
}
} else {
- Close();
+ ok = Close();
_filepos = 0;
ResetBuf();
- ok = _file->Open(FASTOS_FILE_OPEN_WRITE | openFlags, name);
+ ok &= _file->Open(FASTOS_FILE_OPEN_WRITE | openFlags, name);
if (ok) {
_openFlags = FASTOS_FILE_OPEN_WRITE | openFlags;
} else {
diff --git a/fastlib/src/vespa/fastlib/io/bufferedfile.h b/fastlib/src/vespa/fastlib/io/bufferedfile.h
index 78c19ef8169..48f90262ad9 100644
--- a/fastlib/src/vespa/fastlib/io/bufferedfile.h
+++ b/fastlib/src/vespa/fastlib/io/bufferedfile.h
@@ -26,7 +26,6 @@ private:
/** True if the file should be read using direct IO */
bool _directIOEnabled;
- void setupDirectIOAlign();
char * buf() { return static_cast<char *>(_buf.get()); }
protected:
/** The file instance used for low-level file access. */
@@ -51,7 +50,7 @@ public:
/**
* Delete the file instance used for low-level file access.
**/
- virtual ~Fast_BufferedFile(void);
+ virtual ~Fast_BufferedFile();
/**
* Open an existing file for reading.
*
@@ -75,13 +74,13 @@ public:
* Reset the internal start and end pointers to the
* head of the buffer, thus "emptying" it.
*/
- void ResetBuf(void);
+ void ResetBuf();
/**
* Write the buffer to the file. Caution: Uses obsolete
* FastOS_FileInterface::WriteBuf.
* Allocates a 32kB buffer if not previously allocated.
*/
- void flushWriteBuf(void);
+ void flushWriteBuf();
/**
* Read from the file into the buffer. Allocates a 32kB
* buffer if not previously allocated. Fills the buffer,
@@ -90,7 +89,7 @@ public:
* Caution: If the amount read is smaller than the expected
* amount, the method will abort.
*/
- void fillReadBuf(void);
+ void fillReadBuf();
/**
* Read the next line of the buffered file into a buffer,
* reading from the file as necessary.
@@ -131,13 +130,7 @@ public:
* @param byte The byte to write.
*/
void WriteByte(char byte);
- /**
- * Get one byte from the buffered file, reading from
- * the file if necessary.
- *
- * @return int The byte read, or -1 if not read.
- */
- int GetByte(void);
+
/**
* Add an unsigned int number as ASCII text in base 10 to the buffered
* file using a fixed width with a designated fill character.
@@ -148,22 +141,14 @@ public:
* for instance '0' or ' '.
*/
void addNum(unsigned int num, int fieldw, char fill);
- /**
- * Get the number of bytes left to read from the buffered
- * file. This is the sum of bytes left in the buffer, and
- * the number of bytes left in the file that has not yet
- * been read into the buffer.
- *
- * @return The number of bytes left.
- */
- uint64_t BytesLeft(void) const;
+
/**
* Test for end of file.
*
* @return bool True if all bytes have been read from the
* buffered file.
*/
- bool Eof(void) const;
+ bool Eof() const;
/**
* Get the size of the file.
*