Skip to content

Commit

Permalink
Add xtd::collections::generic::empty_comparer class
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Sep 11, 2024
1 parent 6bff12e commit 8131006
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/xtd.core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ add_sources(
include/xtd/collections/generic/comparer
include/xtd/collections/generic/dictionary.h
include/xtd/collections/generic/dictionary
include/xtd/collections/generic/empty_comparer.h
include/xtd/collections/generic/empty_comparer
include/xtd/collections/generic/enumerable_iterators.h
include/xtd/collections/generic/enumerable_iterators
include/xtd/collections/generic/enumerator.h
Expand Down
32 changes: 12 additions & 20 deletions src/xtd.core/include/xtd/collections/generic/comparer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,24 @@ namespace xtd {
namespace collections {
/// @brief The xtd::collections::generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
namespace generic {
/// @brief Exposes a method that compares two objects.
/// @brief Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generic interface.
/// @par Definition
/// ```cpp
/// template<typename type_t>
/// class icomparer interface_
/// class comparer : public xtd::object, public xtd::collections::generic::icomparer<type_t>;
/// ```
/// @par Header
/// ```cpp
/// #include <xtd/collections/icomparer
/// #include <xtd/collections/generic/comparer
/// ```
/// @par Namespace
/// xtd::collections::generic
/// @par Library
/// xtd.core
/// @ingroup xtd_core generic_collections interfaces
/// @ingroup xtd_core generic_collections
template<typename type_t>
class comparer : public object, public icomparer<type_t> {
public:
/// @name Public Constructors

/// @{
/// @brief Initializes a new instance of the Comparer<T> class.
comparer() = default;
/// @}

/// @name Public Properties

/// @{
Expand All @@ -57,16 +50,15 @@ namespace xtd {
/// | Greater than zero | x is greater than y. |
int32 compare(const type_t& x, const type_t& y) const override {return x < y ? -1 : (x == y ? 0 : 1);}
/// @}

protected:
/// @name Protected Constructors

/// @{
/// @brief Initializes a new instance of the xtd::collections::generic::comparer <type_t> class.
comparer() = default;
/// @}
};

/// @cond
template<typename type_t>
class empty_comparer : public object, public icomparer<type_t> {
public:
empty_comparer() {}
int32 compare(const type_t& x, const type_t& y) const override {return 0;}
};
/// @endcond
}
}
}
2 changes: 2 additions & 0 deletions src/xtd.core/include/xtd/collections/generic/empty_comparer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "empty_comparer.h"
51 changes: 51 additions & 0 deletions src/xtd.core/include/xtd/collections/generic/empty_comparer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// @file
/// @brief Contains xtd::collections::generic::empty_comparer <type_t> interface.
/// @copyright Copyright (c) 2024 Gammasoft. All rights reserved.
#pragma once
#include "icomparer.h"
#include "../../object.h"

/// @brief The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
namespace xtd {
/// @brief The xtd::collections namespace contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries.
namespace collections {
/// @brief The xtd::collections::generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
namespace generic {
/// @brief Provides an empty comparer class.
/// @par Definition
/// ```cpp
/// template<typename type_t>
/// class empty_comparer : public xtd::object, public xtd::collections::generic::icomparer<type_t>;
/// ```
/// @par Header
/// ```cpp
/// #include <xtd/collections/generic/empty_comparer
/// ```
/// @par Namespace
/// xtd::collections::generic
/// @par Library
/// xtd.core
/// @ingroup xtd_core generic_collections
template<typename type_t>
class empty_comparer : public object, public icomparer<type_t> {
public:
/// @name Public Constructors

/// @{
/// @brief Initializes a new instance of the xtd::collections::generic::comparer <type_t> class.
empty_comparer() = default;
/// @}

/// @name Public Methods

/// @{
/// @brief Compares two entities and returns a value indicating whether one is less than, equal to, or greater than the other.
/// @param x The first entity to compare.
/// @param y The second entity to compare.
/// @return Always 0.
int32 compare(const type_t& x, const type_t& y) const override {return 0;}
/// @}
};
}
}
}
2 changes: 1 addition & 1 deletion src/xtd.core/include/xtd/collections/generic/icomparer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace xtd {
/// ```
/// @par Header
/// ```cpp
/// #include <xtd/collections/icomparer
/// #include <xtd/collections/generic/icomparer
/// ```
/// @par Namespace
/// xtd::collections::generic
Expand Down
1 change: 1 addition & 0 deletions src/xtd.core/include/xtd/xtd.core.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "collections/key_not_found_exception.h"
#include "collections/generic/comparer.h"
#include "collections/generic/dictionary.h"
#include "collections/generic/empty_comparer.h"
#include "collections/generic/enumerator.h"
#include "collections/generic/hash_set.h"
#include "collections/generic/icollection.h"
Expand Down

0 comments on commit 8131006

Please sign in to comment.