2012-02-11 13:58:26 -05:00
|
|
|
// Copyright (c) 2011 Bryan Schumaker.
|
2012-10-31 08:38:14 -04:00
|
|
|
#include <library.h>
|
2012-09-12 08:15:31 -04:00
|
|
|
#include <track.h>
|
|
|
|
#include <print.h>
|
2011-12-28 22:02:10 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return positive value if s1 > s2
|
|
|
|
* Return negative value if s1 < s2
|
|
|
|
* Return 0 s1 == s2
|
|
|
|
*/
|
|
|
|
static inline int compare_strings(string *s1, string *s2)
|
|
|
|
{
|
|
|
|
/* List empty strings last */
|
|
|
|
if (*s1 == "")
|
|
|
|
return 1;
|
|
|
|
if (*s2 == "")
|
|
|
|
return -1;
|
|
|
|
return s1->compare(*s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace libsaria
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Return true if this < cmp_track */
|
2012-03-18 19:32:20 -04:00
|
|
|
bool Track::operator<(Track &cmp_track)
|
2011-12-28 22:02:10 -05:00
|
|
|
{
|
2012-03-18 19:32:20 -04:00
|
|
|
int cmp;
|
2011-12-28 22:02:10 -05:00
|
|
|
|
|
|
|
/* Compare artists */
|
2012-03-18 19:32:20 -04:00
|
|
|
cmp = compare_strings(artist_lc, cmp_track.artist_lc);
|
2011-12-28 22:02:10 -05:00
|
|
|
if (cmp < 0)
|
|
|
|
return true;
|
|
|
|
else if (cmp > 0)
|
2012-03-18 19:32:20 -04:00
|
|
|
return false;
|
2011-12-28 22:02:10 -05:00
|
|
|
|
|
|
|
/* Compare albums */
|
2012-03-18 19:32:20 -04:00
|
|
|
cmp = compare_strings(album_lc, cmp_track.album_lc);
|
2011-12-28 22:02:10 -05:00
|
|
|
if (cmp < 0)
|
|
|
|
return true;
|
|
|
|
else if (cmp > 0)
|
2012-03-18 19:32:20 -04:00
|
|
|
return false;
|
2011-12-28 22:02:10 -05:00
|
|
|
|
|
|
|
/* Compare tracks */
|
2012-03-18 19:32:20 -04:00
|
|
|
return track < cmp_track.track;
|
|
|
|
}
|
2011-12-28 22:02:10 -05:00
|
|
|
|
|
|
|
}
|