From 614ae1c711b676712a4fce6d9528707ceac2c64c Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 15 Nov 2022 17:05:14 +0100 Subject: [PATCH] I will murder cmake --- CMakeLists.txt | 7 ++++--- src/main.cpp | 5 ++++- tries/CMakeLists.txt | 10 +++++++--- tries/src/ternarytrie.c | 8 ++++---- tries/src/ternarytrie_node.c | 8 ++++---- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5122f34..22ba78b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,16 @@ cmake_minimum_required(VERSION 3.20) project(lander C CXX) -set(CMAKE_C_STANDARD 17) +set(CMAKE_CXX_STANDARD 11) + +include_directories(crow/include tries/include) add_subdirectory(crow) add_subdirectory(tries) -include_directories(crow/include tries/include) if(CMAKE_BUILD_TYPE STREQUAL Release) add_compile_options(-O3 -flto) endif() add_executable(lander src/main.cpp) -target_link_libraries(lander PUBLIC Crow ternarytrie) +target_link_libraries(lander Crow ternarytrie) diff --git a/src/main.cpp b/src/main.cpp index f343c67..72ccf56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,13 @@ #include "crow.h" +#include "ternarytrie.h" int main() { + TernaryTrie *trie = ternarytrie_init(); + crow::SimpleApp app; - CROW_ROUTE(app, "/")([](){ + CROW_ROUTE(app, "/").methods(crow::HTTPMethod::Get, crow::HTTPMethod::Post)([](){ return "Hello world"; }); diff --git a/tries/CMakeLists.txt b/tries/CMakeLists.txt index 08f1a94..d02e243 100644 --- a/tries/CMakeLists.txt +++ b/tries/CMakeLists.txt @@ -1,8 +1,12 @@ cmake_minimum_required(VERSION 3.20) -project(AD3-project-2022-2023 C) +project(ternarytrie C) set(CMAKE_C_STANDARD 17) -include_directories(include) -add_library(ternarytrie STATIC include/ternarytrie.h src/ternarytrie.c) +add_library(ternarytrie STATIC src/ternarytrie.c) + +target_include_directories( + ternarytrie PUBLIC + $ +) diff --git a/tries/src/ternarytrie.c b/tries/src/ternarytrie.c index 6578527..bb3ce1c 100644 --- a/tries/src/ternarytrie.c +++ b/tries/src/ternarytrie.c @@ -14,7 +14,7 @@ typedef struct ttrie { * * @return pointer to the empty TernaryTrie */ -inline TernaryTrie *ternarytrie_init() { +TernaryTrie *ternarytrie_init() { TernaryTrie *node = calloc(1, sizeof(TernaryTrie)); node->root = ttnode_init(); @@ -26,7 +26,7 @@ inline TernaryTrie *ternarytrie_init() { * * @param trie trie to free */ -inline void ternarytrie_free(TernaryTrie *trie) { +void ternarytrie_free(TernaryTrie *trie) { ttnode_free(trie->root); free(trie); } @@ -94,7 +94,7 @@ SearchResult ternarytrie_search_node(TernaryTrie *trie, const char *string) { * @param string string to look up * @return true if the string is present in the trie, false otherwise */ -inline bool ternarytrie_search(TernaryTrie *trie, const char *string) { +bool ternarytrie_search(TernaryTrie *trie, const char *string) { SearchResult res = ternarytrie_search_node(trie, string); return res.child != NULL; @@ -244,4 +244,4 @@ bool ternarytrie_remove(TernaryTrie *trie, const char *string) { * @param trie trie to return size for * @return size of the trie */ -inline size_t ternarytrie_size(TernaryTrie *trie) { return trie->size; } +size_t ternarytrie_size(TernaryTrie *trie) { return trie->size; } diff --git a/tries/src/ternarytrie_node.c b/tries/src/ternarytrie_node.c index f101a3a..413e1ed 100644 --- a/tries/src/ternarytrie_node.c +++ b/tries/src/ternarytrie_node.c @@ -51,7 +51,7 @@ void ttnode_free(TernaryTrieNode *node); * @param c character to represent * @return pointer to newly allocated struct */ -inline TernaryTrieInnerNode *ttinode_init(char c) { +TernaryTrieInnerNode *ttinode_init(char c) { TernaryTrieInnerNode *node = calloc(1, sizeof(TernaryTrieInnerNode)); node->key = c; @@ -63,7 +63,7 @@ inline TernaryTrieInnerNode *ttinode_init(char c) { * * @return pointer to newly allocated struct */ -inline TernaryTrieNode *ttnode_init() { return calloc(1, sizeof(TernaryTrieNode)); } +TernaryTrieNode *ttnode_init() { return calloc(1, sizeof(TernaryTrieNode)); } /** * Free a TernaryTrieInnerNode and its underlying tree structure. This should @@ -109,7 +109,7 @@ void ttnode_free(TernaryTrieNode *node) { * @param node node to add string to * @param string string to add */ -inline void ttnode_set_string(TernaryTrieNode *node, const char *string) { +void ttnode_set_string(TernaryTrieNode *node, const char *string) { node->type = 2; node->size = strlen(string); node->ptr.string = my_strdup(string); @@ -301,7 +301,7 @@ void ttinode_remove(TernaryTrieInnerNode *node, const char c) { * @param node node to remove character from * @param c character to remove */ -inline void ttnode_remove(TernaryTrieNode *node, const char c) { +void ttnode_remove(TernaryTrieNode *node, const char c) { ttinode_remove(node->ptr.root, c); node->size--;