aboutsummaryrefslogtreecommitdiffstats
path: root/src/DirectorySave.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 18:02:44 +0200
committerMax Kellermann <max@duempel.org>2013-09-04 18:14:22 +0200
commit29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch)
tree79766830b55ebca38ddbce84d8d548227eedb69e /src/DirectorySave.cxx
parentc9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff)
downloadmpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to '')
-rw-r--r--src/DirectorySave.cxx38
1 files changed, 15 insertions, 23 deletions
diff --git a/src/DirectorySave.cxx b/src/DirectorySave.cxx
index 1dcc36dbf..c00338182 100644
--- a/src/DirectorySave.cxx
+++ b/src/DirectorySave.cxx
@@ -24,6 +24,8 @@
#include "SongSave.hxx"
#include "PlaylistDatabase.hxx"
#include "TextFile.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <assert.h>
#include <string.h>
@@ -33,14 +35,7 @@
#define DIRECTORY_BEGIN "begin: "
#define DIRECTORY_END "end: "
-/**
- * The quark used for GError.domain.
- */
-static inline GQuark
-directory_quark(void)
-{
- return g_quark_from_static_string("directory");
-}
+static constexpr Domain directory_domain("directory");
void
directory_save(FILE *fp, const Directory *directory)
@@ -77,13 +72,13 @@ directory_save(FILE *fp, const Directory *directory)
static Directory *
directory_load_subdir(TextFile &file, Directory *parent, const char *name,
- GError **error_r)
+ Error &error)
{
bool success;
if (parent->FindChild(name) != nullptr) {
- g_set_error(error_r, directory_quark(), 0,
- "Duplicate subdirectory '%s'", name);
+ error.Format(directory_domain,
+ "Duplicate subdirectory '%s'", name);
return NULL;
}
@@ -91,8 +86,7 @@ directory_load_subdir(TextFile &file, Directory *parent, const char *name,
const char *line = file.ReadLine();
if (line == NULL) {
- g_set_error(error_r, directory_quark(), 0,
- "Unexpected end of file");
+ error.Set(directory_domain, "Unexpected end of file");
directory->Delete();
return NULL;
}
@@ -104,21 +98,19 @@ directory_load_subdir(TextFile &file, Directory *parent, const char *name,
line = file.ReadLine();
if (line == NULL) {
- g_set_error(error_r, directory_quark(), 0,
- "Unexpected end of file");
+ error.Set(directory_domain, "Unexpected end of file");
directory->Delete();
return NULL;
}
}
if (!g_str_has_prefix(line, DIRECTORY_BEGIN)) {
- g_set_error(error_r, directory_quark(), 0,
- "Malformed line: %s", line);
+ error.Format(directory_domain, "Malformed line: %s", line);
directory->Delete();
return NULL;
}
- success = directory_load(file, directory, error_r);
+ success = directory_load(file, directory, error);
if (!success) {
directory->Delete();
return NULL;
@@ -128,7 +120,7 @@ directory_load_subdir(TextFile &file, Directory *parent, const char *name,
}
bool
-directory_load(TextFile &file, Directory *directory, GError **error)
+directory_load(TextFile &file, Directory *directory, Error &error)
{
const char *line;
@@ -146,8 +138,8 @@ directory_load(TextFile &file, Directory *directory, GError **error)
Song *song;
if (directory->FindSong(name) != nullptr) {
- g_set_error(error, directory_quark(), 0,
- "Duplicate song '%s'", name);
+ error.Format(directory_domain,
+ "Duplicate song '%s'", name);
return false;
}
@@ -170,8 +162,8 @@ directory_load(TextFile &file, Directory *directory, GError **error)
g_free(name);
} else {
- g_set_error(error, directory_quark(), 0,
- "Malformed line: %s", line);
+ error.Format(directory_domain,
+ "Malformed line: %s", line);
return false;
}
}