Advertisement
Guest User

AlgCpp

a guest
Dec 18th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 43.30 KB | None | 0 0
  1. //
  2. // Basic.h
  3. //
  4.  
  5. #ifndef BASIC_GUARD
  6. #define BASIC_GUARD
  7.  
  8. #include "../../Macro.h"
  9.  
  10.  
  11. namespace Algorithms
  12. {
  13.    
  14.     /**
  15.      *\brief Swap values between two variables.
  16.      *
  17.      * \param First  First variable.
  18.      * \param Second Second variable.
  19.      */
  20.     template <typename Type>
  21.     CPPMACRO_FORCEINLINE
  22.     CPPMACRO_CONSTEXPR
  23.     void SwapByDeclaringTemporaryVariable(Type& First, Type& Second) CPPMACRO_NOEXCEPT
  24.     {
  25.         const Type Temporary = First;
  26.         First = Second;
  27.         Second = Temporary;
  28.     }
  29. }
  30.  
  31. #endif // BASIC_GUARD
  32.  
  33. //
  34. // Array.h
  35. //
  36.  
  37. #ifndef ARRAY_GUARD
  38. #define ARRAY_GUARD
  39.  
  40. #include "../../Includes.h"
  41. #include "../../Macro.h"
  42.  
  43.  
  44. namespace Structures
  45. {
  46.  
  47.     /**
  48.      * \brief  Implementation of a dynamic array class.
  49.      *
  50.      * \tparam Type Type of data array has.
  51.      */
  52.     template<typename Type>
  53.     class Array
  54.     {
  55.  
  56.         /** @defgroup   STL STL-like interface for a dynamic array class.
  57.          *              Used for compatibility with STL.
  58.          * @{
  59.          */
  60.         using       this_type       = Array<Type>;
  61.         using       size_type       = size_t;
  62.         using       value_type      = Type;
  63.         using       reference       = Type&;
  64.         using       const_reference = const Type&;
  65.         using       pointer         = Type*;
  66.         using       const_pointer   = const Type*;
  67.  
  68.         /** @defgroup   Data group.
  69.          * @{
  70.          */
  71.  
  72.         /**
  73.          * \brief  Pointer to a dynamic array.
  74.          */
  75.         pointer     mRaw            = nullptr;
  76.  
  77.         /**
  78.          * \brief Number of items.
  79.          */
  80.         size_type   mSize           = 0u;
  81.    
  82.         /**
  83.          * @brief   Constant used to pass in dynamic array constructor's argument.
  84.          */
  85.         static const size_type kDefaultAmountOfItems = 1u;
  86.  
  87.     public:
  88.  
  89.         /**
  90.          *\brief  Build a newly dynamically allocated array class with given amount of items provided in constructor's argument.
  91.          *         In case constructor called without argument constructs array class with default amount of items.
  92.          *
  93.          * \param Size Amount of items.
  94.          */
  95.         explicit
  96.         CPPMACRO_FORCEINLINE
  97.         CPPMACRO_CONSTEXPR
  98.         Array(const size_type Size = kDefaultAmountOfItems) : mSize {Size > 0u ? Size : throw (std::invalid_argument("Array(): invalid argument"))}
  99.         {mRaw = new value_type[Size]();}
  100.  
  101.         /**
  102.          *\brief  Build a newly dynamically allocated array class with given amount of items and initialize items with provided value.
  103.          *
  104.          * \param Value Value used to initialize array's class items with.
  105.          * \param Size  Amount of items.
  106.          */
  107.         explicit
  108.         CPPMACRO_FORCEINLINE
  109.         CPPMACRO_CONSTEXPR
  110.         Array(const_reference Value, const size_type Size = kDefaultAmountOfItems)
  111.         {
  112.             if (Size > 0u)
  113.             {
  114.                 Fill(Value);
  115.             }
  116.         }
  117.  
  118.         /**
  119.          * @brief   Build a newly dynamically allocated array class by using dynamically allocated (raw) array.
  120.          *
  121.          * @param   Raw  Pointer to a dynamically allocated (raw) array.
  122.          * @param   Size Amount of items.
  123.          */
  124.         explicit
  125.         CPPMACRO_FORCEINLINE
  126.         CPPMACRO_CONSTEXPR
  127.         Array(const_pointer Raw, const size_type Size) : Array(Size)
  128.         {
  129.             if (Size > 0u)
  130.             {
  131.                 Copy(Raw, Size);
  132.             }
  133.         }
  134.  
  135.         /**
  136.          * @brief   Build a newly dynamically allocated array class by using another array class.
  137.          *
  138.          * @param   Other Another dynamically allocated array class.
  139.          */
  140.         explicit
  141.         CPPMACRO_FORCEINLINE
  142.         CPPMACRO_CONSTEXPR
  143.         Array(const this_type& Other) : Array(Other.mSize)
  144.         {
  145.             if (!IsEquals(Other))
  146.             {
  147.                 if (Other.mSize > 0u)
  148.                 {
  149.                     Copy(Other);
  150.                 }
  151.             }
  152.         }
  153.  
  154.         /**
  155.          * @brief   Build a newly dynamically allocated array class by using initialization list.
  156.          *
  157.          * @param   InitializationList Initialization list to take values from.
  158.          */
  159. #if defined (CPPMACRO_USE_INITIALIZATION_LIST)
  160.         explicit
  161.         CPPMACRO_FORCEINLINE
  162.         CPPMACRO_CONSTEXPR
  163.         Array(const std::initializer_list<value_type> InitializationList)
  164.         : Array(InitializationList.size() ? InitializationList.size()
  165.         : throw (std::invalid_argument("Array(): array has no items!")))
  166.         {  
  167.             decltype(mSize) InitializationListIterator = 0u;
  168.             for (const_reference vPickItemFromList : InitializationList) {
  169.                 mRaw[InitializationListIterator++] =
  170.                 vPickItemFromList;
  171.             }
  172.         }
  173. #endif
  174.  
  175.         /**
  176.          *\brief  Destructor.
  177.          */
  178.         CPPMACRO_FORCEINLINE
  179.         ~Array()
  180.         {   }
  181.  
  182.         CPPMACRO_FORCEINLINE
  183.         CPPMACRO_CONSTEXPR
  184.         void Copy(const_pointer Raw, const size_type Size) CPPMACRO_NOEXCEPT
  185.         {
  186.             if (Raw != nullptr &&
  187.                 Size > 0u)
  188.             {
  189.                 std::copy(Raw, Raw+Size, Raw);
  190.             }
  191.         }
  192.  
  193.         /**
  194.          * @brief   Copy items from another array class into this array class.
  195.          *
  196.          * @param Other Array class to take items from.
  197.          */
  198.         CPPMACRO_FORCEINLINE
  199.         CPPMACRO_CONSTEXPR
  200.         void Copy(const this_type& Other) CPPMACRO_NOEXCEPT
  201.         {
  202.             if (mRaw        != nullptr &&
  203.                 Other.mSize > 0u)
  204.             {
  205.                 Copy(Other.mRaw, Other.mSize);
  206.                 mSize = Other.mSize;
  207.             }
  208.         }
  209.  
  210.         /**
  211.          * @brief   Append dynamically allocated array (raw array) at the end of this array class.
  212.          *
  213.          * @param   Raw  Pointer to a dynamically allocated array.
  214.          * @param   Size Amount of items.
  215.          */
  216.         CPPMACRO_FORCEINLINE
  217.         CPPMACRO_CONSTEXPR
  218.         void Append(const_pointer Raw, const size_type Size) CPPMACRO_NOEXCEPT
  219.         {
  220.             if (Raw != nullptr &&
  221.                 !IsEmpty())
  222.             {
  223.                 Resize(Size+Size);
  224.                 std::memcpy(reinterpret_cast<void*>(Raw+(mSize-Size)), Raw, sizeof(value_type)*Size);
  225.             }
  226.         }
  227.  
  228.         /**
  229.          * @brief   Append dynamically allocated array class at the end of this array class.
  230.          *
  231.          * @param   Other Another dynamically allocated array class.
  232.          */
  233.         CPPMACRO_FORCEINLINE
  234.         CPPMACRO_CONSTEXPR
  235.         void Append(const this_type& Other) CPPMACRO_NOEXCEPT
  236.         {
  237.             if (mRaw        != nullptr  &&
  238.                 Other.mRaw  != nullptr  &&
  239.                 !Other.IsEmpty())
  240.             {
  241.                 Append(Other.mRaw, Other.mSize);
  242.             }
  243.         }
  244.  
  245.         /**
  246.          * @brief   Append dynamically allocated array class at the end of this array class.
  247.          *
  248.          * @param   Other Another dynamically allocated array class.
  249.          * @param   Count Amount of items.
  250.          */
  251.         CPPMACRO_FORCEINLINE
  252.         CPPMACRO_CONSTEXPR
  253.         void Append(const this_type& Other, const size_type Count) CPPMACRO_NOEXCEPT
  254.         {
  255.             if (mRaw        != nullptr &&
  256.                 Other.mRaw  != nullptr &&
  257.                 Count       > 0u       &&
  258.                 !Other.IsEmpty())
  259.             {
  260.                 Append(Other.mRaw, Count);
  261.             }
  262.         }
  263.  
  264.         /**
  265.          * @brief Assign data from another dynamically allocated array class to this dynamically allocated array class.
  266.          *
  267.          * @param Other Another dynamically allocated array class.
  268.          */
  269.         CPPMACRO_FORCEINLINE
  270.         CPPMACRO_CONSTEXPR
  271.         this_type& Assign(const this_type& Other) CPPMACRO_NOEXCEPT
  272.         {
  273.             if (!IsEquals(Other))
  274.             {
  275.                 if (mSize != Other.mSize)
  276.                 {
  277.                     Resize(mSize);
  278.                 }
  279.                
  280.                 Copy(Other);
  281.             }
  282.  
  283.             return (*this);
  284.         }
  285.  
  286.         /**
  287.          * @brief    Get amount of items this array class contains.
  288.          *
  289.          * @returns Amount of items.
  290.          */
  291.         CPPMACRO_FORCEINLINE
  292.         CPPMACRO_CONSTEXPR
  293.         size_type GetAmountOfItems() const CPPMACRO_NOEXCEPT
  294.         {return (mSize);}
  295.  
  296.         /**
  297.          * @brief   Set new size for this dynamically allocated array class.
  298.          *
  299.          * @param   NewSize New size.
  300.          */
  301.         CPPMACRO_FORCEINLINE
  302.         CPPMACRO_CONSTEXPR
  303.         void Resize(const size_type NewSize) CPPMACRO_NOEXCEPT
  304.         {
  305.             pointer NewBuffer = new value_type[NewSize]();
  306.             std::memcpy(reinterpret_cast<void*>(NewBuffer), mRaw, (mSize*sizeof(value_type)));
  307.             mSize = NewSize;
  308.            
  309.             if (mRaw != nullptr)
  310.             {
  311.                 delete[] mRaw;
  312.             }
  313.  
  314.             mRaw = NewBuffer;
  315.         }
  316.  
  317.         /**
  318.          * @brief   Set value at the provided index.
  319.          *
  320.          * @param   Index Index at which set the value.
  321.          * @param   Value Value to set.
  322.          */
  323.         CPPMACRO_FORCEINLINE
  324.         CPPMACRO_CONSTEXPR
  325.         void Set(const size_type Index, const_reference Value) CPPMACRO_NOEXCEPT
  326.         {At(Index) = Value;}
  327.  
  328.         /**
  329.          * @brief   Addict new item to this dynamically allocated array class.
  330.          *
  331.          * @param   Value Value to add.
  332.          */
  333.         CPPMACRO_FORCEINLINE
  334.         CPPMACRO_CONSTEXPR
  335.         void Push(const_reference Value) CPPMACRO_NOEXCEPT
  336.         {
  337.             !IsEmpty() ? Resize(++mSize) : Resize(1);
  338.             mRaw[(mSize-1u)] = Value;
  339.         }
  340.  
  341.         /**
  342.          * @brief    Remove last item from this array class and return a reference to this item.
  343.          *
  344.          * @returns Reference to removed item.
  345.          */
  346.         CPPMACRO_FORCEINLINE
  347.         CPPMACRO_CONSTEXPR
  348.         reference Pop() CPPMACRO_NOEXCEPT
  349.         {
  350.             value_type PopValue = mRaw[mSize-1u];
  351.             Resize(--mSize);
  352.             return (PopValue);
  353.         }
  354.  
  355.         /**
  356.          * @brief   Check if given index lies within an allowed array's range,
  357.          *
  358.          * @param   Index Index to check,
  359.          */
  360.         CPPMACRO_FORCEINLINE
  361.         CPPMACRO_CONSTEXPR
  362.         bool CheckIfIndexWithinAllowedRange(const size_type Index) const CPPMACRO_NOEXCEPT
  363.         {
  364.             if (Index < 0u || Index >= mSize)
  365.             {
  366.                 return (false);
  367.         }
  368.  
  369.             return (mRaw[Index]);
  370.         }
  371.  
  372.         /**
  373.          * @brief    Return a reference at given index.
  374.          *
  375.          * @param    Index Index to look up at,
  376.          *
  377.          * @returns Reference at given index,
  378.          */
  379.         CPPMACRO_FORCEINLINE
  380.         CPPMACRO_CONSTEXPR
  381.         reference At(const size_type Index) const CPPMACRO_NOEXCEPT
  382.         {
  383.             if (CheckIfIndexWithinAllowedRange(Index)) {
  384.                 return (mRaw[Index]);
  385.             } else {
  386.                 return (mRaw[0u]);
  387.             }
  388.         }
  389.  
  390.         /**
  391.          * @brief    Get access to a first item in this array class.
  392.          *
  393.          * @returns Reference to a first item.
  394.          */
  395.         CPPMACRO_FORCEINLINE
  396.         CPPMACRO_CONSTEXPR
  397.         reference GetFront() const CPPMACRO_NOEXCEPT
  398.         {
  399.             value_type Value = (mRaw[0u]);
  400.             return (Value);
  401.         }
  402.  
  403.         /**
  404.          * @brief    Get access to a last item in this array class.
  405.          *
  406.          * @returns Reference to a last item.
  407.          */
  408.         CPPMACRO_FORCEINLINE
  409.         CPPMACRO_CONSTEXPR
  410.         reference GetBack() const CPPMACRO_NOEXCEPT
  411.         {
  412.             value_type Value = (mRaw[mSize-1u]);
  413.             return (Value);
  414.         }
  415.  
  416.         /**
  417.          * @brief    Get a raw representation of this array class.
  418.          *
  419.          * @returns Pointer to a data.
  420.          */
  421.         CPPMACRO_FORCEINLINE
  422.         CPPMACRO_CONSTEXPR
  423.         const_pointer GetRaw() const CPPMACRO_NOEXCEPT
  424.         {return (&mRaw[0u]);}
  425.  
  426.         /**
  427.          * @brief   Cast data to a given type.
  428.          */
  429.         CPPMACRO_FORCEINLINE
  430.         CPPMACRO_CONSTEXPR
  431.         operator value_type&() CPPMACRO_NOEXCEPT
  432.         {return (mRaw);}
  433.  
  434.         /**
  435.          * @brief   Fill the whole array class with given value.
  436.          *
  437.          * @param   Value Value to fill items with.
  438.          */
  439.         CPPMACRO_FORCEINLINE
  440.         CPPMACRO_CONSTEXPR
  441.         void Fill(const_reference Value) CPPMACRO_NOEXCEPT
  442.         {
  443.             if (mRaw != nullptr &&
  444.                 mSize > 0u)
  445.             {
  446.                 std::fill(mRaw, mRaw+mSize, Value);
  447.             }
  448.         }
  449.  
  450.         /**
  451.          * @brief   Fill the array class with provided value starting from given index.
  452.          *
  453.          * @param   From  Index from which to start filling.
  454.          * @param   Value Value to fill items with.
  455.          */
  456.         CPPMACRO_FORCEINLINE
  457.         CPPMACRO_CONSTEXPR
  458.         void Fill(const size_type From, const_reference Value) CPPMACRO_NOEXCEPT
  459.         {
  460.             if (mRaw != nullptr &&
  461.                 mSize > 0u)
  462.             {
  463.                 std::fill(mRaw+From, mRaw+mSize, Value);
  464.             }
  465.         }
  466.  
  467.         /**
  468.          * @brief   Fill the array class with provided value starting from given index until given index.
  469.          *
  470.          * @param   From  Index from which to start filling.
  471.          * @param   To    Index to fill until.
  472.          * @param   Value Value to fill with,
  473.          */
  474.         CPPMACRO_FORCEINLINE
  475.         CPPMACRO_CONSTEXPR
  476.         void Fill(const size_type From, const size_type To, const_reference Value) CPPMACRO_NOEXCEPT
  477.         {
  478.             if (mRaw    != nullptr  &&
  479.                 From    > 0u        &&
  480.                 To      > 0u        &&
  481.                 From    < To        &&
  482.                 mSize   > 0u)
  483.             {
  484.                 std::fill(mRaw +From, mRaw+To, Value);
  485.             }
  486.         }
  487.  
  488.         /**
  489.          * @brief    Check if given array class contains items.
  490.          *
  491.          * @returns True in case array class empty.
  492.          */
  493.         CPPMACRO_FORCEINLINE
  494.         CPPMACRO_CONSTEXPR
  495.         bool IsEmpty() const CPPMACRO_NOEXCEPT
  496.         {return (!mSize);}
  497.  
  498.         /**
  499.          * @brief     Check two given dynamically allocated array classes on equality.
  500.          *
  501.          * @param     Other Another dynamically allocated array class to check.
  502.          *
  503.          * @returns True in case two array classes equals to each other.
  504.          */
  505.         CPPMACRO_FORCEINLINE
  506.         CPPMACRO_CONSTEXPR
  507.         bool IsEquals(const this_type& Other) const CPPMACRO_NOEXCEPT
  508.         {
  509.             if (Other.mSize != mSize)
  510.             {
  511.                 return (false);
  512.             }
  513.            
  514.             if (std::equal(mRaw, mRaw+mSize, Other.mRaw, Other.mRaw+Other.mSize))
  515.             {
  516.                 return (true);
  517.             }
  518.            
  519.             return (false);
  520.         }
  521.  
  522.         /**
  523.          * @brief    Get value at given index using C++'s access operator.
  524.          *
  525.          * @param    Index  Index to lookup value at.
  526.          *
  527.          * @returns Value at given index.
  528.          */
  529.         CPPMACRO_FORCEINLINE CPPMACRO_CONSTEXPR reference        operator[](const size_type Index)       {return (At(Index));}
  530.         CPPMACRO_FORCEINLINE CPPMACRO_CONSTEXPR const value_type operator[](const size_type Index) const {return (At(Index));}
  531.  
  532.         /**
  533.          * @brief     Overloaded equality operator.
  534.          *
  535.          * @param     Other Another dynamically allocated array class used to check.
  536.          *
  537.          * @returns True in case given array class equals to this array class.
  538.          */
  539.         CPPMACRO_FORCEINLINE
  540.         CPPMACRO_CONSTEXPR
  541.         bool operator==(this_type& Other) const CPPMACRO_NOEXCEPT
  542.         {return (IsEquals(Other));}
  543.        
  544.         /**
  545.          * @brief     Overloaded enequality operator.
  546.          *
  547.          * @param     Other Another dynamically allocated array class used to check.
  548.          *
  549.          * @returns True in case given array class differs from this array class.
  550.          */
  551.         CPPMACRO_FORCEINLINE
  552.         CPPMACRO_CONSTEXPR
  553.         bool operator!=(this_type& Other) const CPPMACRO_NOEXCEPT
  554.         {return (!(operator==(Other)));}
  555.        
  556.         /**
  557.          * @brief    Overloaded comparison operators.
  558.          *
  559.          * @param     Other Another dynamically allocated array class used to compare items with.
  560.          *
  561.          * @returns True if condition were met.
  562.          */
  563.         CPPMACRO_FORCEINLINE CPPMACRO_CONSTEXPR bool operator< (this_type& Other) const CPPMACRO_NOEXCEPT {return ((mSize <  Other.mSize));}
  564.         CPPMACRO_FORCEINLINE CPPMACRO_CONSTEXPR bool operator<=(this_type& Other) const CPPMACRO_NOEXCEPT {return ((mSize <= Other.mSize));}
  565.         CPPMACRO_FORCEINLINE CPPMACRO_CONSTEXPR bool operator> (this_type& Other) const CPPMACRO_NOEXCEPT {return ((mSize >  Other.mSize));}
  566.         CPPMACRO_FORCEINLINE CPPMACRO_CONSTEXPR bool operator>=(this_type& Other) const CPPMACRO_NOEXCEPT {return ((mSize >= Other.mSize));}
  567.        
  568.         /**
  569.          * @brief     Build a string which represents content of this array class.
  570.          *
  571.          * @returns String with items.
  572.          */
  573.         CPPMACRO_FORCEINLINE std::string toString() const CPPMACRO_NOEXCEPT
  574.         {
  575.             std::stringstream Output;
  576.  
  577.             for (decltype(mSize) It = 0u; It < mSize; It++) {
  578.                 Output << "Index: " << It << " Value: " << mRaw[It] << " ";
  579.             }
  580.            
  581.             return (Output.str());
  582.         }
  583.  
  584.         /**
  585.          * @brief   Output content by using standart output device.
  586.          */
  587.         CPPMACRO_FORCEINLINE
  588.         CPPMACRO_CONSTEXPR
  589.         void Print() const CPPMACRO_NOEXCEPT
  590.         {
  591.             if (!IsEmpty()) {
  592.                 std::cout << toString() << std::endl;
  593.             }
  594.         }
  595.     };
  596. }
  597.  
  598. #endif // ARRAY_GUARD
  599.  
  600. //
  601. // SingleLinkedList.h
  602. //
  603.  
  604. #ifndef SINGLELINKEDLIST_GUARD
  605. #define SINGLELINKEDLIST_GUARD
  606.  
  607. #include "SingleLinkedListNode.h"
  608.  
  609.  
  610. /**
  611.  * \brief Сache count.
  612.  */
  613. #define CPPMACRO_CACHE_COUNT
  614.  
  615. namespace Structures
  616. {
  617.  
  618.     /**
  619.      * @brief   Implementation of a linked list class (single linked list).
  620.      *
  621.      * @param   Type    Type of data list has.
  622.      */
  623.     template<typename Type>
  624.     class SingleLinkedList
  625.     {
  626.    
  627.         /** @defgroup   STL STL-like interface for a single list class.
  628.          *              Used for compatibility with STL.
  629.          * @{
  630.          */
  631.         using this_type         = SingleLinkedList<Type>;
  632.         using size_type         = size_t;
  633.         using value_type        = Type;
  634.         using reference         = Type&;
  635.         using const_reference   = const Type&;
  636.         using pointer           = Type*;
  637.         using const_pointer     = const Type*;
  638.  
  639.     private:
  640.  
  641.         /**
  642.          * @brief       Constant used to pass in linked list constructor's argument.
  643.          */
  644.         static CPPMACRO_CONSTEXPR size_type kDefaultAmountOfItems = 1u;
  645.  
  646.         /** @defgroup Data group.
  647.          *
  648.          * @{
  649.          */
  650.  
  651.         /**
  652.          * @brief       Node from which to start tracking items from.
  653.          */
  654.         SingleLinkedList<value_type>* mNodeHead;
  655.  
  656.         /**
  657.          * @brief       Use counter to track items count.
  658.          */
  659. #if defined (CPPMACRO_CACHE_COUNT)
  660.         size_type mCount;
  661. #endif
  662.  
  663.     public:
  664.  
  665.         /**
  666.          * @brief   Build empty linked list class, which doesn't contain any single item.
  667.          */
  668.         CPPMACRO_FORCEINLINE
  669.         CPPMACRO_CONSTEXPR
  670.         SingleLinkedList() : mNodeHead {CPPMACRO_INVALID_NODE}
  671. #if defined (CPPMACRO_CACHE_COUNT)
  672.         , mCount {0u}
  673. #endif
  674.         {   }
  675.  
  676.         /**
  677.          * @brief   Build linked list, which does contain single value provided by user.
  678.          *
  679.          * @param   Value Value to put into.
  680.          */
  681.         explicit
  682.         CPPMACRO_FORCEINLINE
  683.         CPPMACRO_CONSTEXPR SingleLinkedList(const_reference Value) : SingleLinkedList()
  684.         {Append(Value);}
  685.  
  686.         /**
  687.          * @brief   Build linked list, which does contain set of values provided in argument.
  688.          *
  689.          * @param   Value Value to put into.
  690.          * @param   Count Amount of items.
  691.          */
  692.         explicit
  693.         CPPMACRO_FORCEINLINE
  694.         CPPMACRO_CONSTEXPR
  695.         SingleLinkedList(const_reference Value, const size_type Count) : SingleLinkedList()
  696.         {
  697.             if (Count > 0u)
  698.             {
  699.                 decltype (mCount) IdIterator = 0u;
  700.                 while (IdIterator < Count)
  701.                 {
  702.                     Append(Value);
  703.                     IdIterator++;
  704.                 }
  705.             }
  706.         }
  707.  
  708.         /**
  709.          * @brief   Build linked list, which does contains items from the raw array.
  710.          *
  711.          * @param   Raw   Dynamically allocated array.
  712.          * @param   Count Amount of items.
  713.          */
  714.         explicit
  715.         CPPMACRO_FORCEINLINE
  716.         CPPMACRO_CONSTEXPR
  717.         SingleLinkedList(const_pointer Raw, const size_type Count) : SingleLinkedList()
  718.         {
  719.             if (Raw != nullptr &&
  720.                 Count > 0u)
  721.             {
  722.                 AppendRawArray(Raw, Count);
  723.             }
  724.         }
  725.  
  726.         /**
  727.          * @brief Build linked list, which does contain values from the initialization list.
  728.          *
  729.          * @param InitializationList Initialization list.
  730.          */
  731.         explicit
  732.         CPPMACRO_FORCEINLINE
  733.         CPPMACRO_CONSTEXPR
  734.         SingleLinkedList(const std::initializer_list<value_type>& InitializationList) : SingleLinkedList()
  735.         {
  736.             if (InitializationList.size() != 0u)
  737.             {
  738.                 AppendInitializerList(InitializationList);
  739.             }
  740.         }
  741.  
  742.         /**
  743.          * @brief   Build linked list, which does contain values from another list.
  744.          *
  745.          * @param   Other Another linked list class.
  746.          */
  747.         explicit
  748.         CPPMACRO_FORCEINLINE
  749.         CPPMACRO_CONSTEXPR
  750.         SingleLinkedList(const this_type& Other) : SingleLinkedList()
  751.         {
  752.             if (Other.IsHasItems())
  753.             {
  754.                 AppendList(Other);
  755.             }
  756.         }
  757.  
  758.         /**
  759.          * @brief   Destructor.
  760.          */
  761.         CPPMACRO_FORCEINLINE
  762.         ~SingleLinkedList()
  763.         {
  764.             Clear();
  765.         }
  766.  
  767.         /**
  768.          * @brief     Check if given linked list class contains items.
  769.          *
  770.          * @returns True in case list class has items.
  771.          */
  772.         CPPMACRO_FORCEINLINE
  773.         CPPMACRO_CONSTEXPR
  774.         bool IsHasItems() const CPPMACRO_NOEXCEPT
  775.         {return (mCount != 0u);}
  776.  
  777.         /**
  778.          * @brief     Check if this linked list class contains given item.
  779.          *
  780.          * @param     Value Value to lookup for.
  781.          *
  782.          * @returns True if found.
  783.          */
  784.         CPPMACRO_FORCEINLINE
  785.         CPPMACRO_CONSTEXPR
  786.         bool IsHasItem(const_reference Value) const CPPMACRO_NOEXCEPT
  787.         {
  788.             for (decltype(mCount) Iterator = 0u; Iterator < mCount; Iterator++)
  789.             {
  790.                 if (GetValueById(Iterator) == Value)
  791.                 {
  792.                     return (true);
  793.                 }
  794.             }
  795.            
  796.             return (false);
  797.         }
  798.  
  799.         /**
  800.          * @brief     Check if this linked list class contains given dynamically allocated (raw) array.
  801.          *
  802.          * @param    Raw    Dynamically allocated (raw) array.
  803.          * @param     Count Amount of items.
  804.          *
  805.          * @returns True if found.
  806.          */
  807.         CPPMACRO_FORCEINLINE
  808.         CPPMACRO_CONSTEXPR
  809.         bool IsHasRawArray(const_pointer Raw, const size_type Count) const CPPMACRO_NOEXCEPT
  810.         {
  811.             if (Raw != nullptr && Count > 0u)
  812.             {
  813.                 for (decltype(mCount) Iterator = 0u; Iterator < Count; Iterator++)
  814.                 {
  815.                     const value_type Value = GetValueById(Iterator);
  816.  
  817.                     if (IsHasItem(Value))
  818.                     {
  819.                         return (true);
  820.                     }
  821.                 }
  822.             }
  823.            
  824.             return (false);
  825.         }
  826.  
  827.         /**
  828.          * @brief    Check if this linked list class contains given initialization list.
  829.          *
  830.          * @param    InitializerList Initialization list.
  831.          *
  832.          * @returns True if found.
  833.          */
  834.         CPPMACRO_FORCEINLINE
  835.         CPPMACRO_CONSTEXPR
  836.         bool IsHasInitializerList(const std::initializer_list<value_type> InitializerList) const CPPMACRO_NOEXCEPT
  837.         {
  838.             if (InitializerList.size())
  839.             {
  840.                 for (const_reference Value : InitializerList)
  841.                 {
  842.                     decltype(mNodeHead) NodeIterator = Create(Value);
  843.                     if (NodeIterator != CPPMACRO_INVALID_NODE)
  844.                     {
  845.                         return (NodeIterator->GetData() == Value);
  846.                     }
  847.                 }
  848.             }
  849.  
  850.             return (false);
  851.         }
  852.  
  853.         /**
  854.          * @brief    Check if this linked list class contains given list.
  855.          *
  856.          * @param    Other Another linked list class.
  857.          *
  858.          * @returns True if found.
  859.          */
  860.         CPPMACRO_FORCEINLINE
  861.         CPPMACRO_CONSTEXPR
  862.         bool IsHasList(const SingleLinkedList<value_type>& Other) const CPPMACRO_NOEXCEPT
  863.         {
  864.             for (decltype(mCount) Iterator = 0u; Iterator < Other.mCount; Iterator++)
  865.             {
  866.                 if (GetValueById(Iterator) !=  Other.GetValueById(Iterator))
  867.                 {
  868.                     return (false);
  869.                 }
  870.             }
  871.        
  872.             return (true);
  873.         }
  874.  
  875.         /**
  876.          * @brief    Check if this linked list class and it's content equals given list.
  877.          *
  878.          * @param   Other Another linked list class.
  879.          *
  880.          * @returns True if equals.
  881.          */
  882.         CPPMACRO_FORCEINLINE
  883.         CPPMACRO_CONSTEXPR
  884.         bool IsEquals(const this_type& Other) const CPPMACRO_NOEXCEPT
  885.         {
  886.             if (Other.mCount != mCount)
  887.             {
  888.                 return (false);
  889.             }
  890.  
  891.             if (Other != *this)
  892.             {
  893.                 for (decltype(mCount) Iterator = 0u; Iterator < mCount; Iterator++)
  894.                 {
  895.                     if (GetValueById(Iterator) != Other.GetValueById(Iterator))
  896.                     {
  897.                         return (false);
  898.                     }
  899.                 }
  900.             }
  901.  
  902.             return (true);
  903.         }
  904.  
  905.         /**
  906.          * @brief    Get value at the beggining of a linked list class.
  907.          *
  908.          * @returns Value of first item.
  909.          */
  910.         CPPMACRO_FORCEINLINE
  911.         CPPMACRO_CONSTEXPR
  912.         value_type GetFront() CPPMACRO_NOEXCEPT
  913.         {return (mNodeHead->GetData());}
  914.  
  915.         /**
  916.          * @brief       Get value at the end of a linked list class.
  917.          *
  918.          * @returns     Value of last item.
  919.          */
  920.         CPPMACRO_FORCEINLINE
  921.         CPPMACRO_CONSTEXPR
  922.         value_type GetBack() CPPMACRO_NOEXCEPT
  923.         {return (GetValueById(mCount));}
  924.  
  925.         /**
  926.          * @brief    Get the value being stored at given index in a linked list class.
  927.          *
  928.          * @param   Id Index at which to look for value.
  929.          *
  930.          * @returns Value.
  931.          */
  932.         CPPMACRO_FORCEINLINE
  933.         CPPMACRO_CONSTEXPR
  934.         const_reference GetValueById(const size_type Id) const CPPMACRO_NOEXCEPT
  935.         {
  936.             decltype(mNodeHead) NodeIterator = mNodeHead;
  937.             decltype(mCount)    IdIterator   = 0u;
  938.  
  939.             while (IdIterator < Id)
  940.             {
  941.                 NodeIterator = NodeIterator->GetNext();
  942.                 IdIterator++;
  943.             }
  944.  
  945.             return (NodeIterator->GetData());
  946.         }
  947.  
  948.         /**
  949.          * @brief    Get the index of the first occurrence for a given value.
  950.          *
  951.          * @param   Value   Value to look up for in a linked list class.
  952.          *
  953.          * @returns Index.
  954.          */
  955.         CPPMACRO_FORCEINLINE
  956.         CPPMACRO_CONSTEXPR
  957.         size_type GetIdByValue(const_reference Value) const CPPMACRO_NOEXCEPT
  958.         {
  959.             decltype(mNodeHead) NodeIterator = mNodeHead;
  960.             decltype(mCount)    IdIterator   = 0u;
  961.  
  962.             while (NodeIterator != CPPMACRO_INVALID_NODE)
  963.             {
  964.                 if (NodeIterator->GetData() == Value)
  965.                 {
  966.                     return (IdIterator);
  967.                 }
  968.  
  969.                 NodeIterator = NodeIterator->GetNext();
  970.                 IdIterator++;
  971.             }
  972.  
  973.             return (0u);
  974.         }
  975.  
  976.         /**
  977.          * @brief   Get the index of the last occurrence for a given value.
  978.          *
  979.          * @param   Value Value to look up for in a linked list class.
  980.          *
  981.          * @returns Index.
  982.          */
  983.         CPPMACRO_FORCEINLINE
  984.         CPPMACRO_CONSTEXPR
  985.         size_type GetLastIdByValue(const_reference Value) const CPPMACRO_NOEXCEPT
  986.         {
  987.             decltype(mNodeHead) NodeIterator = mNodeHead;
  988.             decltype(mCount)    IdIterator   = 0u,
  989.                                 IdCounter    = 0u;
  990.  
  991.             while (NodeIterator != CPPMACRO_INVALID_NODE)
  992.             {
  993.                 if (NodeIterator->GetData() == Value)
  994.                 {
  995.                     IdCounter = IdIterator;
  996.                 }
  997.  
  998.                 NodeIterator = NodeIterator->GetNext();
  999.                 IdIterator++;
  1000.             }
  1001.  
  1002.             return (IdCounter);
  1003.         }
  1004.  
  1005.         /**
  1006.          * @brief    Get amount of items in this linked list class.
  1007.          *
  1008.          * @returns Size of a list.
  1009.          */
  1010.         CPPMACRO_FORCEINLINE
  1011.         CPPMACRO_CONSTEXPR
  1012.         size_type GetSize() const CPPMACRO_NOEXCEPT
  1013.         {
  1014.             decltype(mNodeHead) NodeIterator = mNodeHead;
  1015.             decltype(mCount)    ItemCounter  = 0u;
  1016.  
  1017.             while (NodeIterator != CPPMACRO_INVALID_NODE)
  1018.             {
  1019.                 NodeIterator = NodeIterator->GetNext();
  1020.                 ItemCounter++;
  1021.             }
  1022.  
  1023.             return (ItemCounter);
  1024.         }
  1025.  
  1026.         /**
  1027.          * @brief   Clear the list.
  1028.          */
  1029.         CPPMACRO_FORCEINLINE
  1030.         CPPMACRO_CONSTEXPR
  1031.         void Clear() CPPMACRO_NOEXCEPT
  1032.         {
  1033. #if defined (CPPMACRO_CACHE_COUNT)
  1034.             mCount = 0u;
  1035. #endif
  1036.         }
  1037.  
  1038.         /**
  1039.          * @brief       Create a new node instance with given value.
  1040.          *
  1041.          * @param[in]   Value   Value in node.
  1042.          */
  1043.         CPPMACRO_FORCEINLINE
  1044.         CPPMACRO_CONSTEXPR
  1045.         SingleLinkedListNode<value_type>*
  1046.         Create(const_reference Value) const CPPMACRO_NOEXCEPT
  1047.         {
  1048.             const decltype(mNodeHead) NewNode = new (std::nothrow) SingleLinkedListNode<value_type>(Value);
  1049.             if (NewNode != CPPMACRO_INVALID_NODE)
  1050.             {
  1051.                 return (NewNode);
  1052.             }
  1053.  
  1054.             return (CPPMACRO_INVALID_NODE);
  1055.         }
  1056.  
  1057.         /**
  1058.          * @brief   Set a new size of a linked list class.
  1059.          *
  1060.          * @param   NewCount New size to set.
  1061.          * @param   Value    Value to set in case willing size of a linked list is more then old one.
  1062.          */
  1063.         CPPMACRO_FORCEINLINE
  1064.         CPPMACRO_CONSTEXPR
  1065.         void Resize(const size_type NewCount, const_reference Value = 0u) CPPMACRO_NOEXCEPT
  1066.         {
  1067.             if (NewCount != GetSize())
  1068.             {
  1069.                 if (NewCount > GetSize())
  1070.                 {
  1071.                     while (GetSize() != NewCount)
  1072.                     {Append(Value);}
  1073.                 }
  1074.  
  1075.                 if (NewCount < GetSize())
  1076.                 {
  1077.                     while (GetSize() != NewCount)
  1078.                     {DeleteBack();}
  1079.                 }
  1080.             }
  1081.         }
  1082.  
  1083.         /**
  1084.          * @brief   Replaces the item at the specified index in this linked list class with a new one.
  1085.          *
  1086.          * @param   Id    Index at which to replace.
  1087.          * @param   Value Value.
  1088.          */
  1089.         CPPMACRO_FORCEINLINE
  1090.         CPPMACRO_CONSTEXPR  
  1091.         void Set(const size_type Id, const_reference Value) CPPMACRO_NOEXCEPT
  1092.         {
  1093.             decltype (mNodeHead) NodeIterator = mNodeHead;
  1094.             decltype (mCount)    IdIterator   = 0u;
  1095.  
  1096.             while (NodeIterator != CPPMACRO_INVALID_NODE)
  1097.             {
  1098.                 if (IdIterator == Id)
  1099.                 {
  1100.                     decltype(mNodeHead) NewNode = Create(Value);
  1101.                     if (NewNode != CPPMACRO_INVALID_NODE)
  1102.                     {
  1103.                         NodeIterator->SetData(Value);
  1104.                     }
  1105.                 }
  1106.  
  1107.                 IdIterator++;
  1108.                 NodeIterator = NodeIterator->GetNext();
  1109.             }
  1110.         }
  1111.    
  1112.         /**
  1113.          * @brief Insert the item at the specified index in this linked list class.
  1114.          *
  1115.          * @param Id     Index to insert in.
  1116.          * @param Value Value.
  1117.          */
  1118.         CPPMACRO_FORCEINLINE
  1119.         CPPMACRO_CONSTEXPR
  1120.         void Insert(const size_type Id, const_reference Value) CPPMACRO_NOEXCEPT
  1121.         {
  1122.             if (!IsHasItems())
  1123.             {
  1124.                 Append(Value);
  1125.                 return;
  1126.             }
  1127.  
  1128.             const decltype (mNodeHead) NewNode = Create(Value);
  1129.             if (Id == 0u)
  1130.             {
  1131.                 NewNode->SetNext(mNodeHead);
  1132.                 mNodeHead = NewNode;
  1133. #if defined (CPPMACRO_CACHE_COUNT)
  1134.                 mCount++;
  1135. #endif
  1136.             } else if (Id == mCount)
  1137.             {   Append(Value);
  1138.             } else {
  1139.                 decltype(mNodeHead) NodeIterator = mNodeHead, NodePrevious = CPPMACRO_INVALID_NODE;
  1140.                 if (NodeIterator != CPPMACRO_INVALID_NODE)
  1141.                 {
  1142.                     decltype(mCount) IdIterator = 1u;
  1143.                     while (IdIterator < Id)
  1144.                     {
  1145.                         NodePrevious = NodeIterator;
  1146.                         NodeIterator = NodeIterator->GetNext();
  1147.                         IdIterator++;
  1148.                     }
  1149.  
  1150.                     NewNode->SetNext(NodeIterator);
  1151.                     NodePrevious->SetNext(NewNode);
  1152.                 }
  1153.             }
  1154.         }
  1155.  
  1156.         /**
  1157.          * @brief   Insert given raw array into given position of the linked list class.
  1158.          *
  1159.          * @param   Id      Id after which to insert into a raw array.
  1160.          * @param   Raw     Dynamically allocated (raw) array.
  1161.          * @param   Count   Amount of items.
  1162.          */
  1163.         CPPMACRO_FORCEINLINE
  1164.         CPPMACRO_CONSTEXPR
  1165.         void InsertRawArray(const size_type Id, const_pointer Raw, const size_type Count) CPPMACRO_NOEXCEPT
  1166.         {
  1167.             if (Id > 0u && Raw != nullptr && Count > 0u)
  1168.             {
  1169.                 decltype(mCount) IdIterator = Id;
  1170.                 while (IdIterator < Id)
  1171.                 {
  1172.                     const value_type Value = GetValueById(IdIterator);
  1173.                     Insert(IdIterator, Value);
  1174.                     IdIterator++;
  1175.                 }
  1176.             }
  1177.         }
  1178.  
  1179.         /**
  1180.          * @brief   Insert given initialization list into given position of the linked list class.
  1181.          *
  1182.          * @param   Id               Id after which to insert initialization list.
  1183.          * @param   InitializerList  Initialization list.
  1184.          */
  1185.         CPPMACRO_FORCEINLINE
  1186.         CPPMACRO_CONSTEXPR
  1187.         void InsertInitializerList(const size_type Id, const std::initializer_list<value_type> InitializerList) CPPMACRO_NOEXCEPT
  1188.         {
  1189.             if (InitializerList.size())
  1190.             {
  1191.                 decltype(mCount) IdIterator = Id;
  1192.                 for (const_reference Value : InitializerList)
  1193.                 {
  1194.                     Insert(IdIterator, Value);
  1195.                     IdIterator++;
  1196.                 }
  1197.             }
  1198.         }
  1199.  
  1200.         /**
  1201.          * @brief   Insert given linked list into given position of the linked list class.
  1202.          *
  1203.          * @param Id     Id after which to insert linked list.
  1204.          * @param Other Linked list class.
  1205.          */
  1206.         CPPMACRO_FORCEINLINE
  1207.         CPPMACRO_CONSTEXPR
  1208.         void InsertLinkedList(const size_type Id, const this_type& Other) const CPPMACRO_NOEXCEPT
  1209.         {
  1210.             if (Other.IsHasItems())
  1211.             {
  1212.                 decltype(mCount) IdIterator = Id;
  1213.                 while (IdIterator < Id)
  1214.                 {
  1215.                     Insert(Id, GetValueById(IdIterator));
  1216.                     IdIterator++;
  1217.                 }
  1218.             }
  1219.         }
  1220.        
  1221.         /**
  1222.          * @brief   Append a single value at the end of a linked list class.
  1223.          *
  1224.          * @param   Value   Value used to append.
  1225.          */
  1226.         CPPMACRO_FORCEINLINE
  1227.         CPPMACRO_CONSTEXPR
  1228.         void Append(const_reference Value) CPPMACRO_NOEXCEPT
  1229.         {
  1230.             const decltype(mNodeHead) NewNode = Create(Value);
  1231.             if (NewNode != CPPMACRO_INVALID_NODE)
  1232.             {
  1233.                 if (!IsHasItems())
  1234.                 {
  1235.                     mNodeHead = NewNode;
  1236. #if defined (CPPMACRO_CACHE_COUNT)
  1237.                     mCount = 1u;
  1238. #endif
  1239.                 } else {
  1240.                     decltype(mNodeHead) NodeIterator = mNodeHead;
  1241.                     while (NodeIterator->GetNext() != CPPMACRO_INVALID_NODE)
  1242.                     {
  1243.                         NodeIterator = NodeIterator->GetNext();
  1244.                     }
  1245.  
  1246.                     NodeIterator->SetNext(NewNode);
  1247.                     mCount++;
  1248.  
  1249.                 }
  1250.             }
  1251.         }
  1252.  
  1253.         /**
  1254.          * @brief   Append a dynamically allocated array (raw array) at the end of a linked list class.
  1255.          *
  1256.          * @param Raw    Dynamically allocated array (raw array).
  1257.          * @param Count Amount of items.
  1258.          */
  1259.         CPPMACRO_FORCEINLINE
  1260.         CPPMACRO_CONSTEXPR
  1261.         void AppendRawArray(const_pointer Raw, const size_type Count) CPPMACRO_NOEXCEPT
  1262.         {
  1263.             if (Raw != nullptr && Count > 0u)
  1264.             {
  1265.                 for (decltype(mCount) Iterator = 0u; Iterator < Count; Iterator++)
  1266.                 {
  1267.                     Append(Raw[Iterator]);
  1268.                 }
  1269.             }
  1270.         }
  1271.  
  1272.         /**
  1273.          * @brief   Append a list of values at the end of a linked list class.
  1274.          *
  1275.          * @param InitializerList   Initialization list.
  1276.          */
  1277.         CPPMACRO_FORCEINLINE
  1278.         CPPMACRO_CONSTEXPR
  1279.         void AppendInitializerList(const std::initializer_list<value_type>& InitializerList) CPPMACRO_NOEXCEPT
  1280.         {
  1281.             if (InitializerList.size() != 0u)
  1282.             {
  1283.                 for (const_reference Value : InitializerList)
  1284.                 {
  1285.                     Append(Value);
  1286.                 }
  1287.             }
  1288.         }
  1289.  
  1290.         /**
  1291.          * @brief   Append a linked list class at the end of a linked list class.
  1292.          *
  1293.          * @param Other Another linked list class.
  1294.          */
  1295.         CPPMACRO_FORCEINLINE
  1296.         CPPMACRO_CONSTEXPR
  1297.         void AppendList(const this_type& Other) CPPMACRO_NOEXCEPT
  1298.         {
  1299.             if (Other.IsHasItems())
  1300.             {
  1301.                 decltype(mNodeHead) NodeIterator = Other.mNodeHead;
  1302.                 while (NodeIterator != CPPMACRO_INVALID_NODE)
  1303.                 {
  1304.                     Append(NodeIterator->GetData());
  1305.                     NodeIterator = NodeIterator->GetNext();
  1306.                 }
  1307.             }
  1308.         }
  1309.  
  1310.         /**
  1311.          * @brief Insert value at the beggining of the linked list class,
  1312.          *
  1313.          * @param Value Value to push at the beggining.
  1314.          */
  1315.         CPPMACRO_FORCEINLINE
  1316.         CPPMACRO_CONSTEXPR
  1317.         void InsertFront(const_reference Value) CPPMACRO_NOEXCEPT
  1318.         {Insert(0u, Value);}
  1319.  
  1320.         /**
  1321.          * @brief Insert value at the end of the linked list class,
  1322.          *
  1323.          * @param Value Value to push at the end.
  1324.          */
  1325.         CPPMACRO_FORCEINLINE
  1326.         CPPMACRO_CONSTEXPR
  1327.         void InsertBack(const_reference Value) CPPMACRO_NOEXCEPT
  1328.         {Append(Value);}
  1329.  
  1330.         /**
  1331.          * @brief   Delete item with given id from linked list class.
  1332.          *
  1333.          * @param   Id  Index to delete,
  1334.          */
  1335.         CPPMACRO_FORCEINLINE
  1336.         CPPMACRO_CONSTEXPR  
  1337.         void DeleteById(const size_type Id) CPPMACRO_NOEXCEPT
  1338.         {
  1339.             if (!IsHasItems() &&
  1340.                 Id > mCount)
  1341.             {
  1342.                 return;
  1343.             }
  1344.  
  1345.             decltype(mNodeHead) NodeIterator = mNodeHead;
  1346.             if (NodeIterator != CPPMACRO_INVALID_NODE)
  1347.             {
  1348.                 decltype(mCount) IdIterator = Id;
  1349.                 while (IdIterator < Id)
  1350.                 {
  1351.                     NodeIterator = NodeIterator->GetNext();
  1352.                     if (NodeIterator != CPPMACRO_INVALID_NODE)
  1353.                     {
  1354.                         IdIterator++;
  1355.                     }
  1356.                 }
  1357.  
  1358.                 NodeIterator->SetNext(NodeIterator->GetNext()->GetNext());
  1359.             }
  1360.         }
  1361.  
  1362.         /**
  1363.          * @brief Delete item with given value from linked list class.
  1364.          *
  1365.          * @param Value Value used to delete.
  1366.          */
  1367.         CPPMACRO_FORCEINLINE
  1368.         CPPMACRO_CONSTEXPR
  1369.         void DeleteByValue(const_reference Value) CPPMACRO_NOEXCEPT
  1370.         {
  1371.             if (IsHasItems())
  1372.             {
  1373.                 const CPPMACRO_CONSTEXPR size_type Id = GetIdByValue(Value);
  1374.                 if (Id > 0u)
  1375.                 {
  1376.                     DeleteById(Id);
  1377.                 }
  1378.             }
  1379.         }
  1380.  
  1381.         /**
  1382.          * @brief Delete all occurances with given values from linked list class.
  1383.          *
  1384.          * @param Value Values used to delete.
  1385.          */
  1386.         CPPMACRO_FORCEINLINE
  1387.         CPPMACRO_CONSTEXPR
  1388.         void DeleteByValueAllOccurances(const_reference Value) CPPMACRO_NOEXCEPT
  1389.         {
  1390.             if (IsHasItems())
  1391.             {
  1392.                 decltype(mNodeHead) NodeIterator = mNodeHead;
  1393.                 decltype(mCount)    IdIterator   = 0u;
  1394.  
  1395.                 while (IdIterator < mCount)
  1396.                 {
  1397.                     NodeIterator = NodeIterator->GetNext();
  1398.                     if (NodeIterator->GetData() == Value)
  1399.                     {
  1400.                         DeleteById(IdIterator);
  1401.                     }
  1402.  
  1403.                     IdIterator++;
  1404.                 }
  1405.             }
  1406.         }
  1407.  
  1408.         /**
  1409.          * @brief   Delete value located in from of a linked list class.
  1410.          */
  1411.         CPPMACRO_FORCEINLINE
  1412.         CPPMACRO_CONSTEXPR
  1413.         void DeleteFront() CPPMACRO_NOEXCEPT
  1414.         {
  1415.             if (IsHasItems())
  1416.             {
  1417.                 DeleteById(0u);
  1418.             }
  1419.         }
  1420.  
  1421.         /**
  1422.          * @brief   Delete value located at back of a linked list class.
  1423.          */
  1424.         CPPMACRO_FORCEINLINE
  1425.         CPPMACRO_CONSTEXPR
  1426.         void DeleteBack() CPPMACRO_NOEXCEPT
  1427.         {
  1428.             if (IsHasItems())
  1429.             {
  1430.                 DeleteById(GetSize());
  1431.             }
  1432.         }
  1433.  
  1434.         /**
  1435.          * @brief   Delete first value from a linked list and return deleted value.
  1436.          *
  1437.          * @return  Deleted value.
  1438.          */
  1439.         CPPMACRO_FORCEINLINE
  1440.         CPPMACRO_CONSTEXPR
  1441.         value_type PopFront() CPPMACRO_NOEXCEPT
  1442.         {
  1443.             const CPPMACRO_CONSTEXPR value_type Value = GetFront();
  1444.             DeleteById(0u);
  1445.  
  1446.             return (Value);
  1447.         }
  1448.  
  1449.         /**
  1450.          * @brief   Delete last value from a linked list and return deleted value.
  1451.          *
  1452.          * @return  Deleted value.
  1453.          */
  1454.         CPPMACRO_FORCEINLINE
  1455.         CPPMACRO_CONSTEXPR
  1456.         value_type PopBack() CPPMACRO_NOEXCEPT
  1457.         {
  1458.             const CPPMACRO_CONSTEXPR value_type Value = GetBack();
  1459.             DeleteById(mCount);
  1460.  
  1461.             return (Value);
  1462.         }
  1463.  
  1464.         /**
  1465.          * @brief   Create a new instance of a linked list class by taking initial index and last index of this class.
  1466.          *
  1467.          * @param  From Index used to start building linked list class.
  1468.          * @param   To   Index to finish linked list.
  1469.          *
  1470.          * @return  New list.
  1471.          */
  1472.         CPPMACRO_FORCEINLINE
  1473.         CPPMACRO_CONSTEXPR
  1474.         this_type Create(const size_type From, const size_type To) const CPPMACRO_NOEXCEPT
  1475.         {
  1476.             if (From > 0u && To > From && IsHasItems())
  1477.             {
  1478.                 const CPPMACRO_CONSTEXPR this_type CreateNewListClass;
  1479.                 decltype(mCount) IdIterator = From;
  1480.  
  1481.                 while (IdIterator < To)
  1482.                 {
  1483.                     const CPPMACRO_CONSTEXPR value_type Value = GetValueById(IdIterator);
  1484.                     CreateNewListClass.Insert(IdIterator, Value);
  1485.                     IdIterator++;
  1486.                 }
  1487.  
  1488.                 return (CreateNewListClass);
  1489.             }
  1490.  
  1491.             return (*this);
  1492.         }
  1493.  
  1494.         /**
  1495.          * @brief    Use C++'s access operator to get a value at given index.
  1496.          *
  1497.          * @param    Index Index to lookup value at.
  1498.          *
  1499.          * @returns Value at given index.
  1500.          */
  1501.         CPPMACRO_FORCEINLINE value_type       operator[](const size_type Index)       {return (GetValueById(Index));}
  1502.         CPPMACRO_FORCEINLINE const value_type operator[](const size_type Index) const {return (GetValueById(Index));}
  1503.  
  1504.         /**
  1505.          * @brief     Overloaded comparison operators.
  1506.          *
  1507.          * @param     Other Another linked list class used to compare items with.
  1508.          *
  1509.          * @returns True if condition were met.
  1510.          */
  1511.         CPPMACRO_FORCEINLINE bool operator< (this_type& Other) const CPPMACRO_NOEXCEPT {return ((mCount <  Other.mCount));}
  1512.         CPPMACRO_FORCEINLINE bool operator<=(this_type& Other) const CPPMACRO_NOEXCEPT {return ((mCount <= Other.mCount));}
  1513.         CPPMACRO_FORCEINLINE bool operator> (this_type& Other) const CPPMACRO_NOEXCEPT {return ((mCount >  Other.mCount));}
  1514.         CPPMACRO_FORCEINLINE bool operator>=(this_type& Other) const CPPMACRO_NOEXCEPT {return ((mCount >= Other.mCount));}
  1515.  
  1516.         /**
  1517.          * @brief     Overloaded equality operator.
  1518.          *
  1519.          * @param   Other Another linked list class used to check.
  1520.          *
  1521.          * @returns True on equality.
  1522.          */
  1523.         CPPMACRO_FORCEINLINE
  1524.         CPPMACRO_CONSTEXPR
  1525.         bool operator==(this_type& Other) const CPPMACRO_NOEXCEPT
  1526.         {
  1527.             if (IsEquals(Other))
  1528.             {
  1529.                 return (true);
  1530.             }
  1531.            
  1532.            
  1533.             return (false);
  1534.         }
  1535.  
  1536.         /**
  1537.          * @brief     Overloaded enequality operator.
  1538.          *
  1539.          * @param     Other Another linked list class used to check.
  1540.          *
  1541.          * @returns True on enequality.
  1542.          */
  1543.         CPPMACRO_FORCEINLINE
  1544.         CPPMACRO_CONSTEXPR
  1545.         bool operator!=(this_type& Other) const CPPMACRO_NOEXCEPT
  1546.         {
  1547.             if (!(operator==(Other)))
  1548.             {
  1549.                 return (true);
  1550.             }
  1551.  
  1552.             return (false);
  1553.         }
  1554.  
  1555.         /**
  1556.          * @brief    Overloaded assignment operator.
  1557.          *
  1558.          * @param    Other Instance of a linked list class to take items from.
  1559.          *
  1560.          * @returns Linked list class.
  1561.          */
  1562.         CPPMACRO_FORCEINLINE
  1563.         CPPMACRO_CONSTEXPR
  1564.         this_type& operator=(const this_type& Other) const CPPMACRO_NOEXCEPT
  1565.         {
  1566.             if (std::addressof(Other) != this &&
  1567.                 Other.IsHasItems())
  1568.             {
  1569.                 const CPPMACRO_CONSTEXPR this_type LinkedList;
  1570.  
  1571.                 LinkedList.Clear();
  1572.                 LinkedList.InsertLinkedList(0u, Other);
  1573.                 return (LinkedList);
  1574.             }
  1575.  
  1576.             return (*this);
  1577.         }
  1578.  
  1579.         /**
  1580.          * @brief    Overloaded assignment operator.
  1581.          *
  1582.          * @param    Other Instance of a linked list class to take items from.
  1583.          *
  1584.          * @returns Linked list class.
  1585.          */
  1586.         CPPMACRO_FORCEINLINE
  1587.         CPPMACRO_CONSTEXPR
  1588.         this_type operator+=(const this_type& Other) const CPPMACRO_NOEXCEPT
  1589.         {
  1590.             const CPPMACRO_CONSTEXPR this_type LinkedList;
  1591.  
  1592.             LinkedList.operator=(this);
  1593.             LinkedList.AppendList(Other);
  1594.             return (*this);
  1595.         }
  1596.  
  1597.         /**
  1598.          * @brief    Build a string which represents content of this forward list class.
  1599.          *
  1600.          * @returns String with items.
  1601.          */
  1602.         CPPMACRO_FORCEINLINE
  1603.         CPPMACRO_CONSTEXPR
  1604.         std::string toString() const CPPMACRO_NOEXCEPT
  1605.         {
  1606.             decltype(mNodeHead) NodeIterator = mNodeHead;
  1607.             std::stringstream StreamContent;
  1608.            
  1609.             while (NodeIterator != CPPMACRO_INVALID_NODE)
  1610.             {
  1611.                 StreamContent << NodeIterator->GetData() << " ";
  1612.                 NodeIterator = NodeIterator->GetNext();
  1613.             }
  1614.  
  1615.             StreamContent << std::endl;
  1616.             return (StreamContent.str());
  1617.         }
  1618.  
  1619.         /**
  1620.          * @brief   Output list content by using standart output device.
  1621.          */
  1622.         CPPMACRO_FORCEINLINE
  1623.         CPPMACRO_CONSTEXPR
  1624.         void Print() const CPPMACRO_NOEXCEPT
  1625.         {
  1626.             if (!IsHasItems()) {
  1627.                 std::cout << "SingleLinkedList: linked list class has no items!" << std::endl;
  1628.                 return;
  1629.             }
  1630.  
  1631.             std::cout << toString() << std::endl;
  1632.         }
  1633.     };
  1634. }
  1635. }
  1636. #endif // SINGLELINKEDLIST_GUARD
  1637.  
  1638. //
  1639. // SingleLinkedListNode.h
  1640. //
  1641.  
  1642. #ifndef SINGLELINKEDLISTNODE_GUARD
  1643. #define SINGLELINKEDLISTNODE_GUARD
  1644.  
  1645. #include "../../../Includes.h"
  1646. #include "../../../Macro.h"
  1647.  
  1648.  
  1649. /**
  1650.  * \brief Invalid node.
  1651.  */
  1652. #define CPPMACRO_INVALID_NODE nullptr
  1653.  
  1654. namespace Structures
  1655. {
  1656.  
  1657.     /**
  1658.      * @brief   Node class.
  1659.      *
  1660.      * @param   Value   Value this node instance has.
  1661.      */
  1662.     template<typename Type>
  1663.     class SingleLinkedListNode
  1664.     {
  1665.  
  1666.         /** @defgroup   STL STL-like interface for a node class.
  1667.          *              Used for compatibility with STL.
  1668.          * @{
  1669.          */
  1670.         using this_type             = SingleLinkedListNode<Type>;
  1671.         using value_type            = Type;
  1672.         using reference             = Type&;
  1673.         using const_reference       = const Type&;
  1674.         using pointer               = Type*;
  1675.         using const_pointer         = const Type*;
  1676.  
  1677.         /** @defgroup   Data group.
  1678.          * @{
  1679.          */
  1680.  
  1681.          /**
  1682.           * @brief      Next node followed by this node instance.
  1683.           */
  1684.         this_type* mNext;
  1685.  
  1686.         /**
  1687.          * @brief       Value this node instance has.
  1688.          */
  1689.         value_type mData;
  1690.  
  1691.     public:
  1692.  
  1693.         /**
  1694.          * @brief       Default constructor.
  1695.          *
  1696.          *              Create a new node with value initialized to zero.
  1697.          */
  1698.         CPPMACRO_FORCEINLINE
  1699.         CPPMACRO_CONSTEXPR
  1700.         SingleLinkedListNode() : mNext {CPPMACRO_INVALID_NODE}, mData {0u}
  1701.         {   }
  1702.  
  1703.         /**
  1704.          * @brief       User-defined constructor.
  1705.          *
  1706.          *              Create a new node with value provided in constructor's argument.
  1707.          *
  1708.          * @param       Value   Value this node instance has.
  1709.          */
  1710.         explicit
  1711.         CPPMACRO_FORCEINLINE
  1712.         CPPMACRO_CONSTEXPR
  1713.         SingleLinkedListNode(const_reference Value) : mNext {CPPMACRO_INVALID_NODE}, mData {Value}
  1714.         {   }
  1715.  
  1716.         /**
  1717.          * @brief       User-defined constructor.
  1718.          *
  1719.          * @param       Value   Value this node instance has.
  1720.          * @param       Next    Next node instance followed by this node instance.
  1721.          */
  1722.         explicit
  1723.         CPPMACRO_FORCEINLINE
  1724.         CPPMACRO_CONSTEXPR
  1725.         SingleLinkedListNode(const_reference Value, this_type* Next) : mNext {Next}, mData {Value}
  1726.         {   }
  1727.  
  1728.         /**
  1729.          * @brief       Get value in this node instance.
  1730.          *
  1731.          * @returns Value.
  1732.          */
  1733.         CPPMACRO_FORCEINLINE
  1734.         CPPMACRO_CONSTEXPR
  1735.         reference GetData() CPPMACRO_NOEXCEPT
  1736.         {return (mData);}
  1737.  
  1738.         /**
  1739.          * @brief       Set data this node instance going to contain.
  1740.          *
  1741.          * @param       Value   Value.
  1742.          */
  1743.         CPPMACRO_FORCEINLINE
  1744.         CPPMACRO_CONSTEXPR
  1745.         void SetData(const_reference Value) CPPMACRO_NOEXCEPT
  1746.         {mData = Value;}
  1747.  
  1748.         /**
  1749.          * @brief       Get next node followed by this node instance.
  1750.          *
  1751.          * @returns Next node.
  1752.          */
  1753.         CPPMACRO_FORCEINLINE
  1754.         CPPMACRO_CONSTEXPR
  1755.         this_type* GetNext() const CPPMACRO_NOEXCEPT
  1756.         {return (mNext);}
  1757.  
  1758.         /**
  1759.          * @brief       Set next node followed by this node instance.
  1760.          *
  1761.          * @param       Next    Next node.
  1762.          */
  1763.         CPPMACRO_FORCEINLINE
  1764.         CPPMACRO_CONSTEXPR
  1765.         void SetNext(this_type* Next) CPPMACRO_NOEXCEPT
  1766.         {mNext = Next;}
  1767.     };
  1768. }
  1769. }
  1770. }
  1771.  
  1772. #endif // SINGLELINKEDLISTNODE_GUARD
  1773.  
  1774. //
  1775. // String.h
  1776. //
  1777.  
  1778. #ifndef STRING_GUARD
  1779. #define STRING_GUARD
  1780.  
  1781. #include "../../Includes.h"
  1782. #include "../../Macro.h"
  1783.  
  1784.  
  1785. namespace Structures
  1786. {
  1787.  
  1788.     /**
  1789.      * \brief Class (wrapper) for a raw C string.
  1790.      */
  1791.     class String
  1792.     {
  1793.  
  1794.         /**
  1795.          * \brief
  1796.          */
  1797.         using USING_RAW_C_STRING            = char*;
  1798.        
  1799.         /**
  1800.          * \brief
  1801.          */
  1802.         using USING_RAW_CONSTANT_C_STRING   = const USING_RAW_C_STRING;
  1803.  
  1804.         /**
  1805.          * \brief
  1806.          */
  1807.         using USING_SIZE_TYPE = size_t;
  1808.  
  1809.         /**
  1810.          * \brief Pointer to a C string.
  1811.          */
  1812.         char* mRaw = nullptr;
  1813.  
  1814.     public:
  1815.                
  1816.         /**
  1817.          * \brief Constructor for a raw C string.
  1818.          *
  1819.          * \param Raw mRaw C string.
  1820.          */
  1821.         explicit
  1822.         CPPMACRO_FORCEINLINE
  1823.         String(char* Raw)
  1824.         {mRaw = Raw;}
  1825.  
  1826.         /**
  1827.          * \brief  Get (getter for) a raw C string.
  1828.          *
  1829.          * \return Pointer to a raw C string.
  1830.          */
  1831.         CPPMACRO_FORCEINLINE
  1832.         CPPMACRO_CONSTEXPR
  1833.         USING_RAW_C_STRING Raw() const CPPMACRO_NOEXCEPT
  1834.         {return (mRaw);}
  1835.  
  1836.         /**
  1837.          * \brief  Get string length.
  1838.  
  1839.          * \return String length.
  1840.          */
  1841.         CPPMACRO_FORCEINLINE
  1842.         CPPMACRO_CONSTEXPR
  1843.         size_t GetLength() const CPPMACRO_NOEXCEPT
  1844.         {
  1845.             size_t Count = 0u;
  1846.             while (mRaw[Count] != '\0') {
  1847.                 Count++;
  1848.             }
  1849.  
  1850.             return (Count);
  1851.         }
  1852.  
  1853.         /**
  1854.          * \brief  Get character used to store at given index.
  1855.          *
  1856.          * \param  Index Index to lookup character at.
  1857.          * \return Character at given index.
  1858.          */
  1859.         CPPMACRO_FORCEINLINE
  1860.         CPPMACRO_CONSTEXPR
  1861.         char GetCharacterAtGivenIndex(const size_t Index) const CPPMACRO_NOEXCEPT
  1862.         {
  1863.             if (Index <= 0u) {
  1864.                 return ('\0');
  1865.             }
  1866.  
  1867.             return (mRaw[Index]);
  1868.         }
  1869.  
  1870.         /**
  1871.          * \brief Reverse a string by using STL routines.
  1872.          */
  1873.         CPPMACRO_FORCEINLINE
  1874.         CPPMACRO_CONSTEXPR
  1875.         void ReverseUsingSTLRoutines() const CPPMACRO_NOEXCEPT
  1876.         {
  1877.             std::reverse(mRaw, mRaw+GetLength());
  1878.         }
  1879.     };
  1880. }
  1881.  
  1882. #endif // STRING_GUARD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement