Commit 7e6680c8 authored by daniel_e's avatar daniel_e
Browse files

New little utility template to manage a dynamically allocated array.

* src/miscutils.h (ScopedArray<>): New little utility template to manage
a dynamically allocated array.

* src/fileio.cc (load_iochannel): Ditch Glib::ScopedPtr<> (glibmm internal :)
in favor of Util::ScopedArray<>.
parent ba8b1061
2002-12-25 Daniel Elstner <daniel.elstner@gmx.net>
* src/miscutils.h (ScopedArray<>): New little utility template
to manage a dynamically allocated array.
* src/fileio.cc (load_iochannel): Ditch Glib::ScopedPtr<> (glibmm
internal :) in favor of Util::ScopedArray<>.
2002-12-20 Daniel Elstner <daniel.elstner@gmx.net>
* src/fileio.cc (load_iochannel): Use std::memchr() rather than
......
......@@ -20,6 +20,7 @@
#include "fileio.h"
#include "filebuffer.h"
#include "miscutils.h"
#include "stringutils.h"
#include <glib.h>
......@@ -40,12 +41,12 @@ Glib::RefPtr<FileBuffer> load_iochannel(const Glib::RefPtr<Glib::IOChannel>& inp
const Glib::RefPtr<FileBuffer> text_buffer = FileBuffer::create();
FileBuffer::iterator text_end (text_buffer->end());
const Glib::ScopedPtr<char> inbuf (g_new(char, BUFSIZE));
const Util::ScopedArray<char> inbuf (new char[BUFSIZE]);
gsize bytes_read = 0;
while(input->read(inbuf.get(), BUFSIZE, bytes_read) == Glib::IO_STATUS_NORMAL)
{
if(std::memchr(inbuf.get(), '\0', bytes_read))
if(std::memchr(inbuf.get(), '\0', bytes_read)) // binary file?
return Glib::RefPtr<FileBuffer>();
text_end = text_buffer->insert(text_end, inbuf.get(), inbuf.get() + bytes_read);
......
......@@ -25,6 +25,23 @@
namespace Util
{
template <class T>
class ScopedArray
{
private:
T* array_;
ScopedArray(const ScopedArray<T>&);
ScopedArray<T>& operator=(const ScopedArray<T>&);
public:
explicit ScopedArray(T* array) : array_ (array) {}
~ScopedArray() { delete[] array_; }
T* get() const { return array_; }
};
/* next() and prior(): Idea shamelessly stolen from boost.
*/
template <class Iterator>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment