Name to 'Gedeng', restructure + namespaces

This commit is contained in:
karl 2021-03-20 14:51:45 +01:00
parent b9dfd40089
commit 59b432abc7
12 changed files with 92 additions and 36 deletions

View File

@ -1,17 +1,17 @@
#!python #!python
# Create the environment and create a Compilation Database for use in VSCodium # Create the environment and create a Compilation Database for use in VSCodium
env = DefaultEnvironment(tools=['default', 'compilation_db']) env = Environment(tools=['default', 'compilation_db'])
env.CompilationDatabase() env.CompilationDatabase()
env.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"]) env.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"])
env.Append(CPPPATH=['.', 'include']) env.Append(CPPPATH=['cpp/', 'include/'])
# Build the library # Build the library
env.SharedLibrary('lib/ged', Glob('cpp/*.cpp')) env.SharedLibrary('lib/ged', Glob('cpp/*.cpp'))
# Build the test libraries # Build the test libraries
testEnv = DefaultEnvironment(tools=['default', 'compilation_db']) testEnv = Environment(tools=['default', 'compilation_db'])
testEnv.CompilationDatabase() testEnv.CompilationDatabase()
testEnv.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"]) testEnv.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"])
@ -20,7 +20,6 @@ testEnv.Append(LIBPATH=['lib/'])
testEnv.Append(LIBS=['ged']) testEnv.Append(LIBS=['ged'])
testEnv.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"]) testEnv.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"])
testEnv.Append(CPPPATH=['.', 'include'])
# Build the test programs # Build the test programs
catch_cpp = "test/catch_amalgamated.cpp" catch_cpp = "test/catch_amalgamated.cpp"

11
cpp/Application.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "Gedeng/Application.h"
namespace Gedeng {
void Application::run() {
while (true) {
// TODO: Implement
}
}
} // namespace Gedeng

View File

@ -1,6 +1,10 @@
#include "Logger.h" #include "Gedeng/Logger.h"
#include <iostream> #include <iostream>
namespace Gedeng {
void Logger::debug(const String &text) { void Logger::debug(const String &text) {
std::cout << "Debug: " << text << std::endl; std::cout << "Debug: " << text << std::endl;
} }
} // namespace Gedeng

View File

