From f5a92d6cc39ea15ea8aa4cc35ee742a646b12508 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Jan 2013 01:36:28 +0100 Subject: Directory: add constructor and destructor --- src/Directory.cxx | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'src/Directory.cxx') diff --git a/src/Directory.cxx b/src/Directory.cxx index c2c5d281..b67ad3de 100644 --- a/src/Directory.cxx +++ b/src/Directory.cxx @@ -36,8 +36,8 @@ extern "C" { #include #include -static Directory * -directory_allocate(const char *path) +inline Directory * +Directory::Allocate(const char *path) { assert(path != NULL); @@ -46,30 +46,21 @@ directory_allocate(const char *path) (Directory *)g_malloc0(sizeof(*directory) - sizeof(directory->path) + path_size); - INIT_LIST_HEAD(&directory->children); - INIT_LIST_HEAD(&directory->songs); - INIT_LIST_HEAD(&directory->playlists); - - memcpy(directory->path, path, path_size); + new(directory) Directory(path); return directory; } -Directory * -Directory::NewGeneric(const char *path, Directory *parent) +Directory::Directory(const char *_path) { - assert(path != NULL); - assert((*path == 0) == (parent == NULL)); - - Directory *directory = directory_allocate(path); - - directory->parent = parent; + INIT_LIST_HEAD(&children); + INIT_LIST_HEAD(&songs); + INIT_LIST_HEAD(&playlists); - return directory; + strcpy(path, _path); } -void -Directory::Free() +Directory::~Directory() { playlist_vector_deinit(&playlists); @@ -80,7 +71,25 @@ Directory::Free() Directory *child, *n; directory_for_each_child_safe(child, n, this) child->Free(); +} +Directory * +Directory::NewGeneric(const char *path, Directory *parent) +{ + assert(path != NULL); + assert((*path == 0) == (parent == NULL)); + + Directory *directory = Allocate(path); + + directory->parent = parent; + + return directory; +} + +void +Directory::Free() +{ + this->Directory::~Directory(); g_free(this); } -- cgit v1.2.3