From 1e9d90bdf9ef5fc05093d3449d883597c7f896de Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 8 Nov 2020 13:39:12 +0100 Subject: Added cpp06 boilerplate --- cpp06/ex00/DynamicConverter.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ cpp06/ex00/DynamicConverter.hpp | 44 +++++++++++++++++++++++++++++++++++ cpp06/ex00/Makefile | 35 ++++++++++++++++++++++++++++ cpp06/ex00/detect.cpp | 13 +++++++++++ cpp06/ex00/main.cpp | 32 ++++++++++++++++++++++++++ cpp06/ex00/optional.hpp | 28 ++++++++++++++++++++++ 6 files changed, 203 insertions(+) create mode 100644 cpp06/ex00/DynamicConverter.cpp create mode 100644 cpp06/ex00/DynamicConverter.hpp create mode 100644 cpp06/ex00/Makefile create mode 100644 cpp06/ex00/detect.cpp create mode 100644 cpp06/ex00/main.cpp create mode 100644 cpp06/ex00/optional.hpp (limited to 'cpp06/ex00') diff --git a/cpp06/ex00/DynamicConverter.cpp b/cpp06/ex00/DynamicConverter.cpp new file mode 100644 index 0000000..c22d469 --- /dev/null +++ b/cpp06/ex00/DynamicConverter.cpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* DynamicConverter.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/16 11:48:33 by charles #+# #+# */ +/* Updated: 2020/04/16 12:25:58 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "DynamicConverter.hpp" + +DynamicConverter(DynamicConverter const& other) +{ + *this = other; +} + +DynamicConverter& operator=(DynamicConverter const& other) +{ + if (*this == other) + return *this; + m_origin = other.m_origin; + m_type = other.m_type; + m_int = other.m_int; + m_char = other.m_char; + m_float = other.m_float; + m_double = other.m_double; + return *this; +} + +~DynamicConverter() +{} + +DynamicConverter(std::string const& origin) + : m_origin(origin) +{ + if (isCharLitteral(origin)) + m_type = DetectedTypeChar; + else if (isIntLitteral(origin)) + else if (isFloatLitteral(origin)) + else if (isDoubleLitteral(origin)) + + +} + +bool isCharLitteral(std::string const& s) +{ + if (!origin.length() == 3 && origin[0] == '\'' && origin[2] == '\''); +} diff --git a/cpp06/ex00/DynamicConverter.hpp b/cpp06/ex00/DynamicConverter.hpp new file mode 100644 index 0000000..3f400a2 --- /dev/null +++ b/cpp06/ex00/DynamicConverter.hpp @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* DynamicConverter.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/16 11:35:47 by charles #+# #+# */ +/* Updated: 2020/04/16 11:56:10 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INCLUDE_HPP +# define INCLUDE_HPP + +class DynamicConverter +{ +public: + DynamicConverter(DynamicConverter const& other); + DynamicConverter& operator=(DynamicConverter const& other); + ~DynamicConverter(); + + DynamicConverter(std::string const& origin); + + enum DetectedType + { + DetectedTypeInt, + DetectedTypeChar, + DetectedTypeFloat, + DetectedTypeDouble, + }; + +private: + DynamicConverter(); + + std::string m_origin; + DetectedType m_type; + Optional m_int; + Optional m_char; + Optional m_float; + Optional m_double; +}; + +#endif diff --git a/cpp06/ex00/Makefile b/cpp06/ex00/Makefile new file mode 100644 index 0000000..a5cff07 --- /dev/null +++ b/cpp06/ex00/Makefile @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: charles +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/04/15 09:59:30 by charles #+# #+# # +# Updated: 2020/04/16 10:53:22 by charles ### ########.fr # +# # +# **************************************************************************** # + +NAME = scalar_conversion + +CXX = clang++ +CXXFLAGS = -std=c++98 -Wall -Wextra -Werror + +SRC = main.cpp +OBJ = $(SRC:.cpp=.o) + +all: $(NAME) + +$(NAME): $(OBJ) + $(CXX) -o $@ $< + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $^ + +clean: + rm -rf $(OBJ) + +fclean: clean + rm -rf $(NAME) + +re: fclean all diff --git a/cpp06/ex00/detect.cpp b/cpp06/ex00/detect.cpp new file mode 100644 index 0000000..5dab8fb --- /dev/null +++ b/cpp06/ex00/detect.cpp @@ -0,0 +1,13 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* detect.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/16 11:32:53 by charles #+# #+# */ +/* Updated: 2020/04/16 11:45:28 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + + diff --git a/cpp06/ex00/main.cpp b/cpp06/ex00/main.cpp new file mode 100644 index 0000000..35d64b9 --- /dev/null +++ b/cpp06/ex00/main.cpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/16 10:54:10 by charles #+# #+# */ +/* Updated: 2020/04/16 12:23:06 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int main(int argc, char **argv) +{ + // if (argc != 2) + // { + // std::cout << "Usage: " << argv[0] << " litteral" << std::endl; + // return 1; + // } + + int i; + + std::istringstream("bonjour") >> i; + + + std::cout << i << std::endl; + + return 0; +} diff --git a/cpp06/ex00/optional.hpp b/cpp06/ex00/optional.hpp new file mode 100644 index 0000000..2c77ae3 --- /dev/null +++ b/cpp06/ex00/optional.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* optional.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/16 11:43:24 by charles #+# #+# */ +/* Updated: 2020/04/16 11:45:26 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef OPTIONAL_HPP +# define OPTIONAL_HPP + +template +class Optional +{ +public: + Optional(); + bool hasValue() const; + T& getValue(); + +private: + T m_value; +}; + +#endif -- cgit