ocarina/core/tags/library.cpp

91 lines
1.3 KiB
C++

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/tags/library.h>
static Database<Library> library_db("library.db", true);
Library :: Library()
: _size(0), _enabled(false)
{
}
Library :: Library(const std::string &path)
: _size(0), _path(path), _enabled(true)
{
}
const std::string Library :: primary_key() const
{
return _path;
}
void Library :: read(File &file)
{
file >> _enabled;
_path = file.getline();
}
void Library :: write(File &file)
{
file << _enabled << " " << _path;
}
const bool Library :: enabled()
{
return _enabled;
}
void Library :: set_enabled(bool enabled)
{
_enabled = enabled;
library_db.save();
}
const unsigned int Library :: size()
{
return _size;
}
void Library :: inc_size()
{
_size++;
}
void Library :: dec_size()
{
_size--;
}
void tags :: init_library_db()
{
library_db.load();
}
Library *tags :: get_library(const std::string &path)
{
Library *ret = library_db.find(path);
if (ret)
return ret;
return library_db.insert(Library(path));
}
Library *tags :: get_library(const unsigned int index)
{
return library_db.at(index);
}
void tags :: remove_library(Library *library)
{
if (library)
library_db.remove(library->index());
}
unsigned int tags :: library_size()
{
return library_db.actual_size();
}