Skip to content

Commit

Permalink
rename xtd::linq::enumerable_collection to __opaque_xtd_linq_enumerab…
Browse files Browse the repository at this point in the history
…le_collection__
  • Loading branch information
gammasoft71 committed Jan 9, 2025
1 parent a8e2b1c commit 68b2ca1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/xtd.core/include/xtd/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ namespace xtd {
template <typename source_t>
const xtd::linq::enumerable::ienumerable<xtd::array<source_t>>& xtd::linq::enumerable::chunk(const ienumerable<source_t>& source, size_t size) {
if (size == 0) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
static thread_local auto chunks = enumerable_collection<xtd::array<source_t>> {};
chunks = enumerable_collection<xtd::array<source_t>> {};
static thread_local auto chunks = __opaque_xtd_linq_enumerable_collection__<xtd::array<source_t>> {};
chunks = __opaque_xtd_linq_enumerable_collection__<xtd::array<source_t>> {};
auto chunk = std::vector<source_t> {};
for (auto index = size_t {0}; const auto& item : source) {
chunk.push_back(item);
Expand Down
4 changes: 2 additions & 2 deletions src/xtd.core/include/xtd/as.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ new_type_t* __convert_value__(current_type_t* value) {

template <typename result_t, typename source_t>
inline const xtd::collections::generic::ienumerable<result_t>& xtd::linq::enumerable::cast(const xtd::collections::generic::ienumerable<source_t>& source) noexcept {
static thread_local auto result = xtd::linq::enumerable_collection<result_t> {};
result = xtd::linq::enumerable_collection<result_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
for (const auto& item : source)
result.items.push_back(xtd::as<result_t>(item));
return static_cast<const xtd::collections::generic::ienumerable<result_t>&>(result);
Expand Down
61 changes: 31 additions & 30 deletions src/xtd.core/include/xtd/linq/enumerable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include <algorithm>
#include <functional>

/// @cond
template<typename type_t>
struct __opaque_xtd_linq_enumerable_collection__;
/// @endcond

/// @brief The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
namespace xtd {
/// @cond
Expand All @@ -31,10 +36,6 @@ namespace xtd {

/// @brief Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
namespace linq {
/// @cond
template<typename type_t>
struct enumerable_collection;
/// @endcond

/// @brief Provides a set of static methods for querying objects that implement ienumerable <type_t>.
/// @par Definition
Expand Down Expand Up @@ -215,8 +216,8 @@ namespace xtd {
/// @include enumerable_append.cpp
template<typename source_t>
static const ienumerable<source_t>& append(const ienumerable<source_t>& source, const source_t& element) noexcept {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (const auto& item : source)
result.items.push_back(item);
result.items.push_back(element);
Expand All @@ -243,8 +244,8 @@ namespace xtd {
/// @include enumerable_as_enumerable.cpp
template<typename source_t>
static const ienumerable<source_t>& as_enumerable(std::initializer_list<source_t> source) noexcept {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (const auto& item : source)
result.items.push_back(item);
return result;
Expand All @@ -259,8 +260,8 @@ namespace xtd {
template <typename collection_t>
static const auto& as_enumerable(const collection_t& source) noexcept {
using source_t = typename collection_t::value_type;
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (const auto& item : source)
result.items.push_back(item);
return static_cast<const ienumerable<source_t>&>(result);
Expand All @@ -276,8 +277,8 @@ namespace xtd {
template<typename input_iterator_t>
static const auto& as_enumerable(input_iterator_t first, input_iterator_t last) noexcept {
using source_t = typename std::decay<decltype(*first)>::type;
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (auto iterator = first; iterator != last; ++iterator)
result.items.push_back(*iterator);
return static_cast<const ienumerable<source_t>&>(result);
Expand Down Expand Up @@ -380,8 +381,8 @@ namespace xtd {
/// @return An xtd::collection::generic::ienumerable <type_t> that contains the concatenated elements of the two input sequences.
template <typename source_t>
static const ienumerable<source_t>& concat(const ienumerable<source_t>& first, const ienumerable<source_t>& second) noexcept {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (const auto& item : first)
result.items.push_back(item);
for (const auto& item : second)
Expand Down Expand Up @@ -472,8 +473,8 @@ namespace xtd {
/// @include enumerable_count_by.cpp
template <typename key_t, typename source_t>
static const ienumerable<key_value_pair<key_t, xtd::size>>& count_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector, const iequality_comparer<key_t>& key_comparer) noexcept {
static thread_local auto result = enumerable_collection<key_value_pair<key_t, xtd::size>> {};
result = enumerable_collection<key_value_pair<key_t, xtd::size>> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
auto keys = list<key_t> {};
auto enumerator = source.get_enumerator();
while (enumerator.move_next()) {
Expand Down Expand Up @@ -512,8 +513,8 @@ namespace xtd {
/// @include enumerable_default_if_empty2.cpp
template <typename source_t>
static const ienumerable<source_t>& default_if_empty(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
if (!any(source)) result.items.push_back(default_value);
else for (const auto& item : source)
result.items.push_back(item);
Expand Down Expand Up @@ -639,8 +640,8 @@ namespace xtd {
/// @include enumerable_range.cpp
template<typename result_t, typename source_t>
static const ienumerable<result_t>& select(const ienumerable<source_t>& source, const std::function<result_t(const source_t&)>& selector) {
static thread_local auto result = enumerable_collection<result_t> {};
result = enumerable_collection<result_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
for (const auto& item : source)
result.items.push_back(selector(item));
return result;
Expand All @@ -655,8 +656,8 @@ namespace xtd {
/// @include enumerable_range.cpp
template<typename source_t>
static const ienumerable<source_t>& select(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& selector) {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (const auto& item : source)
result.items.push_back(selector(item));
return result;
Expand All @@ -672,8 +673,8 @@ namespace xtd {
/// @include enumerable_select.cpp
template<typename result_t, typename source_t>
static const ienumerable<result_t>& select(const ienumerable<source_t>& source, const std::function<result_t(const source_t&, xtd::size)>& selector) {
static thread_local auto result = enumerable_collection<result_t> {};
result = enumerable_collection<result_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
auto index = xtd::size {0};
for (const auto& item : source)
result.items.push_back(selector(item, index++));
Expand All @@ -689,8 +690,8 @@ namespace xtd {
/// @include enumerable_select.cpp
template<typename source_t>
static const ienumerable<source_t>& select(const ienumerable<source_t>& source, const std::function<source_t(const source_t&, xtd::size)>& selector) {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
auto index = xtd::size {0};
for (const auto& item : source)
result.items.push_back(selector(item, index++));
Expand Down Expand Up @@ -718,8 +719,8 @@ namespace xtd {
/// @include enumerable_where.cpp
template<typename source_t>
static const ienumerable<source_t>& where(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
for (const auto& item : source)
if (predicate(item)) result.items.push_back(item);
return result;
Expand All @@ -734,8 +735,8 @@ namespace xtd {
/// @include enumerable_where2.cpp
template<typename source_t>
static const ienumerable<source_t>& where(const ienumerable<source_t>& source, const std::function<bool(const source_t&, xtd::size)>& predicate) {
static thread_local auto result = enumerable_collection<source_t> {};
result = enumerable_collection<source_t> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
auto index = xtd::size {0};
for (const auto& item : source)
if (predicate(item, index++)) result.items.push_back(item);
Expand Down
62 changes: 16 additions & 46 deletions src/xtd.core/include/xtd/linq/enumerable_collection.hpp
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
/// @file
/// @brief Contains xtd::linq::enumerable_collection <type_t> struct.
/// @brief Contains __opaque_xtd_linq_enumerable_collection__ <type_t> struct.
/// @copyright Copyright (c) 2025 Gammasoft. All rights reserved.
#pragma once
#include "../collections/generic/helpers/allocator.hpp"
#include "../collections/generic/extensions/enumerable.hpp"
#include "../collections/generic/enumerator.hpp"
#include "../new_ptr.hpp"
#include <limits>
#include <vector>

/// @brief The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
namespace xtd {
/// @cond
namespace collections::generic {
template<typename type_t>
class ienumerable;
}
/// @endcond

/// @brief Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
namespace linq {
/// @cond
class enumerable;
/// @endcond

/// @brief Represent an enumerable collection.
/// @par Definition
/// ```cpp
/// template<typename type_t>
/// struct enumerable_collection : xtd::collections::generic::ienumerable<type_t>;
/// ```
/// @par Header
/// ```cpp
/// #include <xtd/linq/enumerable_collection
/// ```
/// @par Namespace
/// xtd::linq
/// @par Library
/// xtd.core
/// @ingroup xtd_core linq
template<typename type_t>
struct enumerable_collection : xtd::collections::generic::ienumerable<type_t> {
xtd::collections::generic::enumerator<type_t> get_enumerator() const override {
return xtd::collections::generic::enumerator<>::create(items);
}
/// @cond
namespace xtd::linq {
class enumerable;
};

private:
friend class xtd::linq::enumerable;
enumerable_collection() = default;
std::vector<type_t> items;
};
template<typename type_t>
struct __opaque_xtd_linq_enumerable_collection__ : xtd::collections::generic::ienumerable<type_t> {
xtd::collections::generic::enumerator<type_t> get_enumerator() const override {
return xtd::collections::generic::enumerator<>::create(items);
}
}

private:
friend class xtd::linq::enumerable;
__opaque_xtd_linq_enumerable_collection__() = default;
std::vector<type_t> items;
};
/// @endcond
4 changes: 2 additions & 2 deletions src/xtd.core/src/xtd/linq/enumerable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ optional<double> enumerable::average(const ienumerable<optional<int64>>& source)

const enumerable::ienumerable<int32>& enumerable::range(int32 start, int32 count) {
if (count < 0) throw argument_out_of_range_exception {};
static thread_local auto result = enumerable_collection<int32> {};
result = enumerable_collection<int32> {};
static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<int32> {};
result = __opaque_xtd_linq_enumerable_collection__<int32> {};
for (auto index = start; index < start + count; ++index)
result.items.push_back(index);
return result;
Expand Down

0 comments on commit 68b2ca1

Please sign in to comment.