@ -1,4 +1,6 @@
#include "String.h" #include "Gedeng/String.h"
namespace Gedeng {
String::String() : String("") { String::String() : String("") {
} }
@ -116,4 +118,6 @@ const char *String::c_str() const {
size_t String::getLength() const { size_t String::getLength() const {
return length; return length;
} }
} // namespace Gedeng

6
include/Gedeng.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include "Gedeng/Application.h"
#include "Gedeng/Logger.h"
#include "Gedeng/String.h"
#include "Gedeng/Vector.h"

View File

@ -0,0 +1,14 @@
#pragma once
namespace Gedeng {
class Application {
Application() = default;
// Virtual since this class will be inherited by user-created applications
virtual ~Application() = default;
void run();
};
} // namespace Gedeng

1
include/Gedeng/Core.h Normal file
View File

@ -0,0 +1 @@
#pragma once

11
include/Gedeng/Logger.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "Gedeng/String.h"
namespace Gedeng {
class Logger {
static void debug(const String &text);
};
} // namespace Gedeng

View File

@ -1,5 +1,9 @@
#pragma once
#include <cstring> #include <cstring>
namespace Gedeng {
class String { class String {
public: public:
/// Create a new empty String /// Create a new empty String
@ -50,4 +54,6 @@ class String {
size_t length; size_t length;
char *text; char *text;
}; };
} // namespace Gedeng

View File

@ -1,8 +1,11 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
namespace Gedeng {
template <class T> template <class T>
class Vector { class Vector {
public: public:
@ -214,3 +217,5 @@ class Vector {
data = new_data; data = new_data;
} }
}; };
} // namespace Gedeng

View File

@ -1,5 +0,0 @@
#include "String.h"
class Logger {
static void debug(const String &text);
};

View File

@ -1,4 +1,4 @@
#include <Vector.h> #include <Gedeng.h>
#include <iostream> #include <iostream>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
@ -6,7 +6,7 @@
#include "catch_amalgamated.hpp" #include "catch_amalgamated.hpp"
SCENARIO("Vector size and length are correct", "[vector]") { SCENARIO("Vector size and length are correct", "[vector]") {
Vector<int> v(20); Gedeng::Vector<int> v(20);
v.push_back(1); v.push_back(1);
REQUIRE(v.size() == 1); REQUIRE(v.size() == 1);
@ -15,7 +15,7 @@ SCENARIO("Vector size and length are correct", "[vector]") {
SCENARIO("The bracket operator returns the correct element", "[vector]") { SCENARIO("The bracket operator returns the correct element", "[vector]") {
GIVEN("A vector with some elements") { GIVEN("A vector with some elements") {
Vector<int> v(20); Gedeng::Vector<int> v(20);
v.push_back(1); v.push_back(1);
v.push_back(2); v.push_back(2);
v.push_back(3); v.push_back(3);
@ -32,8 +32,8 @@ SCENARIO("The bracket operator returns the correct element", "[vector]") {
SCENARIO("Equality is returned correctly", "[vector]") { SCENARIO("Equality is returned correctly", "[vector]") {
GIVEN("Two vectors with the same items") { GIVEN("Two vectors with the same items") {
Vector<int> v1; Gedeng::Vector<int> v1;
Vector<int> v2; Gedeng::Vector<int> v2;
v1.push_back(1); v1.push_back(1);
v2.push_back(1); v2.push_back(1);
@ -54,8 +54,8 @@ SCENARIO("Equality is returned correctly", "[vector]") {
} }
GIVEN("Two vectors with different items") { GIVEN("Two vectors with different items") {
Vector<int> v1; Gedeng::Vector<int> v1;
Vector<int> v2; Gedeng::Vector<int> v2;
v1.push_back(1); v1.push_back(1);
v2.push_back(2); v2.push_back(2);
@ -79,8 +79,8 @@ SCENARIO("Equality is returned correctly", "[vector]") {
SCENARIO("Erasing an item removes it and moves the following ones forward", SCENARIO("Erasing an item removes it and moves the following ones forward",
"[vector]") { "[vector]") {
GIVEN("Two vectors with almost identical items") { GIVEN("Two vectors with almost identical items") {
Vector<int> v1; Gedeng::Vector<int> v1;
Vector<int> v2; Gedeng::Vector<int> v2;
v1.push_back(1); v1.push_back(1);
v2.push_back(1); v2.push_back(1);
@ -117,8 +117,8 @@ SCENARIO("Erasing an item removes it and moves the following ones forward",
SCENARIO("Copy Assignment", "[vector]") { SCENARIO("Copy Assignment", "[vector]") {
GIVEN("Two vectors with identical items") { GIVEN("Two vectors with identical items") {
Vector<int> v1; Gedeng::Vector<int> v1;
Vector<int> v2; Gedeng::Vector<int> v2;
v1.push_back(1); v1.push_back(1);
v2.push_back(1); v2.push_back(1);
@ -130,7 +130,7 @@ SCENARIO("Copy Assignment", "[vector]") {
REQUIRE(v2.size() == 2); REQUIRE(v2.size() == 2);
WHEN("Copy assigning the second vector to a third vector") { WHEN("Copy assigning the second vector to a third vector") {
Vector<int> v3; Gedeng::Vector<int> v3;
v3 = v2; v3 = v2;
THEN("All vectors should be identical") { THEN("All vectors should be identical") {
@ -143,8 +143,8 @@ SCENARIO("Copy Assignment", "[vector]") {
SCENARIO("Move Assignment", "[vector]") { SCENARIO("Move Assignment", "[vector]") {
GIVEN("Two vectors with identical items") { GIVEN("Two vectors with identical items") {
Vector<int> v1; Gedeng::Vector<int> v1;
Vector<int> v2; Gedeng::Vector<int> v2;
v1.push_back(1); v1.push_back(1);
v2.push_back(1); v2.push_back(1);
@ -156,7 +156,7 @@ SCENARIO("Move Assignment", "[vector]") {
REQUIRE(v2.size() == 2); REQUIRE(v2.size() == 2);
WHEN("Move assigning the second vector to a third vector") { WHEN("Move assigning the second vector to a third vector") {
Vector<int> v3; Gedeng::Vector<int> v3;
v3 = std::move(v2); v3 = std::move(v2);
THEN("The first and third vector should be identical") { THEN("The first and third vector should be identical") {
@ -169,7 +169,7 @@ SCENARIO("Move Assignment", "[vector]") {
SCENARIO("Reserve additional space", "[vector]") { SCENARIO("Reserve additional space", "[vector]") {
GIVEN("A vector with a given length") { GIVEN("A vector with a given length") {
Vector<int> v(5); Gedeng::Vector<int> v(5);
REQUIRE(v.length() == 5); REQUIRE(v.length() == 5);
@ -185,13 +185,13 @@ SCENARIO("Reserve additional space", "[vector]") {
SCENARIO("Resizing a vector", "[vector]") { SCENARIO("Resizing a vector", "[vector]") {
GIVEN("A vector with 3 items") { GIVEN("A vector with 3 items") {
Vector<int> v; Gedeng::Vector<int> v;
v.push_back(1); v.push_back(1);
v.push_back(2); v.push_back(2);
v.push_back(3); v.push_back(3);
Vector<int> target; Gedeng::Vector<int> target;
target.push_back(1); target.push_back(1);
target.push_back(2); target.push_back(2);
@ -256,7 +256,7 @@ SCENARIO("Non-default constructor", "[vector]") {
}; };
WHEN("Creating a vector and adding an element") { WHEN("Creating a vector and adding an element") {
Vector<NonDefault> non_default_vector; Gedeng::Vector<NonDefault> non_default_vector;
non_default_vector.push_back(NonDefault(1)); non_default_vector.push_back(NonDefault(1));
@ -266,7 +266,7 @@ SCENARIO("Non-default constructor", "[vector]") {
} }
WHEN("Creating a vector and resizing it") { WHEN("Creating a vector and resizing it") {
Vector<NonDefault> non_default_vector; Gedeng::Vector<NonDefault> non_default_vector;
non_default_vector.resize(50, NonDefault(42)); non_default_vector.resize(50, NonDefault(42));
@ -279,7 +279,7 @@ SCENARIO("Non-default constructor", "[vector]") {
SCENARIO("Erase by swap", "[vector]") { SCENARIO("Erase by swap", "[vector]") {
GIVEN("A vector with some elements") { GIVEN("A vector with some elements") {
Vector<int> v(3); Gedeng::Vector<int> v(3);
v.push_back(1); v.push_back(1);
v.push_back(2); v.push_back(2);
v.push_back(3); v.push_back(3);
@ -330,7 +330,7 @@ class ReferenceCounter {
SCENARIO("Constructors and Destructors are called as expected", "[vector]") { SCENARIO("Constructors and Destructors are called as expected", "[vector]") {
GIVEN("A vector with a custom reference-counting class") { GIVEN("A vector with a custom reference-counting class") {
Vector<ReferenceCounter> v(3); Gedeng::Vector<ReferenceCounter> v(3);
v.push_back(ReferenceCounter()); v.push_back(ReferenceCounter());
v.push_back(ReferenceCounter()); v.push_back(ReferenceCounter());
v.push_back(ReferenceCounter()); v.push_back(ReferenceCounter());
@ -370,7 +370,7 @@ SCENARIO("Constructors and Destructors are called as expected", "[vector]") {
} }
WHEN("Move-constructing another vector") { WHEN("Move-constructing another vector") {
Vector<ReferenceCounter> v2 = std::move(v); Gedeng::Vector<ReferenceCounter> v2 = std::move(v);
THEN("The reference count should have remained the same") { THEN("The reference count should have remained the same") {
REQUIRE(count == 3); REQUIRE(count == 3);