ocarina/lib/tags.cpp

201 lines
2.5 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <tags.h>
#include <filter.h>
#include <sstream>
Database<Artist> artist_db("artist.db", true);
Database<Album> album_db("album.db", true);
Database<Genre> genre_db("genre.db", true);
Database<Library> library_db("library.db", true);
/**
*
* Artist tag
*
*/
Artist :: Artist() {}
Artist :: Artist(const std::string &s)
: name(s), lower(filter :: lowercase(name))
{
}
const std::string Artist :: primary_key()
{
return name;
}
void Artist :: read(File &f)
{
name = f.getline();
lower = filter :: lowercase(name);
}
void Artist :: write(File &f)
{
f << name;
}
/**
*
* Album tag
*
*/
Album :: Album() {}
Album :: Album(const std::string &s, unsigned int y)
: name(s), lower(filter :: lowercase(name)), year(y)
{
}
const std::string Album :: primary_key()
{
std::stringstream ss;
ss << year << "." << name;
return ss.str();
}
void Album :: read(File &f)
{
f >> year;
name = f.getline();
lower = filter :: lowercase(name);
}
void Album :: write(File &f)
{
f << year << " " << name;
}
/**
*
* Genre tag
*
*/
Genre :: Genre() {}
Genre :: Genre(const std::string &s)
: name(s), lower(filter :: lowercase(name))
{
}
const std::string Genre :: primary_key()
{
return name;
}
void Genre :: read(File &f)
{
name = f.getline();
lower = filter :: lowercase(name);
}
void Genre :: write(File &f)
{
f << name;
}
/**
*
* Library tag
*
*/
Library :: Library()
: count(0), enabled(false)
{
}
Library :: Library(const std::string &s)
: root_path(s), count(0), enabled(true)
{
}
const std::string Library :: primary_key()
{
return root_path;
}
void Library :: read(File &f)
{
f >> enabled;
root_path = f.getline();
}
void Library :: write(File &f)
{
f << enabled << " " << root_path;
}
/**
*
* Track tag
*
*/
Track :: Track() {}
Track :: Track(const std::string &f, Library *l)
: library(l), play_count(0), last_year(0), last_month(0), last_day(0),
filepath(f.substr(l->root_path.size() + 1))
{
}
const std::string Track :: primary_key()
{
return path();
}
void Track :: read(File &f)
{
}
void Track :: write(File &f)
{
}
void Track :: tag()
{
}
const std::string Track :: path()
{
return library->root_path + "/" + filepath;
}
bool Track :: less_than(Track *rhs, sort_t field)
{
return false;
}
/**
*
* Tagdb functions
*
*/
Library *tagdb :: add_library(const std::string &filepath)
{
Database<Library>::iterator it = library_db.insert(Library(filepath));
return &(*it);
}