add: ex01
This commit is contained in:
parent
4afd76b65b
commit
671d71f273
26
ex01/Makefile
Normal file
26
ex01/Makefile
Normal file
@ -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
|
9
ex01/src/Data.hpp
Normal file
9
ex01/src/Data.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef struct s_data
|
||||
{
|
||||
std::string name;
|
||||
int id;
|
||||
} Data;
|
29
ex01/src/Serializer.cpp
Normal file
29
ex01/src/Serializer.cpp
Normal file
@ -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<uintptr_t>(ptr);
|
||||
}
|
||||
|
||||
Data* Serializer::deserialize(uintptr_t raw)
|
||||
{
|
||||
return reinterpret_cast<Data *>(raw);
|
||||
}
|
19
ex01/src/Serializer.hpp
Normal file
19
ex01/src/Serializer.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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);
|
||||
};
|
13
ex01/src/main.cpp
Normal file
13
ex01/src/main.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "Data.hpp"
|
||||
#include "Serializer.hpp"
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user