ex00 and ex01
This commit is contained in:
53
ex01/Serializer/Serializer.cpp
Normal file
53
ex01/Serializer/Serializer.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Serializer.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/02/28 23:48:07 by aortigos #+# #+# */
|
||||
/* Updated: 2026/02/28 23:48:07 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Serializer.hpp"
|
||||
|
||||
//////////////////
|
||||
// Constructors //
|
||||
//////////////////
|
||||
|
||||
Serializer::Serializer()
|
||||
{
|
||||
// std::cout << "Serializer default constructor called" << std::endl;
|
||||
}
|
||||
|
||||
Serializer::Serializer(const Serializer &other)
|
||||
{
|
||||
*this = other;
|
||||
// std::cout << "Serializer copy constructor called" << std::endl;
|
||||
}
|
||||
|
||||
Serializer& Serializer::operator=(const Serializer &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
// Copy attributes here
|
||||
}
|
||||
// std::cout << "Serializer copy assignment operator called" << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Serializer::~Serializer()
|
||||
{
|
||||
// std::cout << "Serializer destructor called" << std::endl;
|
||||
}
|
||||
|
||||
uintptr_t Serializer::serialize(Data *ptr)
|
||||
{
|
||||
return (reinterpret_cast<uintptr_t>(ptr));
|
||||
}
|
||||
|
||||
Data *Serializer::deserialize(uintptr_t raw)
|
||||
{
|
||||
return (reinterpret_cast<Data*>(raw));
|
||||
}
|
||||
40
ex01/Serializer/Serializer.hpp
Normal file
40
ex01/Serializer/Serializer.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Serializer.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/02/28 23:48:07 by aortigos #+# #+# */
|
||||
/* Updated: 2026/02/28 23:48:07 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SERIALIZER_HPP
|
||||
|
||||
# define SERIALIZER_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <stdint.h>
|
||||
|
||||
struct Data
|
||||
{
|
||||
int age;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class Serializer
|
||||
{
|
||||
private:
|
||||
Serializer();
|
||||
Serializer(const Serializer &other);
|
||||
Serializer& operator=(const Serializer &other);
|
||||
~Serializer();
|
||||
|
||||
public:
|
||||
static uintptr_t serialize(Data *ptr);
|
||||
static Data *deserialize(uintptr_t raw);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user