GenericTag: Create a generic tag that other tag classes can use
This implements the basics so I don't need to keep reimplementing everything. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a1432a66e1
commit
fb4f523206
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/filter.h>
|
||||||
|
#include <core/tags/generic.h>
|
||||||
|
|
||||||
|
GenericTag :: GenericTag() {}
|
||||||
|
|
||||||
|
GenericTag :: GenericTag(const std::string &name)
|
||||||
|
: _name(name), _lower(filter :: lowercase(name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string GenericTag :: primary_key() const
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenericTag :: read(File &file)
|
||||||
|
{
|
||||||
|
_name = file.getline();
|
||||||
|
_lower = filter :: lowercase(_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenericTag :: write(File &file)
|
||||||
|
{
|
||||||
|
file << _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &GenericTag :: name()
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &GenericTag :: lowercase()
|
||||||
|
{
|
||||||
|
return _lower;
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_CORE_TAGS_GENERIC_H
|
||||||
|
#define OCARINA_CORE_TAGS_GENERIC_H
|
||||||
|
|
||||||
|
#include <core/database.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GenericTag class implements the basic functions that all
|
||||||
|
* tag classes need. All other tag structures should inherit
|
||||||
|
* from this class to have access to all the basic features.
|
||||||
|
*
|
||||||
|
* When writing a GenericTag to disk, only the _name field needs
|
||||||
|
* to be written.
|
||||||
|
*
|
||||||
|
* ... << name1
|
||||||
|
* ... << name2
|
||||||
|
* ... << name3
|
||||||
|
|
||||||
|
*/
|
||||||
|
class GenericTag : public DatabaseEntry {
|
||||||
|
private:
|
||||||
|
std::string _name; /**< The name associated with this tag. */
|
||||||
|
std::string _lower; /**< The lowercase form of ::_name. */
|
||||||
|
|
||||||
|
public:
|
||||||
|
GenericTag(); /**< GenericTag constructor. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic tag constructor.
|
||||||
|
*
|
||||||
|
* @param name Name to associate with this tag.
|
||||||
|
*/
|
||||||
|
GenericTag(const std::string &);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to access the generic tag's primary key.
|
||||||
|
*
|
||||||
|
* @return ::_name.
|
||||||
|
*/
|
||||||
|
virtual const std::string primary_key() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read ::_name from file and find the lowercase form.
|
||||||
|
*
|
||||||
|
* @param file The file to read from.
|
||||||
|
*/
|
||||||
|
virtual void read(File &);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write ::_name to file.
|
||||||
|
*
|
||||||
|
* @param file The file to write to.
|
||||||
|
*/
|
||||||
|
virtual void write(File &);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to access the name associated with this tag.
|
||||||
|
*
|
||||||
|
* @return ::_name.
|
||||||
|
*/
|
||||||
|
const std::string &name();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to access the lowercase form of ::_name.
|
||||||
|
*
|
||||||
|
* @return ::_lower.
|
||||||
|
*/
|
||||||
|
const std::string &lowercase();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* OCARINA_CORE_TAGS_GENERIC_H */
|
|
@ -14,6 +14,7 @@ test( "index" )
|
||||||
test( "filter" )
|
test( "filter" )
|
||||||
test( "idle" )
|
test( "idle" )
|
||||||
|
|
||||||
|
test( "tags/generic" )
|
||||||
test( "tags/artist" )
|
test( "tags/artist" )
|
||||||
|
|
||||||
test_env.UsePackage("taglib")
|
test_env.UsePackage("taglib")
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
artist
|
artist
|
||||||
|
generic
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/tags/generic.h>
|
||||||
|
#include <tests/test.h>
|
||||||
|
|
||||||
|
static void test_generic_tag()
|
||||||
|
{
|
||||||
|
GenericTag tag("Generic Tag");
|
||||||
|
File f("generic_tag", 0);
|
||||||
|
|
||||||
|
test_equal(tag.name(), (std::string)"Generic Tag");
|
||||||
|
test_equal(tag.lowercase(), (std::string)"generic tag");
|
||||||
|
test_equal(tag.primary_key(), (std::string)"Generic Tag");
|
||||||
|
|
||||||
|
f.open(OPEN_WRITE);
|
||||||
|
tag.write(f);
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
tag = GenericTag();
|
||||||
|
test_equal(tag.name(), (std::string)"");
|
||||||
|
test_equal(tag.lowercase(), (std::string)"");
|
||||||
|
test_equal(tag.primary_key(), (std::string)"");
|
||||||
|
|
||||||
|
f.open(OPEN_READ);
|
||||||
|
tag.read(f);
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
test_equal(tag.name(), (std::string)"Generic Tag");
|
||||||
|
test_equal(tag.lowercase(), (std::string)"generic tag");
|
||||||
|
test_equal(tag.primary_key(), (std::string)"Generic Tag");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
run_test("Generic Tag Test", test_generic_tag);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue