Skip to content

Commit

Permalink
Prepare project for public API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Master92 committed Sep 20, 2023
2 parents 240f10f + c00c0d3 commit 4c47eea
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 79 deletions.
9 changes: 8 additions & 1 deletion src/Entry.h → include/cppIni/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include <cppIni/cppini_export.h>
#include <string>

class Section;
Expand All @@ -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
Expand Down Expand Up @@ -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<char>() const -> char { return std::stoi(m_data); }
template<> inline auto Entry::value<short>() const -> short { return std::stoi(m_data); }
template<> inline auto Entry::value<int>() const -> int { return std::stoi(m_data); }
Expand Down
6 changes: 4 additions & 2 deletions src/File.h → include/cppIni/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

#pragma once

#include "Section.h"
#include <cppIni/cppini_export.h>
#include <cppIni/Section.h>

#include <filesystem>
#include <vector>

/// \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.
Expand Down
5 changes: 3 additions & 2 deletions src/Section.h → include/cppIni/Section.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

#pragma once

#include "Entry.h"
#include <cppIni/cppini_export.h>
#include <cppIni/Entry.h>

#include <unordered_map>

/// \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

Expand Down
6 changes: 3 additions & 3 deletions include/cppIni/cppIni.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

#pragma once

#include <cppIni/cppini_export.h>

int CPPINI_EXPORT one();
#include <cppIni/File.h>
#include <cppIni/Section.h>
#include <cppIni/Entry.h>
13 changes: 6 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ cmake_minimum_required(VERSION 3.24)
set(CMAKE_DEBUG_POSTFIX d)

set(SOURCES
cppIni.cpp

Entry.cpp
File.cpp
Section.cpp
)

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)
Expand Down
4 changes: 2 additions & 2 deletions src/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "Entry.h"
#include "Section.h"
#include <cppIni/Entry.h>
#include <cppIni/Section.h>

auto Entry::fqKey() const -> std::string
{
Expand Down
2 changes: 1 addition & 1 deletion src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "File.h"
#include <cppIni/File.h>

#include <fstream>
#include <stdexcept>
Expand Down
2 changes: 1 addition & 1 deletion src/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "Section.h"
#include <cppIni/Section.h>

#include <algorithm>

Expand Down
24 changes: 0 additions & 24 deletions src/cppIni.cpp

This file was deleted.

8 changes: 4 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ 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
DOCTEST_CONFIG_USE_STD_HEADERS
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}
Expand All @@ -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()
27 changes: 0 additions & 27 deletions tests/ConstructionTest.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion tests/EntryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <sstream>
#include <vector>

#include "../src/Entry.h"
#include <cppIni/Entry.h>

TEST_SUITE_BEGIN("Entry");

Expand Down
5 changes: 3 additions & 2 deletions tests/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

#include <doctest/doctest.h>
#include <cstring>

#include "../src/File.h"
#include <cppIni/File.h>

using namespace std::literals;

Expand Down
4 changes: 2 additions & 2 deletions tests/SectionTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -18,7 +18,7 @@

#include <doctest/doctest.h>

#include "../src/Section.h"
#include <cppIni/Section.h>

TEST_SUITE_BEGIN("Section");

Expand Down

0 comments on commit 4c47eea

Please sign in to comment.