playlist: Create the initial playlist class

Right now it just knows the value of its flags variable.  More to come
soon!

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-12-22 17:24:09 -05:00 committed by Anna Schumaker
parent 9aa2bc7df1
commit 2d13b74c12
8 changed files with 110 additions and 1 deletions

1
config
View File

@ -40,6 +40,7 @@ class Config:
self.GROUP = False
self.IDLE = False
self.LIBRARY = False
self.PLAYLIST = False
self.TEST = TEST
self.reconfigure()

26
include/playlist.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#ifndef OCARINA_PLAYLIST_H
#define OCARINA_PLAYLIST_H
enum playlist_flags {
PL_ENABLED = (1 << 0),
PL_RANDOM = (1 << 1),
PL_LOCKED = (1 << 2),
};
class Playlist {
private:
unsigned int flags;
public:
Playlist(playlist_flags);
~Playlist();
void set_flag(playlist_flags);
void unset_flag(playlist_flags);
const unsigned int get_flags();
};
#endif /* OCARINA_PLAYLIST_H */

View File

@ -21,6 +21,7 @@ modules = {
"GROUP" : Module("group.cpp", depends = [ "DATABASE" ]),
"IDLE" : Module("idle.cpp"),
"LIBRARY" : Module("library.cpp", package = "taglib", depends = [ "DATABASE", "IDLE" ]),
"PLAYLIST" : Module("playlist.cpp", depends = [ "FILE" ]),
###########################
###########################

29
lib/playlist.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <playlist.h>
Playlist :: Playlist(playlist_flags f)
: flags(f)
{
}
Playlist :: ~Playlist()
{
}
void Playlist :: set_flag(playlist_flags f)
{
flags |= f;
}
void Playlist :: unset_flag(playlist_flags f)
{
flags &= ~f;
}
const unsigned int Playlist :: get_flags()
{
return flags;
}

View File

@ -57,7 +57,8 @@ rm_test_dir(xdg.BaseDirectory.xdg_data_home);
#
# Read SConscript files
#
scripts = [ "database", "file", "filter", "group", "idle", "index", "library", "print" ]
scripts = [ "database", "file", "filter", "group", "idle", "index", "library",
"playlist", "print" ]
for s in scripts:
CONFIG.reset(TEST = True)
SConscript("%s/Sconscript" % s)

View File

@ -0,0 +1,6 @@
#!/usr/bin/python
Import("Test", "CONFIG")
CONFIG.PLAYLIST = True
Test("playlist", "playlist.cpp")

View File

@ -0,0 +1,39 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <playlist.h>
#include <print.h>
#include <string>
void test_flags(const std :: string &test, Playlist &plist, unsigned int expected)
{
print("%s: ", test.c_str());
if (plist.get_flags() == expected)
print("SUCCESS\n");
else
print("FAILED\n");
}
/* Test flag setting / unsetting / getting */
void test_0()
{
Playlist plist(PL_ENABLED);
test_flags("0a", plist, PL_ENABLED);
plist.set_flag(PL_RANDOM);
test_flags("0b", plist, PL_ENABLED | PL_RANDOM);
plist.set_flag(PL_ENABLED);
test_flags("0c", plist, PL_ENABLED | PL_RANDOM);
plist.unset_flag(PL_ENABLED);
test_flags("0d", plist, PL_RANDOM);
plist.unset_flag(PL_RANDOM);
test_flags("0f", plist, 0);
print("\n");
}
int main(int argc, char **argv)
{
test_0();
return 0;
}

View File

@ -0,0 +1,6 @@
0a: SUCCESS
0b: SUCCESS
0c: SUCCESS
0d: SUCCESS
0f: SUCCESS