mirror of https://github.com/xfarrow/lasd.git
Library 1
Lib. 1: bugfix Lib. 2: added container from Lib. 1
This commit is contained in:
parent
2941c1d298
commit
04acfaf125
|
@ -148,6 +148,10 @@ bool List<Data>::operator!=(const List<Data>& list) const noexcept{
|
||||||
tmp->next = nullptr;
|
tmp->next = nullptr;
|
||||||
delete tmp;
|
delete tmp;
|
||||||
size--;
|
size--;
|
||||||
|
|
||||||
|
if(head==nullptr){
|
||||||
|
tail=nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
|
|
||||||
namespace lasd {
|
namespace lasd {
|
||||||
|
|
||||||
/* ************************************************************************** */
|
template <typename Data>
|
||||||
|
void AuxFoldExists(const Data& dat, const void* val, void* exists){
|
||||||
|
if(dat == *((Data*)val)){
|
||||||
|
*((bool*)exists) = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ...
|
template <typename Data>
|
||||||
|
bool FoldableContainer<Data>::Exists(const Data& dat) const noexcept{
|
||||||
/* ************************************************************************** */
|
bool exists = false;
|
||||||
|
FoldPreOrder(&AuxFoldExists<Data>, &dat, &exists);
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,226 +2,175 @@
|
||||||
#ifndef CONTAINER_HPP
|
#ifndef CONTAINER_HPP
|
||||||
#define CONTAINER_HPP
|
#define CONTAINER_HPP
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
namespace lasd {
|
namespace lasd {
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
class Container {
|
class Container {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// ...
|
ulong size = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~Container() specifiers
|
virtual ~Container() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
Container& operator=(const Container&) = delete; // Copy assignment of abstract types should not be possible.
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
Container& operator=(Container&&) noexcept = delete;; // Move assignment of abstract types should not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator==(const Container&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator!=(const Container&&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// type Empty() specifiers; // (concrete function should not throw exceptions)
|
virtual bool Empty() const noexcept {
|
||||||
|
return (size == 0);
|
||||||
|
} // (concrete function should not throw exceptions)
|
||||||
|
|
||||||
// type Size() specifiers; // (concrete function should not throw exceptions)
|
virtual ulong Size() const noexcept {
|
||||||
|
return size;
|
||||||
// type Clear() specifiers;
|
} // (concrete function should not throw exceptions)
|
||||||
|
|
||||||
|
virtual void Clear() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class LinearContainer { // Must extend Container
|
class LinearContainer : virtual public Container{ // Must extend Container
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~LinearContainer() specifiers
|
virtual ~LinearContainer() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
LinearContainer& operator=(const LinearContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
LinearContainer& operator=(LinearContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator==(const LinearContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator!=(const LinearContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// type Front() specifiers; // (concrete function must throw std::length_error when empty)
|
virtual Data& Front() const = 0; // (concrete function must throw std::length_error when empty)
|
||||||
// type Back() specifiers; // (concrete function must throw std::length_error when empty)
|
virtual Data& Back() const = 0; // (concrete function must throw std::length_error when empty)
|
||||||
|
|
||||||
// type operator[](argument) specifiers; // (concrete function must throw std::out_of_range when out of range)
|
virtual Data& operator[](const ulong) const = 0; // (concrete function must throw std::out_of_range when out of range)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class TestableContainer { // Must extend Container
|
class TestableContainer : virtual public Container{ // Must extend Container
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~TestableContainer() specifiers
|
virtual ~TestableContainer() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
TestableContainer& operator=(const TestableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
TestableContainer& operator=(TestableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator==(const TestableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator!=(const TestableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// type Exists(argument) specifiers; // (concrete function should not throw exceptions)
|
virtual bool Exists(const Data&) const noexcept = 0; // (concrete function should not throw exceptions)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class MappableContainer { // Must extend Container
|
class MappableContainer : virtual public Container { // Must extend Container
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~MappableContainer() specifiers
|
virtual ~MappableContainer() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
MappableContainer& operator=(const MappableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
MappableContainer& operator=(MappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator==(const MappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator!=(const MappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// typedef std::function<void(Data&, void*)> MapFunctor;
|
typedef std::function<void(Data&, void*)> MapFunctor;
|
||||||
|
|
||||||
// type MapPreOrder(arguments) specifiers;
|
virtual void MapPreOrder(const MapFunctor, void*) = 0;
|
||||||
// type MapPostOrder(arguments) specifiers;
|
virtual void MapPostOrder(const MapFunctor, void*) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class FoldableContainer { // Must extend TestableContainer
|
class FoldableContainer : virtual public TestableContainer<Data>{ // Must extend TestableContainer
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~FoldableContainer() specifiers
|
virtual ~FoldableContainer() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
FoldableContainer& operator=(const FoldableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
FoldableContainer& operator=(FoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator==(FoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator!=(FoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// typedef std::function<void(const Data&, const void*, void*) noexcept> FoldFunctor;
|
typedef std::function<void(const Data&, const void*, void*) noexcept> FoldFunctor;
|
||||||
|
|
||||||
// type FoldPreOrder(arguments) specifiers;
|
virtual void FoldPreOrder(const FoldFunctor, const void*, void*) const = 0;
|
||||||
// type FoldPostOrder(arguments) specifiers;
|
virtual void FoldPostOrder(const FoldFunctor, const void*, void*) const = 0;
|
||||||
|
|
||||||
// type Exists(argument) specifiers; // Override TestableContainer member
|
virtual bool Exists(const Data&) const noexcept override; // Override TestableContainer member
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue