Browse Source

DataBuffer:

* Removed some debug lines
* Added FILE *interfacing functions:
** Added peek_from() functions
** Added pop_from() functions
** Added copy_to() functions
** Added push_to() functions
release/0.19
JustinAJ 10 years ago
parent
commit
4300bb47bc
  1. 68
      Jupiter/DataBuffer.cpp
  2. 48
      Jupiter/DataBuffer.h
  3. BIN
      Release/Jupiter.lib

68
Jupiter/DataBuffer.cpp

@ -74,13 +74,73 @@ Jupiter::DataBuffer::~DataBuffer()
void Jupiter::DataBuffer::push(const uint8_t *data, size_t size_) void Jupiter::DataBuffer::push(const uint8_t *data, size_t size_)
{ {
Jupiter::DataBuffer::secure(size_); Jupiter::DataBuffer::secure(size_);
fputs("Pushing: \"", stdout);
while (size_-- != 0) while (size_-- != 0)
{
fputc(*data, stdout);
*Jupiter::DataBuffer::end++ = *data++; *Jupiter::DataBuffer::end++ = *data++;
}
void Jupiter::DataBuffer::peek_from(FILE *file)
{
fpos_t pos;
fgetpos(file, &pos);
Jupiter::DataBuffer::pop_from(file);
fsetpos(file, &pos);
}
void Jupiter::DataBuffer::peek_from(FILE *file, size_t size_)
{
fpos_t pos;
fgetpos(file, &pos);
Jupiter::DataBuffer::pop_from(file, size_);
fsetpos(file, &pos);
}
void Jupiter::DataBuffer::pop_from(FILE *file)
{
size_t size_;
fread(&size_, sizeof(size_t), 1, file);
Jupiter::DataBuffer::pop_from(file, size_);
}
void Jupiter::DataBuffer::pop_from(FILE *file, size_t size_)
{
Jupiter::DataBuffer::secure(size_);
int chr;
while (size_-- != 0)
{
chr = fgetc(file);
if (chr == EOF)
break;
*Jupiter::DataBuffer::end++ = static_cast<uint8_t>(chr);
} }
puts("\""); }
void Jupiter::DataBuffer::copy_to(FILE *file)
{
fwrite(std::addressof<const size_t>(Jupiter::DataBuffer::size()), sizeof(size_t), 1, file);
Jupiter::DataBuffer::copy_to(file, Jupiter::DataBuffer::size());
}
void Jupiter::DataBuffer::copy_to(FILE *file, size_t size_)
{
fwrite(Jupiter::DataBuffer::head, sizeof(uint8_t), size_, file);
}
void Jupiter::DataBuffer::copy_to(FILE *file, size_t index, size_t size_)
{
fwrite(Jupiter::DataBuffer::head + index, sizeof(uint8_t), size_, file);
}
void Jupiter::DataBuffer::push_to(FILE *file)
{
Jupiter::DataBuffer::copy_to(file);
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base;
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head;
}
void Jupiter::DataBuffer::push_to(FILE *file, size_t size_)
{
Jupiter::DataBuffer::copy_to(file, size_);
Jupiter::DataBuffer::head += size_;
} }
size_t Jupiter::DataBuffer::shrink() size_t Jupiter::DataBuffer::shrink()

48
Jupiter/DataBuffer.h

@ -141,6 +141,54 @@ namespace Jupiter
*/ */
void push(const uint8_t *data, size_t size); void push(const uint8_t *data, size_t size);
/**
* @brief Peeks a DataBuffer from a file, and appends it to the buffer.
*
* @param file FILE to peek from
*/
void peek_from(FILE *file);
/**
* @brief Peeks data from a file, and pushes it to the buffer.
*
* @param file FILE to peek from
* @param size Number of octets to peek
*/
void peek_from(FILE *file, size_t size);
/**
* @brief Pops a DataBuffer from a file, and appends it to the buffer.
*
* @param file FILE to pop from
*/
void pop_from(FILE *file);
/**
* @brief Pops data from a file, and pushes it to the buffer.
*
* @param file FILE to pop from
* @param size Number of octets to pop
*/
void pop_from(FILE *file, size_t size);
/**
* @brief Copies the buffer to a file.
*
* @param file FILE to copy to
*/
void copy_to(FILE *file);
/**
* @brief Copies data from the buffer to a file.
*
* @param file FILE to copy to
* @param size Number of octets to copy
*/
void copy_to(FILE *file, size_t size);
void copy_to(FILE *file, size_t index, size_t size);
void push_to(FILE *file);
void push_to(FILE *file, size_t size);
/** /**
* @brief Shrinks the buffer to the smallest possible size. * @brief Shrinks the buffer to the smallest possible size.
* *

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save