diff --git a/d04/ex02/Makefile b/d04/ex02/Makefile index 2265727..fc4b7c2 100644 --- a/d04/ex02/Makefile +++ b/d04/ex02/Makefile @@ -9,6 +9,10 @@ NAME = pure #TYPE = c TYPE = cpp +ifndef TYPE +echo hello +endif + ifeq "$(TYPE)" "c" CC = c EXT = c diff --git a/d04/ex02/pure b/d04/ex02/pure new file mode 100755 index 0000000..fe31b46 Binary files /dev/null and b/d04/ex02/pure differ diff --git a/d04/ex03/Makefile b/d04/ex03/Makefile new file mode 100644 index 0000000..710467d --- /dev/null +++ b/d04/ex03/Makefile @@ -0,0 +1,82 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value \ . += append to a variable # +# VARIABLES . value . != set result of command # +# . name is case sensitive . ?= set if not already set # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = materia + +#TYPE = c +TYPE = cpp + +ifeq "$(TYPE)" "c" + CC = c + EXT = c +else ifeq "$(TYPE)" "cpp" + CC = c++ + EXT = cpp +endif + +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) +ifeq "$(TYPE)" "cpp" + CFLAGS += -std=c++98 +endif + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = srcs +SRCS = main.cpp \ + Animal.cpp \ + Dog.cpp \ + Cat.cpp \ + Brain.cpp + +D_HEADERS = headers +HEADERS = Animal.hpp \ + Dog.hpp \ + Cat.hpp \ + Brain.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) + +ifeq "$(D_OBJS)" "." + RM_OBJS = rm -f $(OBJS) +else + RM_OBJS = rm -rf $(D_OBJS) +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + $(RM_OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY : all clean fclean re + diff --git a/d04/ex03/headers/AMateria.hpp b/d04/ex03/headers/AMateria.hpp new file mode 100644 index 0000000..096f251 --- /dev/null +++ b/d04/ex03/headers/AMateria.hpp @@ -0,0 +1,24 @@ +#ifndef AMATERIA_HPP +# define AMATERIA_HPP + +# include + +#include "ICharacter.hpp" + +class AMateria { + +public: + AMateria(std::string const & type); + virtual ~AMateria(); + + std::string const & getType() const; //Returns the materia type + + virtual AMateria* clone() const = 0; + virtual void use(ICharacter& target); + +protected: + std::string _type; + +}; + +#endif diff --git a/d04/ex03/headers/Character.hpp b/d04/ex03/headers/Character.hpp new file mode 100644 index 0000000..73e2c10 --- /dev/null +++ b/d04/ex03/headers/Character.hpp @@ -0,0 +1,18 @@ +#ifndef CHARACTER_HPP +# define CHARACTER_HPP + +#include "ICharacter.hpp" + +class Character : public ICharacter { + +public: + Character(); + Character( Character const & src ); + ~Character(); + Character & operator=( Character const & rhs ); + +private: + +}; + +#endif diff --git a/d04/ex03/headers/Cure.hpp b/d04/ex03/headers/Cure.hpp new file mode 100644 index 0000000..1ca03c8 --- /dev/null +++ b/d04/ex03/headers/Cure.hpp @@ -0,0 +1,19 @@ +#ifndef CURE_HPP +# define CURE_HPP + +#include "AMateria.hpp" + +class Cure : public AMateria { + +public: + Cure(); + Cure( Cure const & src ); + ~Cure(); + Cure & operator=( Cure const & rhs ); + +private: + +}; + +#endif + diff --git a/d04/ex03/headers/ICharacter.hpp b/d04/ex03/headers/ICharacter.hpp new file mode 100644 index 0000000..11fa9fc --- /dev/null +++ b/d04/ex03/headers/ICharacter.hpp @@ -0,0 +1,15 @@ +#ifndef ICE_HPP +# define ICE_HPP + +class ICharacter { + +public: + virtual ~ICharacter() {} + virtual std::string const & getName() const = 0; + virtual void equip(AMateria* m) = 0; + virtual void unequip(int idx) = 0; + virtual void use(int idx, ICharacter& target) = 0; +}; + +#endif + diff --git a/d04/ex03/headers/Ice.hpp b/d04/ex03/headers/Ice.hpp new file mode 100644 index 0000000..52e3419 --- /dev/null +++ b/d04/ex03/headers/Ice.hpp @@ -0,0 +1,18 @@ +#ifndef ICE_HPP +# define ICE_HPP + +#include "AMateria.hpp" + +class Ice : public AMateria { + +public: + Ice(); + Ice( Ice const & src ); + ~Ice(); + Ice & operator=( Ice const & rhs ); + +private: + +}; + +#endif diff --git a/d04/ex03/main.cpp b/d04/ex03/main.cpp new file mode 100644 index 0000000..245e05a --- /dev/null +++ b/d04/ex03/main.cpp @@ -0,0 +1,32 @@ +#include "AMateria.hpp" +#include "Ice.hpp" +#include "Cure.hpp" +#include "ICharacter" +#include "IMateriaSource" + +int main() { + + IMateriaSource* src = new MateriaSource(); + src->learnMateria(new Ice()); + src->learnMateria(new Cure()); + + ICharacter* me = new Character("me"); + + AMateria* tmp; + tmp = src->createMateria("ice"); + me->equip(tmp); + tmp = src->createMateria("cure"); + me->equip(tmp); + + ICharacter* bob = new Character("bob"); + + me->use(0, *bob); + me->use(1, *bob); + + delete bob; + delete me; + delete src; + + return 0; +} + diff --git a/d04/ex03/srcs/AMateria.cpp b/d04/ex03/srcs/AMateria.cpp new file mode 100644 index 0000000..fca370d --- /dev/null +++ b/d04/ex03/srcs/AMateria.cpp @@ -0,0 +1,14 @@ +#include "AMateria.hpp" + +AMateria::AMateria(std::string const & type) { + _type = type; +} + +std::string const & AMateria::getType() const { + return _type; +} + +virtual AMateria * AMateria::clone() const { + AMateria clone = new AMateria; + return clone; +} diff --git a/d04/ex03/srcs/Cure.cpp b/d04/ex03/srcs/Cure.cpp new file mode 100644 index 0000000..d804128 --- /dev/null +++ b/d04/ex03/srcs/Cure.cpp @@ -0,0 +1,15 @@ +#include "Cure.hpp" + +Cure::Cure() : _type("cure") {} + +Cure::Cure( Cure const & src ) { + *this = src +} + +Cure & Cure::operator=( Cure const & rhs ) { + return *this; +} + +virtual void Ice::use(ICharacter & target) { + std::cout << "* heals " << target.name << "’s wounds *" +} diff --git a/d04/ex03/srcs/Ice.cpp b/d04/ex03/srcs/Ice.cpp new file mode 100644 index 0000000..06f7379 --- /dev/null +++ b/d04/ex03/srcs/Ice.cpp @@ -0,0 +1,15 @@ +#include "Ice.hpp" + +Ice::Ice() : _type("ice") {} + +Ice::Ice( Ice const & src ) { + *this = src +} + +Ice & Ice::operator=( Ice const & rhs ) { + return *this; +} + +virtual void Ice::use(ICharacter & target) { + std::cout << "* shoots an ice bolt at " << target.name << " *" +} diff --git a/d05/ex00/Bureaucrate.hpp b/d05/ex00/Bureaucrate.hpp new file mode 100644 index 0000000..46677db --- /dev/null +++ b/d05/ex00/Bureaucrate.hpp @@ -0,0 +1,14 @@ +#ifndef BUREAUCRATE_HPP +# define BUREAUCRATE_HPP + +class Bureaucrate { +public: + Bureaucrate(); + Bureaucrate(std::string name, int grade); + +private: + std::string const _name; + int _grade; +} + +#endif diff --git a/d05/ex00/Makefile b/d05/ex00/Makefile new file mode 100644 index 0000000..ee31047 --- /dev/null +++ b/d05/ex00/Makefile @@ -0,0 +1,71 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value \ . += append to a variable # +# VARIABLES . value . != set result of command # +# . name is case sensitive . ?= set if not already set # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = bureaucrate + +#CC = gcc +CXX = c++ + +#CFLAGS = -Wall -Wextra -Werror $(INCLUDES) +CXXFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 + +#EXT = c +EXT = cpp + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp \ + Bureaucrate.cpp + +D_HEADERS = . +HEADERS = Bureaucrate.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) + +ifeq "$(D_OBJS)" "." + RM_OBJS = rm -f $(OBJS) +else + RM_OBJS = rm -rf $(D_OBJS) +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) +# $(CC) $(CFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) +# $(CC) $(OBJS) -o $@ $(LIBS) + $(CXX) $(OBJS) -o $@ $(LIBS) + +clean: + $(RM_OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY : all clean fclean re + diff --git a/d05/ex00/main.cpp b/d05/ex00/main.cpp new file mode 100644 index 0000000..8f37d92 --- /dev/null +++ b/d05/ex00/main.cpp @@ -0,0 +1,10 @@ +int main() { + try + { + + } + catch (std::exception & e) + { + + } +}