mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Database: add tags method for getting set of tag names
The database class now separatly tracks tag information. So for the one place where all the inclusions were iterated over in order to build up a tag set, we now instead ask the database for this set directly. Related to issue #245
This commit is contained in:
parent
5dcf226d20
commit
b06b8cf8ae
5 changed files with 27 additions and 5 deletions
|
@ -260,6 +260,12 @@ std::vector <std::string> Database::files () const
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::set <std::string> Database::tags () const
|
||||||
|
{
|
||||||
|
return _tagInfoDatabase.tags ();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Return most recent line from database
|
// Return most recent line from database
|
||||||
std::string Database::firstLine ()
|
std::string Database::firstLine ()
|
||||||
|
|
|
@ -97,6 +97,7 @@ public:
|
||||||
void initialize (const std::string&, Journal& journal);
|
void initialize (const std::string&, Journal& journal);
|
||||||
void commit ();
|
void commit ();
|
||||||
std::vector <std::string> files () const;
|
std::vector <std::string> files () const;
|
||||||
|
std::set <std::string> tags () const;
|
||||||
|
|
||||||
std::string firstLine ();
|
std::string firstLine ();
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,21 @@ void TagInfoDatabase::add (const std::string& tag, const TagInfo& tagInfo)
|
||||||
_tagInformation.emplace (tag, tagInfo);
|
_tagInformation.emplace (tag, tagInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Return the current set of tag names
|
||||||
|
//
|
||||||
|
std::set <std::string> TagInfoDatabase::tags () const
|
||||||
|
{
|
||||||
|
std::set <std::string> tags;
|
||||||
|
|
||||||
|
for (auto& item : _tagInformation)
|
||||||
|
{
|
||||||
|
tags.insert (item.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
std::string TagInfoDatabase::toJson ()
|
std::string TagInfoDatabase::toJson ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#ifndef INCLUDED_TAGINFODATABASE
|
#ifndef INCLUDED_TAGINFODATABASE
|
||||||
#define INCLUDED_TAGINFODATABASE
|
#define INCLUDED_TAGINFODATABASE
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <TagInfo.h>
|
#include <TagInfo.h>
|
||||||
|
@ -39,6 +40,8 @@ public:
|
||||||
|
|
||||||
void add (const std::string&, const TagInfo&);
|
void add (const std::string&, const TagInfo&);
|
||||||
|
|
||||||
|
std::set <std::string> tags () const;
|
||||||
|
|
||||||
std::string toJson ();
|
std::string toJson ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -177,11 +177,8 @@ bool domGet (
|
||||||
|
|
||||||
else if (pig.skipLiteral ("tag."))
|
else if (pig.skipLiteral ("tag."))
|
||||||
{
|
{
|
||||||
// Generate a unique, ordered list of tags.
|
// get unique, ordered list of tags.
|
||||||
std::set <std::string> tags;
|
std::set <std::string> tags = database.tags ();
|
||||||
for (auto& interval : getAllInclusions (database))
|
|
||||||
for (auto& tag : interval.tags ())
|
|
||||||
tags.insert (tag);
|
|
||||||
|
|
||||||
// dom.tag.count
|
// dom.tag.count
|
||||||
if (pig.skipLiteral ("count"))
|
if (pig.skipLiteral ("count"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue