bindings: cxx: rename line and chip iterator classes
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 21 Feb 2018 12:39:25 +0000 (13:39 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 21 Feb 2018 12:41:31 +0000 (13:41 +0100)
Use a shorter name for code brevity. Change chip_iterator to chip_iter
and line_iterator to line_iter.

Rename the helper functions as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
bindings/cxx/examples/gpiodetectcxx.cpp
bindings/cxx/examples/gpioinfocxx.cpp
bindings/cxx/gpiod.hpp
bindings/cxx/iter.cpp
bindings/cxx/line.cpp

index 257a84cd602140e919bce217ae37a06ffe0c83e4..bcecf04fbbe84639aec366097c5c1e4ec001861f 100644 (file)
@@ -23,7 +23,7 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       for (auto& it: ::gpiod::make_chip_iterator()) {
+       for (auto& it: ::gpiod::make_chip_iter()) {
                ::std::cout << it.name() << " ["
                          << it.label() << "] ("
                          << it.num_lines() << " lines)" << ::std::endl;
index 1559c6b723b063b3768b7178c806f16b23889a1a..5be60bd5056b712b1d67b489d6c8a6ee066f7033 100644 (file)
@@ -23,10 +23,10 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       for (auto& cit: ::gpiod::make_chip_iterator()) {
+       for (auto& cit: ::gpiod::make_chip_iter()) {
                ::std::cout << cit.name() << " - " << cit.num_lines() << " lines:" << ::std::endl;
 
-               for (auto& lit: ::gpiod::line_iterator(cit)) {
+               for (auto& lit: ::gpiod::line_iter(cit)) {
                        ::std::cout << "\tline ";
                        ::std::cout.width(3);
                        ::std::cout << lit.offset() << ": ";
index efa15f2da3decd349ff83fcfef09d9f3fc8f43d5..da1e83b134cbaadc244e62ad5057d91f1bdbcd47 100644 (file)
@@ -25,8 +25,8 @@ namespace gpiod {
 class line;
 class line_bulk;
 class line_event;
-class line_iterator;
-class chip_iterator;
+class line_iter;
+class chip_iter;
 
 /**
  * @defgroup __gpiod_cxx__ C++ bindings
@@ -199,8 +199,8 @@ private:
 
        ::std::shared_ptr<::gpiod_chip> _m_chip;
 
-       friend chip_iterator;
-       friend line_iterator;
+       friend chip_iter;
+       friend line_iter;
 };
 
 /**
@@ -461,7 +461,7 @@ private:
 
        friend chip;
        friend line_bulk;
-       friend line_iterator;
+       friend line_iter;
 };
 
 /**
@@ -749,75 +749,75 @@ private:
 };
 
 /**
- * @brief Create a new chip_iterator.
+ * @brief Create a new chip_iter.
  * @return New chip iterator object pointing to the first GPIO chip on the system.
  * @note This function is needed as we already use the default constructor of
- *       gpiod::chip_iterator as the return value of gpiod::end.
+ *       gpiod::chip_iter as the return value of gpiod::end.
  */
-GPIOD_API chip_iterator make_chip_iterator(void);
+GPIOD_API chip_iter make_chip_iter(void);
 
 /**
  * @brief Support for range-based loops for chip iterators.
  * @param iter A chip iterator.
  * @return Iterator unchanged.
  */
-GPIOD_API chip_iterator begin(chip_iterator iter) noexcept;
+GPIOD_API chip_iter begin(chip_iter iter) noexcept;
 
 /**
  * @brief Support for range-based loops for chip iterators.
  * @param iter A chip iterator.
  * @return New end iterator.
  */
-GPIOD_API chip_iterator end(const chip_iterator& iter) noexcept;
+GPIOD_API chip_iter end(const chip_iter& iter) noexcept;
 
 /**
  * @brief Allows to iterate over all GPIO chips present on the system.
  */
-class chip_iterator
+class chip_iter
 {
 public:
 
        /**
         * @brief Default constructor. Creates the end iterator.
         */
-       GPIOD_API chip_iterator(void) = default;
+       GPIOD_API chip_iter(void) = default;
 
        /**
         * @brief Copy constructor.
-        * @param other Other chip_iterator.
+        * @param other Other chip_iter.
         */
-       GPIOD_API chip_iterator(const chip_iterator& other) = default;
+       GPIOD_API chip_iter(const chip_iter& other) = default;
 
        /**
         * @brief Move constructor.
-        * @param other Other chip_iterator.
+        * @param other Other chip_iter.
         */
-       GPIOD_API chip_iterator(chip_iterator&& other) = default;
+       GPIOD_API chip_iter(chip_iter&& other) = default;
 
        /**
         * @brief Assignment operator.
-        * @param other Other chip_iterator.
+        * @param other Other chip_iter.
         * @return Reference to this iterator.
         */
-       GPIOD_API chip_iterator& operator=(const chip_iterator& other) = default;
+       GPIOD_API chip_iter& operator=(const chip_iter& other) = default;
 
        /**
         * @brief Move assignment operator.
-        * @param other Other chip_iterator.
+        * @param other Other chip_iter.
         * @return Reference to this iterator.
         */
-       GPIOD_API chip_iterator& operator=(chip_iterator&& other) = default;
+       GPIOD_API chip_iter& operator=(chip_iter&& other) = default;
 
        /**
         * @brief Destructor.
         */
-       GPIOD_API ~chip_iterator(void) = default;
+       GPIOD_API ~chip_iter(void) = default;
 
        /**
         * @brief Advance the iterator by one element.
         * @return Reference to this iterator.
         */
-       GPIOD_API chip_iterator& operator++(void);
+       GPIOD_API chip_iter& operator++(void);
 
        /**
         * @brief Dereference current element.
@@ -834,27 +834,27 @@ public:
        /**
         * @brief Check if this operator points to the same element.
         * @param rhs Right-hand side of the equation.
-        * @return True if this iterator points to the same chip_iterator,
+        * @return True if this iterator points to the same chip_iter,
         *         false otherwise.
         */
-       GPIOD_API bool operator==(const chip_iterator& rhs) const noexcept;
+       GPIOD_API bool operator==(const chip_iter& rhs) const noexcept;
 
        /**
         * @brief Check if this operator doesn't point to the same element.
         * @param rhs Right-hand side of the equation.
-        * @return True if this iterator doesn't point to the same chip_iterator,
+        * @return True if this iterator doesn't point to the same chip_iter,
         *         false otherwise.
         */
-       GPIOD_API bool operator!=(const chip_iterator& rhs) const noexcept;
+       GPIOD_API bool operator!=(const chip_iter& rhs) const noexcept;
 
 private:
 
-       chip_iterator(::gpiod_chip_iter* iter);
+       chip_iter(::gpiod_chip_iter* iter);
 
        ::std::shared_ptr<::gpiod_chip_iter> _m_iter;
        chip _m_current;
 
-       friend chip_iterator make_chip_iterator(void);
+       friend chip_iter make_chip_iter(void);
 };
 
 /**
@@ -862,69 +862,69 @@ private:
  * @param iter A line iterator.
  * @return Iterator unchanged.
  */
-GPIOD_API line_iterator begin(line_iterator iter) noexcept;
+GPIOD_API line_iter begin(line_iter iter) noexcept;
 
 /**
  * @brief Support for range-based loops for line iterators.
  * @param iter A line iterator.
  * @return New end iterator.
  */
-GPIOD_API line_iterator end(const line_iterator& iter) noexcept;
+GPIOD_API line_iter end(const line_iter& iter) noexcept;
 
 /**
  * @brief Allows to iterate over all lines owned by a GPIO chip.
  */
-class line_iterator
+class line_iter
 {
 public:
 
        /**
         * @brief Default constructor. Creates the end iterator.
         */
-       GPIOD_API line_iterator(void) = default;
+       GPIOD_API line_iter(void) = default;
 
        /**
         * @brief Constructor. Creates the begin iterator.
         * @param owner Chip owning the GPIO lines over which we want to iterate.
         */
-       GPIOD_API line_iterator(const chip& owner);
+       GPIOD_API line_iter(const chip& owner);
 
        /**
         * @brief Copy constructor.
         * @param other Other line iterator.
         */
-       GPIOD_API line_iterator(const line_iterator& other) = default;
+       GPIOD_API line_iter(const line_iter& other) = default;
 
        /**
         * @brief Move constructor.
         * @param other Other line iterator.
         */
-       GPIOD_API line_iterator(line_iterator&& other) = default;
+       GPIOD_API line_iter(line_iter&& other) = default;
 
        /**
         * @brief Assignment operator.
         * @param other Other line iterator.
-        * @return Reference to this line_iterator.
+        * @return Reference to this line_iter.
         */
-       GPIOD_API line_iterator& operator=(const line_iterator& other) = default;
+       GPIOD_API line_iter& operator=(const line_iter& other) = default;
 
        /**
         * @brief Move assignment operator.
         * @param other Other line iterator.
-        * @return Reference to this line_iterator.
+        * @return Reference to this line_iter.
         */
-       GPIOD_API line_iterator& operator=(line_iterator&& other) = default;
+       GPIOD_API line_iter& operator=(line_iter&& other) = default;
 
        /**
         * @brief Destructor.
         */
-       GPIOD_API ~line_iterator(void) = default;
+       GPIOD_API ~line_iter(void) = default;
 
        /**
         * @brief Advance the iterator by one element.
         * @return Reference to this iterator.
         */
-       GPIOD_API line_iterator& operator++(void);
+       GPIOD_API line_iter& operator++(void);
 
        /**
         * @brief Dereference current element.
@@ -941,18 +941,18 @@ public:
        /**
         * @brief Check if this operator points to the same element.
         * @param rhs Right-hand side of the equation.
-        * @return True if this iterator points to the same line_iterator,
+        * @return True if this iterator points to the same line_iter,
         *         false otherwise.
         */
-       GPIOD_API bool operator==(const line_iterator& rhs) const noexcept;
+       GPIOD_API bool operator==(const line_iter& rhs) const noexcept;
 
        /**
         * @brief Check if this operator doesn't point to the same element.
         * @param rhs Right-hand side of the equation.
-        * @return True if this iterator doesn't point to the same line_iterator,
+        * @return True if this iterator doesn't point to the same line_iter,
         *         false otherwise.
         */
-       GPIOD_API bool operator!=(const line_iterator& rhs) const noexcept;
+       GPIOD_API bool operator!=(const line_iter& rhs) const noexcept;
 
 private:
 
index 14b4bdbb2cc8e22faae5e8913c3c453bd92cf525..a9f0d42e4ea14b06145e72317e95631cb479dd7a 100644 (file)
@@ -27,7 +27,7 @@ void line_iter_deleter(::gpiod_line_iter* iter)
        ::gpiod_line_iter_free(iter);
 }
 
-::gpiod_line_iter* make_line_iterator(::gpiod_chip* chip)
+::gpiod_line_iter* make_line_iter(::gpiod_chip* chip)
 {
        ::gpiod_line_iter* iter;
 
@@ -41,34 +41,34 @@ void line_iter_deleter(::gpiod_line_iter* iter)
 
 } /* namespace */
 
-chip_iterator make_chip_iterator(void)
+chip_iter make_chip_iter(void)
 {
        ::gpiod_chip_iter* iter = ::gpiod_chip_iter_new();
        if (!iter)
                throw ::std::system_error(errno, ::std::system_category(),
                                          "error creating GPIO chip iterator");
 
-       return ::std::move(chip_iterator(iter));
+       return ::std::move(chip_iter(iter));
 }
 
-bool chip_iterator::operator==(const chip_iterator& rhs) const noexcept
+bool chip_iter::operator==(const chip_iter& rhs) const noexcept
 {
        return this->_m_current == rhs._m_current;
 }
 
-bool chip_iterator::operator!=(const chip_iterator& rhs) const noexcept
+bool chip_iter::operator!=(const chip_iter& rhs) const noexcept
 {
        return this->_m_current != rhs._m_current;
 }
 
-chip_iterator::chip_iterator(::gpiod_chip_iter *iter)
+chip_iter::chip_iter(::gpiod_chip_iter *iter)
        : _m_iter(iter, chip_iter_deleter),
          _m_current(chip(::gpiod_chip_iter_next_noclose(this->_m_iter.get())))
 {
 
 }
 
-chip_iterator& chip_iterator::operator++(void)
+chip_iter& chip_iter::operator++(void)
 {
        ::gpiod_chip* next = ::gpiod_chip_iter_next_noclose(this->_m_iter.get());
 
@@ -77,44 +77,44 @@ chip_iterator& chip_iterator::operator++(void)
        return *this;
 }
 
-const chip& chip_iterator::operator*(void) const
+const chip& chip_iter::operator*(void) const
 {
        return this->_m_current;
 }
 
-const chip* chip_iterator::operator->(void) const
+const chip* chip_iter::operator->(void) const
 {
        return ::std::addressof(this->_m_current);
 }
 
-chip_iterator begin(chip_iterator iter) noexcept
+chip_iter begin(chip_iter iter) noexcept
 {
        return iter;
 }
 
-chip_iterator end(const chip_iterator&) noexcept
+chip_iter end(const chip_iter&) noexcept
 {
-       return ::std::move(chip_iterator());
+       return ::std::move(chip_iter());
 }
 
-line_iterator begin(line_iterator iter) noexcept
+line_iter begin(line_iter iter) noexcept
 {
        return iter;
 }
 
-line_iterator end(const line_iterator&) noexcept
+line_iter end(const line_iter&) noexcept
 {
-       return ::std::move(line_iterator());
+       return ::std::move(line_iter());
 }
 
-line_iterator::line_iterator(const chip& owner)
-       : _m_iter(make_line_iterator(owner._m_chip.get()), line_iter_deleter),
+line_iter::line_iter(const chip& owner)
+       : _m_iter(make_line_iter(owner._m_chip.get()), line_iter_deleter),
          _m_current(line(::gpiod_line_iter_next(this->_m_iter.get()), owner))
 {
 
 }
 
-line_iterator& line_iterator::operator++(void)
+line_iter& line_iter::operator++(void)
 {
        ::gpiod_line* next = ::gpiod_line_iter_next(this->_m_iter.get());
 
@@ -123,22 +123,22 @@ line_iterator& line_iterator::operator++(void)
        return *this;
 }
 
-const line& line_iterator::operator*(void) const
+const line& line_iter::operator*(void) const
 {
        return this->_m_current;
 }
 
-const line* line_iterator::operator->(void) const
+const line* line_iter::operator->(void) const
 {
        return ::std::addressof(this->_m_current);
 }
 
-bool line_iterator::operator==(const line_iterator& rhs) const noexcept
+bool line_iter::operator==(const line_iter& rhs) const noexcept
 {
        return this->_m_current._m_line == rhs._m_current._m_line;
 }
 
-bool line_iterator::operator!=(const line_iterator& rhs) const noexcept
+bool line_iter::operator!=(const line_iter& rhs) const noexcept
 {
        return this->_m_current._m_line != rhs._m_current._m_line;
 }
index 05f77fc0697bb06de153883c916f510cd450438a..bd3afc313d4436422ba2edcefbc41c2015392d27 100644 (file)
@@ -235,7 +235,7 @@ line find_line(const ::std::string& name)
 {
        line ret;
 
-       for (auto& it: make_chip_iterator()) {
+       for (auto& it: make_chip_iter()) {
                ret = it.find_line(name);
                if (ret)
                        break;