doc: Remove superfluous comment already described in footnotes.
[mpd-mk.git] / src / directory.h
blob8207bd3a2873ee2967b3849ec5711b342f8daa01
1 /*
2 * Copyright (C) 2003-2009 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_DIRECTORY_H
21 #define MPD_DIRECTORY_H
23 #include "dirvec.h"
24 #include "songvec.h"
26 #include <stdbool.h>
27 #include <sys/types.h>
29 #define DIRECTORY_DIR "directory: "
31 #define DEVICE_INARCHIVE (unsigned)(-1)
32 #define DEVICE_CONTAINER (unsigned)(-2)
34 struct directory {
35 struct dirvec children;
36 struct songvec songs;
37 struct directory *parent;
38 time_t mtime;
39 ino_t inode;
40 dev_t device;
41 unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */
42 char path[sizeof(long)];
45 static inline bool
46 isRootDirectory(const char *name)
48 return name[0] == 0 || (name[0] == '/' && name[1] == 0);
51 struct directory *
52 directory_new(const char *dirname, struct directory *parent);
54 void
55 directory_free(struct directory *directory);
57 static inline bool
58 directory_is_empty(const struct directory *directory)
60 return directory->children.nr == 0 && directory->songs.nr == 0;
63 static inline const char *
64 directory_get_path(const struct directory *directory)
66 return directory->path;
69 /**
70 * Is this the root directory of the music database?
72 static inline bool
73 directory_is_root(const struct directory *directory)
75 return directory->parent == NULL;
78 /**
79 * Returns the base name of the directory.
81 const char *
82 directory_get_name(const struct directory *directory);
84 static inline struct directory *
85 directory_get_child(const struct directory *directory, const char *name)
87 return dirvec_find(&directory->children, name);
90 static inline struct directory *
91 directory_new_child(struct directory *directory, const char *name)
93 struct directory *subdir = directory_new(name, directory);
94 dirvec_add(&directory->children, subdir);
95 return subdir;
98 void
99 directory_prune_empty(struct directory *directory);
102 * Looks up a directory by its relative URI.
104 * @param directory the parent (or grandparent, ...) directory
105 * @param uri the relative URI
106 * @return the directory, or NULL if none was found
108 struct directory *
109 directory_lookup_directory(struct directory *directory, const char *uri);
112 * Looks up a song by its relative URI.
114 * @param directory the parent (or grandparent, ...) directory
115 * @param uri the relative URI
116 * @return the song, or NULL if none was found
118 struct song *
119 directory_lookup_song(struct directory *directory, const char *uri);
121 void
122 directory_sort(struct directory *directory);
125 directory_walk(struct directory *directory,
126 int (*forEachSong)(struct song *, void *),
127 int (*forEachDir)(struct directory *, void *),
128 void *data);
130 #endif