From 6d818a3b48fe6046a0607737b3fce6323c4daa5f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 15 Jul 2017 15:01:45 +0200 Subject: [PATCH] Add filter module for tag iterators --- libimagentrytimetrack/src/iter/filter.rs | 70 ++++++++++++++++++++++++ libimagentrytimetrack/src/iter/mod.rs | 1 + 2 files changed, 71 insertions(+) create mode 100644 libimagentrytimetrack/src/iter/filter.rs diff --git a/libimagentrytimetrack/src/iter/filter.rs b/libimagentrytimetrack/src/iter/filter.rs new file mode 100644 index 00000000..b236c8dd --- /dev/null +++ b/libimagentrytimetrack/src/iter/filter.rs @@ -0,0 +1,70 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use error::TimeTrackError as TTE; +use error::TimeTrackErrorKind as TTEK; +use error::MapErrInto; + +use libimagstore::store::FileLockEntry; +use libimagstore::store::Store; +use libimagstore::storeid::StoreIdIterator; +use libimagerror::into::IntoError; + +use iter::get::GetTimeTrackIter; +use tag::TimeTrackingTag as TTT; +use timetracking::TimeTracking; + +pub struct WithOneOf<'a> { + iter: GetTimeTrackIter<'a>, + allowed_tags: &'a Vec, +} + +impl<'a> WithOneOf<'a> { + + pub fn new(iter: GetTimeTrackIter<'a>, allowed_tags: &'a Vec) -> WithOneOf<'a> { + WithOneOf { + iter: iter, + allowed_tags: allowed_tags + } + } +} + +impl<'a> Iterator for WithOneOf<'a> { + type Item = Result, TTE>; + + fn next(&mut self) -> Option { + loop { + match self.iter.next() { + Some(Ok(fle)) => { + match fle.get_timetrack_tag() { + Err(e) => return Some(Err(e)), + Ok(t) => if self.allowed_tags.contains(&t) { + return Some(Ok(fle)) + } else { + // loop + }, + } + }, + Some(Err(e)) => return Some(Err(e)), + None => return None, + } + } + } +} + diff --git a/libimagentrytimetrack/src/iter/mod.rs b/libimagentrytimetrack/src/iter/mod.rs index 22dcea26..d2d78cd9 100644 --- a/libimagentrytimetrack/src/iter/mod.rs +++ b/libimagentrytimetrack/src/iter/mod.rs @@ -18,6 +18,7 @@ // pub mod create; +pub mod filter; pub mod get; pub mod setendtime; pub mod storeid;