diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..6a4b384 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,26 @@ +CXX := c++ +CXXFLAGS := -std=c++98 -Wall -Wextra -Werror -g +SRCDIR := src +OBJDIR := obj +NAME := ex01 + +SRCS := $(wildcard $(SRCDIR)/*.cpp) +OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) + +all: $(NAME) + +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp + mkdir -p $(OBJDIR) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(NAME): $(OBJS) + $(CXX) $(CXXFLAGS) $^ -o $@ + +clean: + rm -rf $(OBJDIR) + +fclean: clean + rm -fr $(NAME) + +re: fclean + @make --no-print-directory all diff --git a/ex01/src/Data.hpp b/ex01/src/Data.hpp new file mode 100644 index 0000000..d417a4d --- /dev/null +++ b/ex01/src/Data.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +typedef struct s_data +{ + std::string name; + int id; +} Data; diff --git a/ex01/src/Serializer.cpp b/ex01/src/Serializer.cpp new file mode 100644 index 0000000..af5a0fb --- /dev/null +++ b/ex01/src/Serializer.cpp @@ -0,0 +1,29 @@ +#include "Serializer.hpp" +#include "Data.hpp" + +Serializer::Serializer() +{} + +Serializer::~Serializer() +{} + +Serializer::Serializer(const Serializer& src) +{ + (void)src; +} + +Serializer& Serializer::operator=(const Serializer& src) +{ + (void)src; + return *this; +} + +uintptr_t Serializer::serialize(Data* ptr) +{ + return reinterpret_cast(ptr); +} + +Data* Serializer::deserialize(uintptr_t raw) +{ + return reinterpret_cast(raw); +} diff --git a/ex01/src/Serializer.hpp b/ex01/src/Serializer.hpp new file mode 100644 index 0000000..1581fe1 --- /dev/null +++ b/ex01/src/Serializer.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "Data.hpp" + +class Serializer +{ + private: + Serializer(); + ~Serializer(); + Serializer(const Serializer& src); + + Serializer& operator=(const Serializer& src); + + public: + static uintptr_t serialize(Data* ptr); + static Data* deserialize(uintptr_t raw); +}; diff --git a/ex01/src/main.cpp b/ex01/src/main.cpp new file mode 100644 index 0000000..4bbff36 --- /dev/null +++ b/ex01/src/main.cpp @@ -0,0 +1,13 @@ +#include "Data.hpp" +#include "Serializer.hpp" +#include + +int main() +{ + Data data = {"bozo", 10}; + uintptr_t tmp = Serializer::serialize(&data); + + + std::cout << "serialized: " << std::hex << tmp << std::endl; + std::cout << "deserialized: " << Serializer::deserialize(tmp) << std::endl; +}