added schema node iterator
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "matador/object/error_code.hpp"
|
||||
#include "matador/object/schema_node.hpp"
|
||||
#include "matador/object/schema_node_iterator.hpp"
|
||||
|
||||
#include "matador/utils/result.hpp"
|
||||
#include "matador/utils/error.hpp"
|
||||
@@ -15,6 +16,8 @@ namespace matador::object {
|
||||
|
||||
class schema {
|
||||
public:
|
||||
typedef const_schema_node_iterator const_iterator; /**< Shortcut for the list const iterator. */
|
||||
|
||||
schema();
|
||||
|
||||
template <typename Type>
|
||||
@@ -36,6 +39,20 @@ public:
|
||||
return utils::ok<void>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first schema node.
|
||||
*
|
||||
* @return The first schema node iterator.
|
||||
*/
|
||||
[[nodiscard]] const_iterator begin() const;
|
||||
|
||||
/**
|
||||
* Return the last schema node.
|
||||
*
|
||||
* @return The last schema node iterator.
|
||||
*/
|
||||
[[nodiscard]] const_iterator end() const;
|
||||
|
||||
[[nodiscard]] bool empty() const;
|
||||
|
||||
[[nodiscard]] size_t size() const;
|
||||
|
||||
@@ -56,7 +56,8 @@ private:
|
||||
|
||||
|
||||
private:
|
||||
friend schema;
|
||||
friend class schema;
|
||||
friend class const_schema_node_iterator;
|
||||
|
||||
schema &schema_;
|
||||
std::unique_ptr<basic_object_info> info_;
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
#ifndef SCHEMA_NODE_ITERATOR_HPP
|
||||
#define SCHEMA_NODE_ITERATOR_HPP
|
||||
|
||||
#include "matador/object/schema_node.hpp"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
class const_schema_node_iterator {
|
||||
public:
|
||||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using value_type = schema_node;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
/**
|
||||
* Creates an empty iterator
|
||||
*/
|
||||
const_schema_node_iterator() = default;
|
||||
|
||||
/**
|
||||
* @brief Creates an iterator for a concrete type.
|
||||
*
|
||||
* This constructor creates an iterator for a concrete
|
||||
* type and a concrete object.
|
||||
*
|
||||
* @param node The schema node of the object
|
||||
*/
|
||||
explicit const_schema_node_iterator(std::shared_ptr<value_type> node);
|
||||
|
||||
/**
|
||||
* Copy from a given const_object_view_iterator.
|
||||
*
|
||||
* @param x The prototype_iterator to copy from.
|
||||
*/
|
||||
const_schema_node_iterator(const const_schema_node_iterator &x) = default;
|
||||
|
||||
/**
|
||||
* Assign from a given prototype_iterator.
|
||||
*
|
||||
* @param x The prototype_iterator to assign from.
|
||||
* @return The assigned prototype_iterator.
|
||||
*/
|
||||
const_schema_node_iterator& operator=(const const_schema_node_iterator &x) = default;
|
||||
|
||||
~const_schema_node_iterator() = default;
|
||||
|
||||
/**
|
||||
* @brief Compares this with another iterators.
|
||||
*
|
||||
* Compares this with another iterators. Returns true
|
||||
* if the iterators node prototype_type are the same.
|
||||
*
|
||||
* @param i The iterator to compare with.
|
||||
* @return True if the iterators are the same.
|
||||
*/
|
||||
bool operator==(const const_schema_node_iterator &i) const;
|
||||
|
||||
/**
|
||||
* @brief Compares this with another iterators.
|
||||
*
|
||||
* Compares this with another iterators. Returns true
|
||||
* if the iterators node prototype_node are not the same.
|
||||
*
|
||||
* @param i The iterator to compare with.
|
||||
* @return True if the iterators are not the same.
|
||||
*/
|
||||
bool operator!=(const const_schema_node_iterator &i) const;
|
||||
|
||||
/**
|
||||
* Pre increments the iterator
|
||||
*
|
||||
* @return Returns iterators successor.
|
||||
*/
|
||||
const_schema_node_iterator& operator++();
|
||||
|
||||
/**
|
||||
* Post increments the iterator
|
||||
*
|
||||
* @return Returns iterator before incrementing.
|
||||
*/
|
||||
const_schema_node_iterator operator++(int);
|
||||
|
||||
/**
|
||||
* Pre increments the iterator
|
||||
*
|
||||
* @return Returns iterators predecessor.
|
||||
*/
|
||||
const_schema_node_iterator& operator--();
|
||||
|
||||
/**
|
||||
* Post decrements the iterator
|
||||
*
|
||||
* @return Returns iterator before decrementing.
|
||||
*/
|
||||
const_schema_node_iterator operator--(int);
|
||||
|
||||
/**
|
||||
* Returns the pointer to the node.
|
||||
*
|
||||
* @return The pointer to the node.
|
||||
*/
|
||||
pointer operator->() const;
|
||||
|
||||
/**
|
||||
* Returns the node.
|
||||
*
|
||||
* @return The iterators underlying node.
|
||||
*/
|
||||
const reference operator*() const;
|
||||
|
||||
/**
|
||||
* Returns the pointer to the node.
|
||||
*
|
||||
* @return The pointer to the node.
|
||||
*/
|
||||
[[nodiscard]] pointer get() const;
|
||||
|
||||
private:
|
||||
void increment();
|
||||
void decrement();
|
||||
|
||||
private:
|
||||
std::shared_ptr<value_type> node_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif //SCHEMA_NODE_ITERATOR_HPP
|
||||
Reference in New Issue
Block a user