From 5f0dfe405ef5eedb3c8c249d54dcf3f1443303bc Mon Sep 17 00:00:00 2001 From: kinou-p Date: Wed, 19 Oct 2022 17:31:20 +0200 Subject: [PATCH] first push stack maybe down --- Makefile | 39 +++++++++++++ containers/map.hpp | 16 ++++++ containers/set.hpp | 16 ++++++ containers/stack.hpp | 81 ++++++++++++++++++++++++++ containers/vector.hpp | 51 +++++++++++++++++ ft_containers.hpp | 25 +++++++++ main.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++ tests/main.cpp | 41 ++++++++++++++ tests/stack_test.cpp | 17 ++++++ 9 files changed, 414 insertions(+) create mode 100644 Makefile create mode 100644 containers/map.hpp create mode 100644 containers/set.hpp create mode 100644 containers/stack.hpp create mode 100644 containers/vector.hpp create mode 100644 ft_containers.hpp create mode 100644 main.cpp create mode 100644 tests/main.cpp create mode 100644 tests/stack_test.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..138933a --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/10/12 19:45:18 by apommier #+# #+# # +# Updated: 2022/10/19 14:25:28 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = a.out +SRCS = tests/stack_test.cpp\ + tests/main.cpp + + +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -g -Wall -Wextra -Werror -std=c++98 +RM = rm -rf + +.cpp.o: + $(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o) + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/containers/map.hpp b/containers/map.hpp new file mode 100644 index 0000000..02f7f41 --- /dev/null +++ b/containers/map.hpp @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/12 19:46:25 by apommier #+# #+# */ +/* Updated: 2022/10/18 10:17:57 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAP_HPP +# define MAP_HPP + +#endif \ No newline at end of file diff --git a/containers/set.hpp b/containers/set.hpp new file mode 100644 index 0000000..c263123 --- /dev/null +++ b/containers/set.hpp @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/12 19:46:29 by apommier #+# #+# */ +/* Updated: 2022/10/18 10:18:12 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SET_HPP +# define SET_HPP + +#endif \ No newline at end of file diff --git a/containers/stack.hpp b/containers/stack.hpp new file mode 100644 index 0000000..23cdb6f --- /dev/null +++ b/containers/stack.hpp @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/12 19:46:30 by apommier #+# #+# */ +/* Updated: 2022/10/19 17:22:33 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STACK_HPP +# define STACK_HPP + +# include + +namespace ft +{ + +template > +class stack +{ + public: + + //---------MEMBER TYPE--------- + typedef std::size_t size_type; + typedef T value_type; + typedef Container container_type; + + private: + container_type c; + + public: + //---------COPLIEN FORM FUNCTION--------- + explicit stack (const container_type& ctnr = container_type()) : c(ctnr){}//default constructor + stack(const stack &other )//copy constructor + { + *this = other; + } + ~stack(void) {}//destructor + stack &operator=( const stack &other )//assigment operator + { + if (this != &other) + this->c = other.c; + return *this; + } + //---------MEMBER FUNCTION---------- + bool empty() const + { + return (c.empty()); + } + + size_type size() const + { + return (c.size()); + } + + value_type& top() + { + return (c.back()); + } + + const value_type& top() const + { + return (c.back()); + } + + void push (const value_type& val) + { + return (c.push_back()); + } + + void pop() + { + return (c.pop_back()); + } +}; + +} +#endif \ No newline at end of file diff --git a/containers/vector.hpp b/containers/vector.hpp new file mode 100644 index 0000000..71c7bd6 --- /dev/null +++ b/containers/vector.hpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* vector.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/12 19:46:32 by apommier #+# #+# */ +/* Updated: 2022/10/19 17:30:38 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef VECTOR_HPP +# define VECTOR_HPP + +namespace ft +{ + +template< class T, class Allocator = std::allocator > class vector; +class vector +{ + public: + + //---------MEMBER TYPE--------- + typedef value_type; + typedef allocator_type; + typedef reference; + typedef const_reference; + typedef pointer; + typedef const_pointer; + typedef iterator; + typedef const_iterator; + typedef reverse_iterator; + typedef const_reverse_iterator; + typedef difference_type; + typedef size_type; + + //---------COPLIEN FORM FUNCTION--------- + explicit vector (const allocator_type& alloc = allocator_type());//default constructor + explicit vector (size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type());//fill constructor + template + vector (InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());//range constructor + vector (const vector& x);//copy constructor + ~vector(); + vector& operator= (const vector& x);//assignation operator + //---------MEMBER FUNCTION---------- + private: +}; + +} +#endif \ No newline at end of file diff --git a/ft_containers.hpp b/ft_containers.hpp new file mode 100644 index 0000000..d9b08c7 --- /dev/null +++ b/ft_containers.hpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_containers.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/12 19:46:33 by apommier #+# #+# */ +/* Updated: 2022/10/19 17:22:39 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_CONTAINERS_HPP +# define FT_CONTAINERS_HPP + +# include + +//namespace ft { +# include "./containers/map.hpp" +# include "./containers/set.hpp" +# include "./containers/stack.hpp" +# include "./containers/vector.hpp" +//} + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..220c78c --- /dev/null +++ b/main.cpp @@ -0,0 +1,128 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/12 19:46:35 by apommier #+# #+# */ +/* Updated: 2022/10/12 19:46:56 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#if 1 //CREATE A REAL STL EXAMPLE + #include + #include + #include + namespace ft = std; +#else + #include + #include + #include +#endif + +#include + +#define MAX_RAM 4294967296 +#define BUFFER_SIZE 4096 +struct Buffer +{ + int idx; + char buff[BUFFER_SIZE]; +}; + + +#define COUNT (MAX_RAM / (int)sizeof(Buffer)) + +template +class MutantStack : public ft::stack +{ +public: + MutantStack() {} + MutantStack(const MutantStack& src) { *this = src; } + MutantStack& operator=(const MutantStack& rhs) + { + this->c = rhs.c; + return *this; + } + ~MutantStack() {} + + typedef typename ft::stack::container_type::iterator iterator; + + iterator begin() { return this->c.begin(); } + iterator end() { return this->c.end(); } +}; + +int main(int argc, char** argv) { + if (argc != 2) + { + std::cerr << "Usage: ./test seed" << std::endl; + std::cerr << "Provide a seed please" << std::endl; + std::cerr << "Count value:" << COUNT << std::endl; + return 1; + } + const int seed = atoi(argv[1]); + srand(seed); + + ft::vector vector_str; + ft::vector vector_int; + ft::stack stack_int; + ft::vector vector_buffer; + ft::stack > stack_deq_buffer; + ft::map map_int; + + for (int i = 0; i < COUNT; i++) + { + vector_buffer.push_back(Buffer()); + } + + for (int i = 0; i < COUNT; i++) + { + const int idx = rand() % COUNT; + vector_buffer[idx].idx = 5; + } + ft::vector().swap(vector_buffer); + + try + { + for (int i = 0; i < COUNT; i++) + { + const int idx = rand() % COUNT; + vector_buffer.at(idx); + std::cerr << "Error: THIS VECTOR SHOULD BE EMPTY!!" < copy = map_int; + } + MutantStack iterable_stack; + for (char letter = 'a'; letter <= 'z'; letter++) + iterable_stack.push(letter); + for (MutantStack::iterator it = iterable_stack.begin(); it != iterable_stack.end(); it++) + { + std::cout << *it; + } + std::cout << std::endl; + return (0); +} \ No newline at end of file diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..67131db --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/19 14:04:37 by apommier #+# #+# */ +/* Updated: 2022/10/19 14:38:42 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../ft_containers.hpp" + +void stack_tester() +{ + ft::stack first; + std::cout << "------empty------\n"; + std::cout << first.empty() << std::endl; + std::cout << "------size------\n"; + std::cout << first.size() << std::endl; +} + +void vector_tester() +{ +} + +int main() +{ + std::cout << "------TESTER START-------\n"; + std::cout << "------STACK-------\n"; + stack_tester(); + std::cout << "------VECTOR-------\n"; + vector_tester(); + // std::cout << "------MAP-------\n"; + // map_tester(); + // std::cout << "------SET-------\n"; + // set_tester(); + std::cout << "------End-------\n"; + return (0); +} \ No newline at end of file diff --git a/tests/stack_test.cpp b/tests/stack_test.cpp new file mode 100644 index 0000000..dcadbef --- /dev/null +++ b/tests/stack_test.cpp @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack_test.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/19 14:04:13 by apommier #+# #+# */ +/* Updated: 2022/10/19 14:29:06 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +// void tester() +// { +// //ft::stack first() +// return; +// } \ No newline at end of file