diff options
author | Max Kellermann <max@duempel.org> | 2013-01-03 01:36:28 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-03 01:36:28 +0100 |
commit | f5a92d6cc39ea15ea8aa4cc35ee742a646b12508 (patch) | |
tree | 0797bc80790ce919880a43bb032bd991fe7b2a4b /src/Directory.cxx | |
parent | 3e8047e5831b4cc7dabae596746066698ad7c8cd (diff) | |
download | mpd-f5a92d6cc39ea15ea8aa4cc35ee742a646b12508.tar.gz mpd-f5a92d6cc39ea15ea8aa4cc35ee742a646b12508.tar.xz mpd-f5a92d6cc39ea15ea8aa4cc35ee742a646b12508.zip |
Directory: add constructor and destructor
Diffstat (limited to 'src/Directory.cxx')
-rw-r--r-- | src/Directory.cxx | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/Directory.cxx b/src/Directory.cxx index c2c5d2816..b67ad3de8 100644 --- a/src/Directory.cxx +++ b/src/Directory.cxx @@ -36,8 +36,8 @@ extern "C" { #include <string.h> #include <stdlib.h> -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); } |