aboutsummaryrefslogtreecommitdiff
path: root/cpp06
diff options
context:
space:
mode:
Diffstat (limited to 'cpp06')
-rw-r--r--cpp06/ex00/DynamicConverter.cpp51
-rw-r--r--cpp06/ex00/DynamicConverter.hpp44
-rw-r--r--cpp06/ex00/Makefile35
-rw-r--r--cpp06/ex00/detect.cpp13
-rw-r--r--cpp06/ex00/main.cpp32
-rw-r--r--cpp06/ex00/optional.hpp28
-rw-r--r--cpp06/ex02/A.hpp22
-rw-r--r--cpp06/ex02/B.hpp22
-rw-r--r--cpp06/ex02/Base.hpp22
-rw-r--r--cpp06/ex02/C.hpp22
-rw-r--r--cpp06/ex02/Makefile35
-rw-r--r--cpp06/ex02/main.cpp36
12 files changed, 362 insertions, 0 deletions
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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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<int> m_int;
+ Optional<char> m_char;
+ Optional<float> m_float;
+ Optional<double> 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 <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# 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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/16 10:54:10 by charles #+# #+# */
+/* Updated: 2020/04/16 12:23:06 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <iostream>
+#include <sstream>
+
+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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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<typename T>
+class Optional
+{
+public:
+ Optional();
+ bool hasValue() const;
+ T& getValue();
+
+private:
+ T m_value;
+};
+
+#endif
diff --git a/cpp06/ex02/A.hpp b/cpp06/ex02/A.hpp
new file mode 100644
index 0000000..30c68d5
--- /dev/null
+++ b/cpp06/ex02/A.hpp
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* A.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 09:56:52 by charles #+# #+# */
+/* Updated: 2020/04/15 10:03:37 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef A_HPP
+# define A_HPP
+
+# include "Base.hpp"
+
+class A : public Base
+{
+};
+
+#endif
diff --git a/cpp06/ex02/B.hpp b/cpp06/ex02/B.hpp
new file mode 100644
index 0000000..aeac82e
--- /dev/null
+++ b/cpp06/ex02/B.hpp
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* B.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 09:57:12 by charles #+# #+# */
+/* Updated: 2020/04/15 10:07:52 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef B_HPP
+# define B_HPP
+
+# include "Base.hpp"
+
+class B : public Base
+{
+};
+
+#endif
diff --git a/cpp06/ex02/Base.hpp b/cpp06/ex02/Base.hpp
new file mode 100644
index 0000000..c70706a
--- /dev/null
+++ b/cpp06/ex02/Base.hpp
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Base.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 09:56:24 by charles #+# #+# */
+/* Updated: 2020/04/15 09:56:41 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef BASE_HPP
+# define BASE_HPP
+
+class Base
+{
+public:
+ virtual ~Base();
+};
+
+#endif
diff --git a/cpp06/ex02/C.hpp b/cpp06/ex02/C.hpp
new file mode 100644
index 0000000..537c0c5
--- /dev/null
+++ b/cpp06/ex02/C.hpp
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* C.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 09:57:24 by charles #+# #+# */
+/* Updated: 2020/04/15 10:03:30 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef C_HPP
+# define C_HPP
+
+# include "Base.hpp"
+
+class C : public Base
+{
+};
+
+#endif
diff --git a/cpp06/ex02/Makefile b/cpp06/ex02/Makefile
new file mode 100644
index 0000000..b68a586
--- /dev/null
+++ b/cpp06/ex02/Makefile
@@ -0,0 +1,35 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/04/15 09:59:30 by charles #+# #+# #
+# Updated: 2020/04/15 10:00:05 by charles ### ########.fr #
+# #
+# **************************************************************************** #
+
+NAME = identify_real_type
+
+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/ex02/main.cpp b/cpp06/ex02/main.cpp
new file mode 100644
index 0000000..17c0c3d
--- /dev/null
+++ b/cpp06/ex02/main.cpp
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 10:00:18 by charles #+# #+# */
+/* Updated: 2020/04/15 10:05:23 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <iostream>
+#include <cstdlib>
+#include "Base.hpp"
+#include "A.hpp"
+#include "B.hpp"
+#include "C.hpp"
+
+Base* generate(void)
+{
+ switch (rand() % 3)
+ {
+ case 0: return new A();
+ case 1: return new B();
+ case 2: return new C();
+ }
+ return NULL;
+}
+
+int main()
+{
+ srand(time(NULL));
+
+ return 0;
+}