mirror of https://github.com/xfarrow/lasd.git
parent
3e73aeb28d
commit
6788a731b3
|
@ -1,10 +1,19 @@
|
||||||
|
|
||||||
namespace lasd {
|
namespace lasd {
|
||||||
|
// Specific constructor
|
||||||
|
template <typename Data>
|
||||||
|
List<Data>::Node::Node(Data newValue){
|
||||||
|
value = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************** */
|
// Copy constructor
|
||||||
|
template <typename Data>
|
||||||
|
List<Data>::Node::Node(const Data& copyFrom){
|
||||||
|
value = copyFrom.value;
|
||||||
|
}
|
||||||
|
|
||||||
// ...
|
// Move constructor
|
||||||
|
template <typename Data>
|
||||||
/* ************************************************************************** */
|
List<Data>::Node::Node(Data&& moveFrom){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,150 +13,144 @@ namespace lasd {
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class List { // Must extend LinearContainer<Data>, MappableContainer<Data>, and FoldableContainer<Data>
|
class List : virtual public LinearContainer<Data>,
|
||||||
|
virtual public MappableContainer<Data>,
|
||||||
|
virtual public FoldableContainer<Data> { // Must extend LinearContainer<Data>, MappableContainer<Data>, and FoldableContainer<Data>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// using LinearContainer<Data>::???;
|
using LinearContainer<Data>::size;
|
||||||
|
|
||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
|
Data value;
|
||||||
// Data
|
Node* next = nullptr;
|
||||||
// ...
|
|
||||||
|
|
||||||
/* ********************************************************************** */
|
/* ********************************************************************** */
|
||||||
|
|
||||||
// Specific constructors
|
// Specific constructors
|
||||||
// ...
|
Node(Data);
|
||||||
|
|
||||||
/* ********************************************************************** */
|
/* ********************************************************************** */
|
||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
// ...
|
Node(const Node&);
|
||||||
|
|
||||||
// Move constructor
|
// Move constructor
|
||||||
// ...
|
Node(Node&&);
|
||||||
|
|
||||||
/* ********************************************************************** */
|
/* ********************************************************************** */
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ...
|
~Node() = default;
|
||||||
|
|
||||||
/* ********************************************************************** */
|
/* ********************************************************************** */
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// ...
|
bool operator==(const Node&) const noexcept;
|
||||||
|
bool operator!=(const Node&) const noexcept;
|
||||||
/* ********************************************************************** */
|
|
||||||
|
|
||||||
// Specific member functions
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ...
|
struct Node* head = nullptr;
|
||||||
|
struct Node* tail = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
// List() specifiers;
|
List() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific constructor
|
// Specific constructor
|
||||||
// List(argument) specifiers; // A list obtained from a LinearContainer
|
List(const LinearContainer&); // A list obtained from a LinearContainer
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
// List(argument) specifiers;
|
List(const List&);
|
||||||
|
|
||||||
// Move constructor
|
//Move constructor
|
||||||
// List(argument) specifiers;
|
List(List&&);
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~List() specifiers;
|
~List();
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument) specifiers;
|
List& operator=(const List&);
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument) specifiers;
|
List& operator=(List&&) noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers;
|
bool operator==(const List&) const noexcept;
|
||||||
// type operator!=(argument) specifiers;
|
bool operator!=(const List&) const noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// type InsertAtFront(argument) specifier; // Copy of the value
|
void InsertAtFront(const Data&); // Copy of the value
|
||||||
// type InsertAtFront(argument) specifier; // Move of the value
|
void InsertAtFront(Data&&); // Move of the value
|
||||||
// type RemoveFromFront() specifier; // (must throw std::length_error when empty)
|
void RemoveFromFront(); // (must throw std::length_error when empty)
|
||||||
// type FrontNRemove() specifier; // (must throw std::length_error when empty)
|
Data FrontNRemove(); // (must throw std::length_error when empty)
|
||||||
|
|
||||||
// type InsertAtBack(argument) specifier; // Copy of the value
|
void InsertAtBack(const Data&); // Copy of the value
|
||||||
// type InsertAtBack(argument) specifier; // Move of the value
|
void InsertAtBack(Data&&); // Move of the value
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from Container)
|
// Specific member functions (inherited from Container)
|
||||||
|
|
||||||
// type Clear() specifiers; // Override Container member
|
void Clear() override; // Override Container member
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from LinearContainer)
|
// Specific member functions (inherited from LinearContainer)
|
||||||
|
|
||||||
// type Front() specifiers; // Override LinearContainer member (must throw std::length_error when empty)
|
Data& Front() override const; // Override LinearContainer member (must throw std::length_error when empty)
|
||||||
// type Back() specifiers; // Override LinearContainer member (must throw std::length_error when empty)
|
Data& Back() override const; // Override LinearContainer member (must throw std::length_error when empty)
|
||||||
|
|
||||||
// type operator[](argument) specifiers; // Override LinearContainer member (must throw std::out_of_range when out of range)
|
Data& operator[](const ulong) const override; // Override LinearContainer member (must throw std::out_of_range when out of range)
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from MappableContainer)
|
// Specific member functions (inherited from MappableContainer)
|
||||||
|
|
||||||
// using typename MappableContainer<Data>::MapFunctor;
|
using typename MappableContainer<Data>::MapFunctor;
|
||||||
|
|
||||||
// type MapPreOrder(arguments) specifiers; // Override MappableContainer member
|
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
|
||||||
// type MapPostOrder(arguments) specifiers; // Override MappableContainer member
|
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from FoldableContainer)
|
// Specific member functions (inherited from FoldableContainer)
|
||||||
|
|
||||||
// using typename FoldableContainer<Data>::FoldFunctor;
|
using typename FoldableContainer<Data>::FoldFunctor;
|
||||||
|
|
||||||
// type FoldPreOrder(arguments) specifiers; // Override FoldableContainer member
|
void FoldPreOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
|
||||||
// type FoldPostOrder(arguments) specifiers; // Override FoldableContainer member
|
void FoldPostOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Auxiliary member functions (for MappableContainer)
|
// Auxiliary member functions (for MappableContainer)
|
||||||
|
|
||||||
// type MapPreOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards
|
void MapPreOrder(const MapFunctor, void*, struct Node*); // Accessory function executing from one point of the list onwards
|
||||||
// type MapPostOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards
|
void MapPostOrder(const MapFunctor, void*, struct Node*); // Accessory function executing from one point of the list onwards
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Auxiliary member functions (for FoldableContainer)
|
// Auxiliary member functions (for FoldableContainer)
|
||||||
|
|
||||||
// type FoldPreOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards
|
void FoldPreOrder(const FoldFunctor, const void*, void*, struct Node*) const; // Accessory function executing from one point of the list onwards
|
||||||
// type FoldPostOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards
|
void FoldPostOrder(const FoldFunctor, const void*, void*, struct Node*) const; // Accessory function executing from one point of the list onwards
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -121,3 +121,60 @@ void Vector<Data>::Clear(){
|
||||||
Elements = nullptr;
|
Elements = nullptr;
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
Data& Vector<Data>::Front() const{
|
||||||
|
if(size!=0){
|
||||||
|
return Elements[0];
|
||||||
|
}else{
|
||||||
|
return std::length_error("Access to an empty vector");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
Data& Vector<Data>::Back() const{
|
||||||
|
if(size!=0){
|
||||||
|
return Elements[size-1];
|
||||||
|
}else{
|
||||||
|
return std::length_error("Access to an empty vector");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
Data& Vector<Data>::operator[](const ulong index) const{
|
||||||
|
if(index < size){
|
||||||
|
return Elements[index];
|
||||||
|
}else{
|
||||||
|
throw std::out_of_range("Access at index " + std::to_string(index) + " invalid because the vector size is" + std::to_string(size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
void Vector<Data>::MapPreOrder(const MapFunctor fun, void* par){
|
||||||
|
for(ulong i = 0 ; i<size ; i++){
|
||||||
|
fun(Elements[i], par);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
void Vector<Data>::MapPostOrder(const MapFunctor fun, void* par){
|
||||||
|
ulong i = size;
|
||||||
|
while(i>0){
|
||||||
|
fun(Elements[--i], par);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
void Vector<Data>::FoldPreOrder(const FoldFunctor fun, const void* par, void* acc) const{
|
||||||
|
for(ulong i = 0 ; i<size ; ++i){
|
||||||
|
fun(Elements[i], par, acc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template typename<Data>
|
||||||
|
void Vector<Data>::FoldPostOrder(const FoldFunctor fun, const void* par, void* acc) const{
|
||||||
|
ulong i = size;
|
||||||
|
while(i>0){
|
||||||
|
fun(Elements[--i], par, acc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue