changeset 204:7086e93bc4ea

Directory: add count() operator== and STL compat
author David Demelier <markand@malikania.fr>
date Sun, 16 Feb 2014 12:38:49 +0100
parents 1ffe6d4937b7
children 9f22ce5f1b39
files C++/Directory.cpp C++/Directory.h
diffstat 2 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/C++/Directory.cpp	Thu Jan 23 14:56:50 2014 +0100
+++ b/C++/Directory.cpp	Sun Feb 16 12:38:49 2014 +0100
@@ -143,6 +143,11 @@
 {
 }
 
+bool operator==(const Directory::Entry &e1, const Directory::Entry &e2)
+{
+	return e1.name == e2.name && e1.type == e2.type;
+}
+
 Directory::Directory()
 {
 }
@@ -171,3 +176,13 @@
 {
 	return m_list.cend();
 }
+
+int Directory::count() const
+{
+	return m_list.size();
+}
+
+bool operator==(const Directory &d1, const Directory &d2)
+{
+	return d1.m_list == d2.m_list;
+}
--- a/C++/Directory.h	Thu Jan 23 14:56:50 2014 +0100
+++ b/C++/Directory.h	Sun Feb 16 12:38:49 2014 +0100
@@ -61,10 +61,17 @@
 		Type		type;		//! type of file
 
 		Entry();
+
+		friend bool operator==(const Entry &e1, const Entry &e2);
 	};
 
 	using List = std::vector<Entry>;
 
+	// C++ Container compatibility
+	using value_type	= List::value_type;
+	using iterator		= List::iterator;
+	using const_iterator	= List::const_iterator;
+
 private:
 	List m_list;
 
@@ -110,7 +117,15 @@
 	 * @return the iterator
 	 */
 	List::const_iterator cend() const;
+
+	/**
+	 * Get the number of entries in the directory.
+	 *
+	 * @return the number
+	 */
+	int count() const;
+
+	friend bool operator==(const Directory &d1, const Directory &d2);
 };
 
 #endif // !_DIRECTORY_H_
-