diff --git a/src/Entry.h b/include/cppIni/Entry.h similarity index 97% rename from src/Entry.h rename to include/cppIni/Entry.h index ed6c1d3..19c55a0 100644 --- a/src/Entry.h +++ b/include/cppIni/Entry.h @@ -18,6 +18,7 @@ #pragma once +#include #include class Section; @@ -28,7 +29,7 @@ class Section; /// \note The value is stored as a string. /// \note The value is copied into the Entry and not moved. /// \note The parent Section is a pointer to the Section object that contains this Entry. -class Entry { +class CPPINI_EXPORT Entry { public: constexpr Entry() = default; ///< Default constructor virtual ~Entry() = default; ///< Destructor @@ -105,6 +106,12 @@ inline auto Entry::setData(std::string value) -> void m_data = std::move(value); } +template<> +inline auto Entry::setData(std::string_view value) -> void +{ + m_data = value; +} + template<> inline auto Entry::value() const -> char { return std::stoi(m_data); } template<> inline auto Entry::value() const -> short { return std::stoi(m_data); } template<> inline auto Entry::value() const -> int { return std::stoi(m_data); } diff --git a/src/File.h b/include/cppIni/File.h similarity index 94% rename from src/File.h rename to include/cppIni/File.h index 3048c3c..d4aea57 100644 --- a/src/File.h +++ b/include/cppIni/File.h @@ -18,13 +18,15 @@ #pragma once -#include "Section.h" +#include +#include +#include #include /// \brief Represents a file on disk. /// A file is a collection of Sections. -class File { +class CPPINI_EXPORT File { public: explicit File(std::string_view filename); ///< Constructor. virtual ~File() = default; ///< Destructor. diff --git a/src/Section.h b/include/cppIni/Section.h similarity index 96% rename from src/Section.h rename to include/cppIni/Section.h index 5ecddd6..308494e 100644 --- a/src/Section.h +++ b/include/cppIni/Section.h @@ -18,14 +18,15 @@ #pragma once -#include "Entry.h" +#include +#include #include /// \brief Represents a section in a configuration file /// \details A section is a collection of Entry objects with a title (e.g. [Section]) in a configuration file /// \note A section has a title and a list of Entry objects -class Section { +class CPPINI_EXPORT Section { public: explicit Section(std::string_view title, Section* parent = nullptr); ///< Constructor with title diff --git a/include/cppIni/cppIni.h b/include/cppIni/cppIni.h index e6d6991..8f7249f 100644 --- a/include/cppIni/cppIni.h +++ b/include/cppIni/cppIni.h @@ -18,6 +18,6 @@ #pragma once -#include - -int CPPINI_EXPORT one(); +#include +#include +#include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a3429e..268dd6c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.24) set(CMAKE_DEBUG_POSTFIX d) set(SOURCES - cppIni.cpp - Entry.cpp File.cpp Section.cpp @@ -12,16 +10,17 @@ set(SOURCES set(API_HEADERS cppIni.h -) -LIST(TRANSFORM API_HEADERS PREPEND ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/) - -set(HEADERS Entry.h File.h Section.h ) +LIST(TRANSFORM API_HEADERS PREPEND ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/) + +set(PRIVATE_HEADERS + +) -add_library(${PROJECT_NAME} ${SOURCES} ${API_HEADERS} ${HEADERS}) +add_library(${PROJECT_NAME} ${SOURCES} ${API_HEADERS} ${PRIVATE_HEADERS}) include(GenerateExportHeader) string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) diff --git a/src/Entry.cpp b/src/Entry.cpp index 243c4b4..396fa1c 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#include "Entry.h" -#include "Section.h" +#include +#include auto Entry::fqKey() const -> std::string { diff --git a/src/File.cpp b/src/File.cpp index 8b621b4..ad1295d 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "File.h" +#include #include #include diff --git a/src/Section.cpp b/src/Section.cpp index 196845b..58f130d 100644 --- a/src/Section.cpp +++ b/src/Section.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "Section.h" +#include #include diff --git a/src/cppIni.cpp b/src/cppIni.cpp deleted file mode 100644 index be57b89..0000000 --- a/src/cppIni.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * cppIni - C++20/23 library for dealing with settings files - * Copyright (C) 2023 Nils Hofmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -int one() -{ - return 1; -} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b400dc5..ab235f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,14 +3,14 @@ cmake_minimum_required(VERSION 3.24) find_package(doctest REQUIRED) set(TEST_SOURCES - ConstructionTest.cpp EntryTest.cpp FileTest.cpp SectionTest.cpp ) add_executable(${PROJECT_NAME}_tests ${TEST_SOURCES}) -target_link_libraries(${PROJECT_NAME}_tests doctest::doctest cppIni) + +target_link_libraries(${PROJECT_NAME}_tests doctest::doctest ${PROJECT_NAME}) target_compile_definitions(${PROJECT_NAME}_tests PUBLIC DOCTEST_CONFIG_NO_MULTITHREADING @@ -18,7 +18,7 @@ target_compile_definitions(${PROJECT_NAME}_tests WORKING_DIR="${CMAKE_CURRENT_SOURCE_DIR}" ) -target_include_directories(${PROJECT_NAME} +target_include_directories(${PROJECT_NAME}_tests PUBLIC ${PROJECT_SOURCE_DIR}/include ${DOCTEST_INCLUDE_DIR} @@ -29,5 +29,5 @@ if(NOT DOCTEST_CMAKE) message(FATAL_ERROR "Could not find doctest.cmake") else() include(${DOCTEST_CMAKE}) - doctest_discover_tests(${PROJECT_NAME}_tests) + doctest_discover_tests(${PROJECT_NAME}_tests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../src) endif() diff --git a/tests/ConstructionTest.cpp b/tests/ConstructionTest.cpp deleted file mode 100644 index 1532c16..0000000 --- a/tests/ConstructionTest.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * cppIni - C++20/23 library for dealing with settings files - * Copyright (C) 2023 Nils Hofmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN - -#include -#include - -TEST_CASE("Construction test") -{ - CHECK_EQ(one(), 1); -} diff --git a/tests/EntryTest.cpp b/tests/EntryTest.cpp index a9ee376..fe13001 100644 --- a/tests/EntryTest.cpp +++ b/tests/EntryTest.cpp @@ -20,7 +20,7 @@ #include #include -#include "../src/Entry.h" +#include TEST_SUITE_BEGIN("Entry"); diff --git a/tests/FileTest.cpp b/tests/FileTest.cpp index 7a90847..8599d90 100644 --- a/tests/FileTest.cpp +++ b/tests/FileTest.cpp @@ -16,10 +16,11 @@ * along with this program. If not, see . */ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + #include -#include -#include "../src/File.h" +#include using namespace std::literals; diff --git a/tests/SectionTest.cpp b/tests/SectionTest.cpp index ff3fe28..f861c6e 100644 --- a/tests/SectionTest.cpp +++ b/tests/SectionTest.cpp @@ -1,5 +1,5 @@ /* - * cppIni - C++17/20/23 library for dealing with settings files + * cppIni - C++20/23 library for dealing with settings files * Copyright (C) 2023 Nils Hofmann * * This program is free software: you can redistribute it and/or modify @@ -18,7 +18,7 @@ #include -#include "../src/Section.h" +#include TEST_SUITE_BEGIN("Section");