aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-08 13:39:12 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-08 13:39:12 +0100
commit1e9d90bdf9ef5fc05093d3449d883597c7f896de (patch)
treecc5334baec6ec10a0d99bc925499512bc44f2cd0
parentc426fe76ec5925e8c94aae3db04e5e1f1ce1585e (diff)
downloadpiscine_cpp-1e9d90bdf9ef5fc05093d3449d883597c7f896de.tar.gz
piscine_cpp-1e9d90bdf9ef5fc05093d3449d883597c7f896de.tar.bz2
piscine_cpp-1e9d90bdf9ef5fc05093d3449d883597c7f896de.zip
Added cpp06 boilerplate
-rw-r--r--.gitignore2
-rw-r--r--cpp02/ex01/Fixed.cpp4
-rw-r--r--cpp02/ex01/Fixed.hpp6
-rw-r--r--cpp04/ex02/Squad.cpp6
-rw-r--r--cpp04/ex03/MateriaSource.cpp4
-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
17 files changed, 375 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index effcdeb..9b6809c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@ replace
a_few_functions
iter
array
+identify_real_type
+scalar_conversion
diff --git a/cpp02/ex01/Fixed.cpp b/cpp02/ex01/Fixed.cpp
index 755a6ae..a81c1cf 100644
--- a/cpp02/ex01/Fixed.cpp
+++ b/cpp02/ex01/Fixed.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 11:45:18 by charles #+# #+# */
-/* Updated: 2020/10/19 11:29:39 by cacharle ### ########.fr */
+/* Updated: 2020/11/08 13:38:40 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -64,7 +64,7 @@ float Fixed::toFloat() const
int Fixed::toInt() const
{
- return m_value >> m_fractionalBits;
+ return roundf(toFloat());
}
int Fixed::getFractionalBits()
diff --git a/cpp02/ex01/Fixed.hpp b/cpp02/ex01/Fixed.hpp
index 726b810..a262c59 100644
--- a/cpp02/ex01/Fixed.hpp
+++ b/cpp02/ex01/Fixed.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 11:40:49 by charles #+# #+# */
-/* Updated: 2020/10/19 11:29:30 by cacharle ### ########.fr */
+/* Updated: 2020/11/08 13:38:48 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,13 +30,15 @@ public:
int getRawBits() const;
void setRawBits(int const raw);
+ int getRawBits() const;
+ void setRawBits(int const raw);
float toFloat() const;
int toInt() const;
static int getFractionalBits();
private:
- int m_value;
+ int m_value;
static int const m_fractionalBits = 8;
};
diff --git a/cpp04/ex02/Squad.cpp b/cpp04/ex02/Squad.cpp
index ba825b9..11c7862 100644
--- a/cpp04/ex02/Squad.cpp
+++ b/cpp04/ex02/Squad.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 15:08:35 by charles #+# #+# */
-/* Updated: 2020/04/14 15:54:17 by charles ### ########.fr */
+/* Updated: 2020/04/15 10:06:04 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,13 +43,13 @@ int Squad::getCount() const
ISpaceMarine* Squad::getUnit(int n) const
{
if (n < 0 || n >= m_size)
- return nullptr;
+ return NULL;
return m_units[n];
}
int Squad::push(ISpaceMarine* spaceMarine)
{
- if (spaceMarine == nullptr)
+ if (spaceMarine == NULL)
return (-1);
for (int i = 0; i < m_size; i++)
if (m_units[i] == spaceMarine)
diff --git a/cpp04/ex03/MateriaSource.cpp b/cpp04/ex03/MateriaSource.cpp
index bce6e5a..f5aaf60 100644
--- a/cpp04/ex03/MateriaSource.cpp
+++ b/cpp04/ex03/MateriaSource.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 17:19:10 by charles #+# #+# */
-/* Updated: 2020/04/14 17:51:07 by charles ### ########.fr */
+/* Updated: 2020/04/15 10:05:47 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,5 +39,5 @@ void MateriaSource::learnMateria(AMateria* materia)
AMateria* MateriaSource::createMateria(std::string const& type)
{
- return nullptr;
+ return NULL;
}
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;
+}