1 // Generated by gtkmmproc -- DO NOT MODIFY!
4 #include <glibmm/fileutils.h>
5 #include <glibmm/private/fileutils_p.h>
8 /* $Id: fileutils.ccg,v 1.1 2003/01/07 16:58:25 murrayc Exp $ */
10 /* Copyright (C) 2002 The gtkmm Development Team
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <glib/gdir.h>
28 #include <glib/gfileutils.h>
29 #include <glib/gstrfuncs.h>
30 #include <glibmm/utility.h>
36 /**** Glib::Dir ************************************************************/
38 Dir::Dir(const std::string& path)
41 gobject_ = g_dir_open(path.c_str(), 0, &error);
44 Glib::Error::throw_exception(error);
47 Dir::Dir(GDir* gobject)
55 g_dir_close(gobject_);
58 std::string Dir::read_name()
60 const char *const name = g_dir_read_name(gobject_);
61 return (name) ? std::string(name) : std::string();
66 g_dir_rewind(gobject_);
73 g_dir_close(gobject_);
78 DirIterator Dir::begin()
80 g_dir_rewind(gobject_);
81 return DirIterator(gobject_, g_dir_read_name(gobject_));
84 DirIterator Dir::end()
86 return DirIterator(gobject_, 0);
90 /**** Glib::DirIterator ****************************************************/
92 DirIterator::DirIterator()
98 DirIterator::DirIterator(GDir* gobject, const char* current)
104 std::string DirIterator::operator*() const
106 return (current_) ? std::string(current_) : std::string();
109 DirIterator& DirIterator::operator++()
111 current_ = g_dir_read_name(gobject_);
115 void DirIterator::operator++(int)
117 current_ = g_dir_read_name(gobject_);
120 bool DirIterator::operator==(const DirIterator& rhs) const
122 return (current_ == rhs.current_);
125 bool DirIterator::operator!=(const DirIterator& rhs) const
127 return (current_ != rhs.current_);
131 bool file_test(const std::string& filename, FileTest test)
133 return g_file_test(filename.c_str(), static_cast<GFileTest>(unsigned(test)));
136 int mkstemp(std::string& filename_template)
138 const ScopedPtr<char> buf (g_strndup(filename_template.data(), filename_template.size()));
139 const int fileno = g_mkstemp(buf.get());
141 filename_template = buf.get();
145 int file_open_tmp(std::string& name_used, const std::string& prefix)
147 std::string basename_template (prefix);
148 basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface
151 ScopedPtr<char> buf_name_used;
153 const int fileno = g_file_open_tmp(basename_template.c_str(), buf_name_used.addr(), &error);
156 Glib::Error::throw_exception(error);
158 name_used = buf_name_used.get();
162 int file_open_tmp(std::string& name_used)
165 ScopedPtr<char> buf_name_used;
167 const int fileno = g_file_open_tmp(0, buf_name_used.addr(), &error);
170 Glib::Error::throw_exception(error);
172 name_used = buf_name_used.get();
176 std::string file_get_contents(const std::string& filename)
178 ScopedPtr<char> contents;
182 g_file_get_contents(filename.c_str(), contents.addr(), &length, &error);
185 Glib::Error::throw_exception(error);
187 return std::string(contents.get(), length);
195 } // anonymous namespace
198 Glib::FileError::FileError(Glib::FileError::Code error_code, const Glib::ustring& error_message)
200 Glib::Error (G_FILE_ERROR, error_code, error_message)
203 Glib::FileError::FileError(GError* gobject)
205 Glib::Error (gobject)
208 Glib::FileError::Code Glib::FileError::code() const
210 return static_cast<Code>(Glib::Error::code());
213 #ifdef GLIBMM_EXCEPTIONS_ENABLED
214 void Glib::FileError::throw_func(GError* gobject)
216 throw Glib::FileError(gobject);
219 //When not using exceptions, we just pass the Exception object around without throwing it:
220 std::auto_ptr<Glib::Error> Glib::FileError::throw_func(GError* gobject)
222 return std::auto_ptr<Glib::Error>(new Glib::FileError(gobject));
224 #endif //GLIBMM_EXCEPTIONS_ENABLED