Skip to content

Commit

Permalink
Add xtd::collections::generic::params
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Sep 6, 2024
1 parent 9813422 commit ce8c67c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/xtd.core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ add_sources(
include/xtd/collections/generic/key_value_pair
include/xtd/collections/generic/list.h
include/xtd/collections/generic/list
include/xtd/collections/generic/params.h
include/xtd/collections/generic/params
include/xtd/collections/generic/sorted_dictionary.h
include/xtd/collections/generic/sorted_dictionary
include/xtd/collections/generic/sorted_set.h
Expand Down
2 changes: 2 additions & 0 deletions src/xtd.core/include/xtd/collections/generic/params
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "params.h"
101 changes: 101 additions & 0 deletions src/xtd.core/include/xtd/collections/generic/params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/// @file
/// @brief Contains xtd::params class.
/// @copyright Copyright (c) 2024 Gammasoft. All rights reserved.
#pragma once

/// @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 An object of type xtd::params <type_t> is a lightweight proxy object that provides access to an array of objects of type const `type_t` (that may be allocated in read-only memory).
/// @par Namespace
/// xtd
/// @par Library
/// xtd.core
/// @ingroup xtd_core system
/// @remarks This class cannot be inherited.
/// @remarks A xtd::params object is automatically constructed when:
/// * A brace-enclosed params is used to initialize an object, where the corresponding constructor accepts an xtd::params or [std::initializer_list](https://en.cppreference.com/w/cpp/utility/initializer_list) parameter,
/// * A brace-enclosed params is used as the right operand of assignment or as a function call argument, and the corresponding assignment operator/function accepts an xtd::params or [std::initializer_list](https://en.cppreference.com/w/cpp/utility/initializer_list) parameter.
/// * A brace-enclosed params is bound to auto, including in a [ranged for loop](https://en.cppreference.com/w/cpp/language/range-for).
/// @remarks xtd::params may be implemented as a pair of pointers or pointer and length. Copying a xtd::params does not copy the backing array of the corresponding params.
/// @remarks xtd::params is exactly The same as [std::initializer_list](https://en.cppreference.com/w/cpp/utility/initializer_list) object.
template<typename type_t>
class params : public xtd::object {
public:
/// @name Public Alias

/// @{
/// @brief Represents the params base type.
using base_type = std::initializer_list<type_t>;
/// @brief Represents the params value type.
using value_type = base_type::value_type;
/// @brief Represents the reference of params value type.
using reference = base_type::reference;
/// @brief Represents the const reference of params value type.
using const_reference = base_type::const_reference;
/// @brief Represents the pointer of params value type.
using pointer = const base_type*;
/// @brief Represents the const pointer of params value type.
using const_pointer = const base_type*;
/// @brief Represents the params size type (usually xtd::size).
using size_type = base_type::size_type;
/// @brief Represents the iterator of params value type.
using iterator = base_type::iterator;
/// @brief Represents the const iterator of params value type.
using const_iterator = base_type::const_iterator;
/// @}

/// @name Public Constructors

/// @{
/// @brief Create a new instance of the class xtd::params.
params() noexcept = default;
/// @}

/// @cond
params(const params&) noexcept = default;
params(params&&) noexcept = default;
params(const base_type& il) noexcept : items_(il) {}
params(base_type&& il) noexcept : items_(il) {}
/// @endcond

/// @name Public Methods

/// @{
/// @brief Returns the number of elements in the params, i.e. `std::distance(begin(), end())`.
/// @return The number of elements in the params.
size_type size() const noexcept {return items_.size();}

/// @brief Returns a pointer to the first element in the params.
/// @return A pointer to the first element in the params.
/// @remarks If the params is empty, the values of begin() and end() are unspecified, but will be identical.
iterator begin() const noexcept {return items_.begin();}
/// @brief Returns a pointer to one past the last element in the params, i.e. begin() + size().
/// @return A pointer to one past the last element in the params.
/// @remarks If the params is empty, the values of begin() and end() are unspecified, but will be identical.
iterator end() const noexcept {return items_.end();}

xtd::string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", items_));}
/// @}

/// @name Public Operators

/// @{
/// @brief Returns a reference to the underlying base type.
/// @return Reference to the underlying base type.
operator const base_type&() const noexcept {return items_;}
/// @brief Returns a reference to the underlying base type.
/// @return Reference to the underlying base type.
operator base_type&() noexcept {return items_;}
/// @}

private:
params(const_pointer p, size_type l) noexcept : items_(p, l) {}
base_type items_;
};
}
}
}
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 @@ -23,6 +23,7 @@
#include "collections/generic/ilist.h"
#include "collections/generic/key_value_pair.h"
#include "collections/generic/list.h"
#include "collections/generic/params.h"
#include "collections/generic/sorted_dictionary.h"
#include "collections/generic/sorted_set.h"
#include "collections/generic/helpers/allocator.h"
Expand Down

0 comments on commit ce8c67c

Please sign in to comment.