From c101364d4aafe50807cf7c8a831fb66eade3fb7f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 12 Oct 2024 17:23:56 +0200 Subject: wip --- backend/ArmorObject.h | 2 +- backend/Enemy.h | 2 -- backend/GoldObject.h | 2 +- backend/List.hpp | 3 +-- backend/Location.h | 4 ++-- backend/Object.cpp | 15 +++++++++++++++ backend/Object.h | 6 +++--- backend/check | 11 +++++++++++ makefile | 8 +++++++- 9 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 backend/Object.cpp create mode 100755 backend/check diff --git a/backend/ArmorObject.h b/backend/ArmorObject.h index c8223bc..e9c02d2 100644 --- a/backend/ArmorObject.h +++ b/backend/ArmorObject.h @@ -4,7 +4,7 @@ class ArmorObject : public Object { private: - int protection; + int protection = 0; }; diff --git a/backend/Enemy.h b/backend/Enemy.h index 036c5df..dd33090 100644 --- a/backend/Enemy.h +++ b/backend/Enemy.h @@ -1,7 +1,5 @@ #pragma once class Enemy { -private: - }; diff --git a/backend/GoldObject.h b/backend/GoldObject.h index 0f64ce2..f37b7d9 100644 --- a/backend/GoldObject.h +++ b/backend/GoldObject.h @@ -4,5 +4,5 @@ class GoldObject : public Object { private: - int count; + int count = 0; }; diff --git a/backend/List.hpp b/backend/List.hpp index df44f7a..d6c7738 100644 --- a/backend/List.hpp +++ b/backend/List.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include template struct ListLink { diff --git a/backend/Location.h b/backend/Location.h index 94c3eac..1b23c78 100644 --- a/backend/Location.h +++ b/backend/Location.h @@ -2,8 +2,8 @@ class Location { protected: - Location(); - virtual ~Location(); + Location() = default; + virtual ~Location() = default; friend class LocationFactory; }; diff --git a/backend/Object.cpp b/backend/Object.cpp new file mode 100644 index 0000000..300e6ac --- /dev/null +++ b/backend/Object.cpp @@ -0,0 +1,15 @@ +#include + +#include "Object.h" + +Object::~Object() { + if (this->name != nullptr) { + free(const_cast(this->name)); + this->name = nullptr; + } + if (this->description != nullptr) { + free(const_cast(this->description)); + this->description = nullptr; + } +} + diff --git a/backend/Object.h b/backend/Object.h index 8127f08..789de25 100644 --- a/backend/Object.h +++ b/backend/Object.h @@ -2,11 +2,11 @@ class Object { private: - const char * name; - const char * description; + const char * name = nullptr; + const char * description = nullptr; protected: - Object(); + Object() = default; virtual ~Object(); friend class ObjectFactory; diff --git a/backend/check b/backend/check new file mode 100755 index 0000000..445dbbe --- /dev/null +++ b/backend/check @@ -0,0 +1,11 @@ +#!/bin/sh +for file in *.cpp *.hpp *.h ; do + # non C-style headers + grep -Hn '#include\s*<[^.]\+>' "$file" + # forbidden STL containers + grep -Hn '\' "$file" + grep -Hn '\' "$file" + grep -Hn '\' "$file" +done +exit 0 + diff --git a/makefile b/makefile index 396d7b3..f6797c7 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,13 @@ .PHONY: FORCE +CXXFLAGS += -std=c++20 +LDFLAGS += -lstdc++ + OBJS += main.o -OBJS += backend/List.o +OBJS += backend/EnemyFactory.o +OBJS += backend/LocationFactory.o +OBJS += backend/ObjectFactory.o +OBJS += backend/Object.o main: $(OBJS) -- cgit v1.2.3