diff --git a/d01/ex04/Makefile.replace b/d01/ex04/Makefile.replace new file mode 100644 index 0000000..495c03c --- /dev/null +++ b/d01/ex04/Makefile.replace @@ -0,0 +1,62 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value . name is case sensitive # +# VARIABLES . or name = value \ . use VPATH only for .c # +# . value . or .cpp # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = sed + +CC = clang++ +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 -g3 + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp \ + Sed.cpp + +D_HEADERS = . +HEADERS = Sed.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) + +RM_D_OBJS = rm -rf $(D_OBJS) +ifeq "$(D_OBJS)" "." +RM_D_OBJS = +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.cpp | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + $(RM_D_OBJS) + +re: fclean all + +.PHONY : all clean fclean re bonus run valgrind diff --git a/d01/ex04/Sed.cpp b/d01/ex04/Sed.cpp index 74cc9f4..b5556e6 100644 --- a/d01/ex04/Sed.cpp +++ b/d01/ex04/Sed.cpp @@ -37,8 +37,8 @@ void Sed::replace() { str.erase(str.begin()); str.push_back(file.get()); } - for (int i = 0; str[i + 1]; i++) - new_file << str[i]; + str.erase(str.end() - 1); + new_file << str; } diff --git a/d01/ex04/sed b/d01/ex04/sed new file mode 100755 index 0000000..973c59b Binary files /dev/null and b/d01/ex04/sed differ diff --git a/d01/ex04/test.txt.replace b/d01/ex04/test.txt.replace new file mode 100644 index 0000000..e69de29 diff --git a/d01/ex04/unitests/test_log/test1 b/d01/ex04/unitests/test_log/test1 new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/d01/ex04/unitests/test_log/test1 @@ -0,0 +1 @@ + diff --git a/d01/ex04/unitests/test_log/test1.replace b/d01/ex04/unitests/test_log/test1.replace new file mode 100644 index 0000000..b6fc4c6 --- /dev/null +++ b/d01/ex04/unitests/test_log/test1.replace @@ -0,0 +1 @@ +hello \ No newline at end of file diff --git a/d01/ex04/unitests/test_log/test2 b/d01/ex04/unitests/test_log/test2 new file mode 100644 index 0000000..23b0c96 --- /dev/null +++ b/d01/ex04/unitests/test_log/test2 @@ -0,0 +1,5 @@ +ce fichier +contient +plusieurs lignes +les unes au dessus des autres +youhouuu ioieux diff --git a/d01/ex04/unitests/test_log/test2.replace b/d01/ex04/unitests/test_log/test2.replace new file mode 100644 index 0000000..a573c23 --- /dev/null +++ b/d01/ex04/unitests/test_log/test2.replace @@ -0,0 +1,5 @@ +ce fich++r +cont++nt +plus++urs lignes +les unes au dessus des autres +youhouuu io++ux diff --git a/d01/ex04/unitests/test_log/test3 b/d01/ex04/unitests/test_log/test3 new file mode 100644 index 0000000..922f88c --- /dev/null +++ b/d01/ex04/unitests/test_log/test3 @@ -0,0 +1 @@ +....................................................; diff --git a/d01/ex04/unitests/test_log/test3.replace b/d01/ex04/unitests/test_log/test3.replace new file mode 100644 index 0000000..d3b95af --- /dev/null +++ b/d01/ex04/unitests/test_log/test3.replace @@ -0,0 +1 @@ +++++++++++++++++++++++++++++++++++++++++++++++++++++; diff --git a/d01/ex04/unitests/test_log/test4 b/d01/ex04/unitests/test_log/test4 new file mode 100644 index 0000000..0880dee --- /dev/null +++ b/d01/ex04/unitests/test_log/test4 @@ -0,0 +1,2 @@ +...................................................; +. . . . . . . . . . . . . . . . . . . . . . . . . .; diff --git a/d01/ex04/unitests/test_log/test4.replace b/d01/ex04/unitests/test_log/test4.replace new file mode 100644 index 0000000..80f497e --- /dev/null +++ b/d01/ex04/unitests/test_log/test4.replace @@ -0,0 +1,2 @@ +++++++++++++++++++++++++++++++++++++++++++++++++++.; +. . . . . . . . . . . . . . . . . . . . . . . . . .; diff --git a/d01/ex04/unitests/test_log/test5 b/d01/ex04/unitests/test_log/test5 new file mode 100644 index 0000000..671f5ed --- /dev/null +++ b/d01/ex04/unitests/test_log/test5 @@ -0,0 +1 @@ +test de mmdr foubar diff --git a/d01/ex04/unitests/test_log/test5.replace b/d01/ex04/unitests/test_log/test5.replace new file mode 100644 index 0000000..991bdd3 --- /dev/null +++ b/d01/ex04/unitests/test_log/test5.replace @@ -0,0 +1 @@ +test de m||| foubar diff --git a/d01/ex04/unitests/test_log/test6 b/d01/ex04/unitests/test_log/test6 new file mode 100644 index 0000000..a74f1c0 --- /dev/null +++ b/d01/ex04/unitests/test_log/test6 @@ -0,0 +1,2 @@ +trouve ce mot toutouille +et celui-la toutoutouille diff --git a/d01/ex04/unitests/test_log/test6.replace b/d01/ex04/unitests/test_log/test6.replace new file mode 100644 index 0000000..8072725 --- /dev/null +++ b/d01/ex04/unitests/test_log/test6.replace @@ -0,0 +1,2 @@ +trouve ce mot |||||||||| +et celui-la tou|||||||||| \ No newline at end of file diff --git a/d01/ex04/unitests/test_log/test7 b/d01/ex04/unitests/test_log/test7 new file mode 100644 index 0000000..05ee8e4 --- /dev/null +++ b/d01/ex04/unitests/test_log/test7 @@ -0,0 +1,27 @@ +No more tears, my heart is dry +I don't laugh and I don't cry +I don't think about you all the time +But when I do - I wonder why + +You have to go out of my door +And leave just like you did before +I know I said that I was sure +But rich men can't imagine poor. + +One day baby, we'll be old +Oh baby, we'll be old +And think of all the stories that we could have told + +Little me and little you +Kept doing all the things they do +They never really think it through +Like I can never think you're true + +Here I go again - the blame +The guilt, the pain, the hurt, the shame +The founding fathers of our plane +That's stuck in heavy clouds of rain. + +One day baby, we'll be old +Oh baby, we'll be old +And think of all the stories that we could have told diff --git a/d01/ex04/unitests/test_log/test7.replace b/d01/ex04/unitests/test_log/test7.replace new file mode 100644 index 0000000..7292451 --- /dev/null +++ b/d01/ex04/unitests/test_log/test7.replace @@ -0,0 +1,27 @@ +No more tears, my heart is dry +I do000 laugh and I do000 cry +I do000 think about you all the time +But when I do - I wonder why + +You have to go out of my door +And leave just like you did before +I know I said that I was sure +But rich men ca000 imagine poor. + +One day baby, we'll be old +Oh baby, we'll be old +And think of all the stories that we could have told + +Little me and little you +Kept doing all the things they do +They never really think it through +Like I can never think you're true + +Here I go again - the blame +The guilt, the pain, the hurt, the shame +The founding fathers of our plane +That's stuck in heavy clouds of rain. + +One day baby, we'll be old +Oh baby, we'll be old +And think of all the stories that we could have told diff --git a/d01/ex04/unitests/test_log/test8 b/d01/ex04/unitests/test_log/test8 new file mode 100644 index 0000000..652b428 --- /dev/null +++ b/d01/ex04/unitests/test_log/test8 @@ -0,0 +1,4 @@ +No more tears, my heart is dry +I don't laugh and I don't cry +I don't think about you all the time +But when I do - I wonder why diff --git a/d01/ex04/unitests/test_log/test8.replace b/d01/ex04/unitests/test_log/test8.replace new file mode 100644 index 0000000..3a2e850 --- /dev/null +++ b/d01/ex04/unitests/test_log/test8.replace @@ -0,0 +1,4 @@ +No more tears, my heart is doo +oooooooolaugh and I don't coo +oooooooothink about you all the time +But when I do - I wonder why diff --git a/d01/ex05/Karen.cpp b/d01/ex05/Karen.cpp index 2aeec72..e6c74fe 100644 --- a/d01/ex05/Karen.cpp +++ b/d01/ex05/Karen.cpp @@ -1,13 +1,9 @@ #include "Karen.hpp" +void (Karen::*Karen::_fp[4])() = { &Karen::_debug, &Karen::_info, &Karen::_warning, &Karen::_error}; Karen::Karen() { - _fp[0] = &Karen::_debug; - _fp[1] = &Karen::_info; - _fp[2] = &Karen::_warning; - _fp[3] = &Karen::_error; - _level[0] = "DEBUG"; _level[1] = "INFO"; _level[2] = "WARNING"; diff --git a/d01/ex05/Karen.hpp b/d01/ex05/Karen.hpp index 7385055..53e2976 100644 --- a/d01/ex05/Karen.hpp +++ b/d01/ex05/Karen.hpp @@ -14,7 +14,7 @@ public: private: - void (Karen::*_fp[4])(); + static void (Karen::*_fp[4])(); std::string _level[4]; void _debug( void ); diff --git a/d01/ex05/karen b/d01/ex05/karen index e04dacb..04b0e44 100755 Binary files a/d01/ex05/karen and b/d01/ex05/karen differ diff --git a/d02/ex00/Fixed.hpp b/d02/ex00/Fixed.hpp index 33321a0..cc08f04 100644 --- a/d02/ex00/Fixed.hpp +++ b/d02/ex00/Fixed.hpp @@ -80,6 +80,30 @@ private: // // // +// /// NEGATIVS INTEGERS /////////////////////////////////////// +// +// 5 0101 0 0000 0 0000 0000 0000 0000 0000 0000 0000 0000 +// 1010 + 1 1 0001 1 0000 0000 0000 0000 0000 0000 0000 0001 +// -5 1011 2 0010 2 0000 0000 0000 0000 0000 0000 0000 0010 +// 3 0011 3 0000 0000 0000 0000 0000 0000 0000 0011 +// 4 0100 4 0000 0000 0000 0000 0000 0000 0000 0100 +// -> 5 0101 5 0000 0000 0000 0000 0000 0000 0000 0101 +// 6 0110 6 0000 0000 0000 0000 0000 0000 0000 0110 +// 7 0111 7 0000 0000 0000 0000 0000 0000 0000 0111 +// ... +// 0111 1111 1111 1111 1111 1111 1111 1111 MAXINT +// 1000 0000 0000 0000 0000 0000 0000 0000 MININT +// ... +// 8 1000 -8 1111 1111 1111 1111 1111 1111 1111 1000 +// 9 1001 -7 1111 1111 1111 1111 1111 1111 1111 1001 +// 10 1010 -6 1111 1111 1111 1111 1111 1111 1111 1010 +// -> 11 1011 -5 1111 1111 1111 1111 1111 1111 1111 1011 +// 12 1100 -4 1111 1111 1111 1111 1111 1111 1111 1100 +// 13 1101 -3 1111 1111 1111 1111 1111 1111 1111 1101 +// 14 1110 -2 1111 1111 1111 1111 1111 1111 1111 1110 +// 15 1111 -1 1111 1111 1111 1111 1111 1111 1111 1111 +// +// // /// FLOATS VS FIXED ///////////////////////////////////////// // // 1.....................23 diff --git a/d02/ex01/Fixed.cpp b/d02/ex01/Fixed.cpp new file mode 100644 index 0000000..82b8f4b --- /dev/null +++ b/d02/ex01/Fixed.cpp @@ -0,0 +1,66 @@ +#include "Fixed.hpp" + +void printBits(std::string before, unsigned int num) +{ + int i = 0; + + std::cout << before; + for (unsigned int mask = 1U << 31; mask; mask = mask >> 1) + { + std::cout << ((num & mask) != 0); + i++; + if (i % 8 == 0) + std::cout << ' '; + } + std::cout << "(" << num << ")" << '\n'; +} + +// default/parametric constructor +Fixed::Fixed( void ) : _value( 0 ) { + std::cout << "Default constructor called" << '\n'; + return; +} + +// copy constructor +Fixed::Fixed( Fixed const & src ) { + std::cout << "Copy constructor called" << '\n'; + *this = src; + return; +} + +// destructor +Fixed::~Fixed( void ) { + std::cout << "Destructor called" << '\n'; + return; +} + +Fixed::Fixed( int integer ) { + + std::cout << integer << '\n'; + printBits("integer : ", integer); + this->_value = integer << this->_frac; + printBits("this->_value : ", this->_value); + +} + +// assignement operator +Fixed & Fixed::operator=( Fixed const & rhs ) { + + std::cout << "Copy assignment operator called" << '\n'; + if ( this != &rhs ) + this->_value = rhs.getRawBits(); + + return *this; + +} + +int Fixed::getRawBits( void ) const { + std::cout << "getRawBits member function called" << '\n'; + + return this->_value; +} + +void Fixed::setRawBits( int const raw ) { + this->_value = raw; +} + diff --git a/d02/ex01/Fixed.hpp b/d02/ex01/Fixed.hpp new file mode 100644 index 0000000..5224527 --- /dev/null +++ b/d02/ex01/Fixed.hpp @@ -0,0 +1,29 @@ +#ifndef FIXED_HPP +# define FIXED_HPP + +#include +#include + +class Fixed { + +public: + + Fixed( void ); // default/parametric constructor + Fixed( Fixed const & src ); // copy constructor + ~Fixed( void ); // destructor + Fixed( int integer); + Fixed( float const floater ); + + Fixed & operator=( Fixed const & rhs ); // assignement operator + + int getRawBits( void ) const; + void setRawBits( int const raw ); + +private: + + int _value; + static int const _frac = 8; + +}; + +#endif diff --git a/d02/ex01/Makefile b/d02/ex01/Makefile new file mode 100644 index 0000000..0712445 --- /dev/null +++ b/d02/ex01/Makefile @@ -0,0 +1,62 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value . name is case sensitive # +# VARIABLES . or name = value \ . use VPATH only for .c # +# . value . or .cpp # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = fixed + +CC = clang++ +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp \ + Fixed.cpp + +D_HEADERS = . +HEADERS = Fixed.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) + +RM_D_OBJS = rm -rf $(D_OBJS) +ifeq "$(D_OBJS)" "." +RM_D_OBJS = +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.cpp | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + $(RM_D_OBJS) + +re: fclean all + +.PHONY : all clean fclean re bonus run valgrind diff --git a/d02/ex01/fixed b/d02/ex01/fixed new file mode 100755 index 0000000..7caafdb Binary files /dev/null and b/d02/ex01/fixed differ diff --git a/d02/ex01/main.cpp b/d02/ex01/main.cpp new file mode 100644 index 0000000..a191bfe --- /dev/null +++ b/d02/ex01/main.cpp @@ -0,0 +1,36 @@ +#include "Fixed.hpp" +#include + +int main( void ) { + + Fixed a( 1 ); + std::cout << a.getRawBits() << '\n'; + + Fixed b( 6 ); + std::cout << b.getRawBits() << '\n'; + + Fixed c( -6 ); + std::cout << c.getRawBits() << '\n'; + + Fixed d( -1 ); + std::cout << d.getRawBits() << '\n'; + +// Fixed a; +// Fixed const b( 10 ); +// Fixed const c( 42.42f ); +// Fixed const d( b ); +// +// a = Fixed( 1234.4321f ); +// +// std::cout << "a is " << a << std::endl; +// std::cout << "b is " << b << std::endl; +// std::cout << "c is " << c << std::endl; +// std::cout << "d is " << d << std::endl; +// +// std::cout << "a is " << a.toInt() << " as integer" << std::endl; +// std::cout << "b is " << b.toInt() << " as integer" << std::endl; +// std::cout << "c is " << c.toInt() << " as integer" << std::endl; +// std::cout << "d is " << d.toInt() << " as integer" << std::endl; + + return 0; +}