summaryrefslogtreecommitdiffstats
path: root/src/libixion/named_expressions_iterator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libixion/named_expressions_iterator.cpp')
-rw-r--r--src/libixion/named_expressions_iterator.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/libixion/named_expressions_iterator.cpp b/src/libixion/named_expressions_iterator.cpp
new file mode 100644
index 0000000..77ce457
--- /dev/null
+++ b/src/libixion/named_expressions_iterator.cpp
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "ixion/named_expressions_iterator.hpp"
+#include "ixion/global.hpp"
+#include "model_types.hpp"
+#include "model_context_impl.hpp"
+
+namespace ixion {
+
+struct named_expressions_iterator::impl
+{
+ const detail::named_expressions_t* named_exps;
+ detail::named_expressions_t::const_iterator it;
+ detail::named_expressions_t::const_iterator it_end;
+
+ impl() : named_exps(nullptr) {}
+
+ impl(const model_context& cxt, sheet_t scope) :
+ named_exps(scope >=0 ? &cxt.mp_impl->get_named_expressions(scope) : &cxt.mp_impl->get_named_expressions()),
+ it(named_exps->cbegin()),
+ it_end(named_exps->cend()) {}
+
+ impl(const impl& other) :
+ named_exps(other.named_exps),
+ it(other.it),
+ it_end(other.it_end) {}
+};
+
+named_expressions_iterator::named_expressions_iterator() :
+ mp_impl(std::make_unique<impl>()) {}
+
+named_expressions_iterator::named_expressions_iterator(const model_context& cxt, sheet_t scope) :
+ mp_impl(std::make_unique<impl>(cxt, scope)) {}
+
+named_expressions_iterator::named_expressions_iterator(const named_expressions_iterator& other) :
+ mp_impl(std::make_unique<impl>(*other.mp_impl)) {}
+
+named_expressions_iterator::named_expressions_iterator(named_expressions_iterator&& other) :
+ mp_impl(std::move(other.mp_impl)) {}
+
+named_expressions_iterator::~named_expressions_iterator() = default;
+
+size_t named_expressions_iterator::size() const
+{
+ if (!mp_impl->named_exps)
+ return 0;
+
+ return mp_impl->named_exps->size();
+}
+
+bool named_expressions_iterator::has() const
+{
+ if (!mp_impl->named_exps)
+ return false;
+
+ return mp_impl->it != mp_impl->it_end;
+}
+
+void named_expressions_iterator::next()
+{
+ ++mp_impl->it;
+}
+
+named_expressions_iterator::named_expression named_expressions_iterator::get() const
+{
+ named_expression ret;
+ ret.name = &mp_impl->it->first;
+ ret.expression = &mp_impl->it->second;
+ return ret;
+}
+
+named_expressions_iterator& named_expressions_iterator::operator= (const named_expressions_iterator& other)
+{
+ mp_impl = std::make_unique<impl>(*other.mp_impl);
+ return *this;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */