Skip to content

Convert pini to a library #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[*]
insert_final_newline = true
charset = utf-8
indent_size = 4
indent_style = tab
# Optional: git will commit as lf, this will only affect local files
end_of_line = lf

[*.{py,md,yml,sh,cmake}]
indent_style = space
indent_size = 2

[*.{py,md,yml,sh}.in]
indent_style = space
indent_size = 2

[CMakeLists.txt]
indent_style = space
indent_size = 2
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
cmake_minimum_required(VERSION 3.19)

project(pini)
add_executable(${PROJECT_NAME} src/main.cpp
src/util.cpp
src/pini.cpp)
add_library(${PROJECT_NAME} src/util.cpp
src/util.hpp
src/pini.cpp
include/pini/pini.hpp)
add_library(pini::pini ALIAS pini)
target_include_directories(${PROJECT_NAME} PRIVATE src PUBLIC include)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror=return-type)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

option(PINI_BUILD_TESTS "Build tests" ON)

if(PINI_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

set(CCJSON "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json")
if(EXISTS "${CCJSON}")
message(STATUS "Copying ${CCJSON} to project root")
file(COPY "${CCJSON}" DESTINATION "${PROJECT_SOURCE_DIR}")
endif()
endif()
1 change: 0 additions & 1 deletion src/pini.hpp → include/pini/pini.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <string_view>
#include <unordered_map>
#include <vector>
#include "util.hpp"

namespace pn {
class pini {
Expand Down
18 changes: 0 additions & 18 deletions src/main.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions src/pini.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "pini.hpp"
#include <cstddef>
#include <cstdint>
#include <sstream>
#include <string_view>
#include <vector>
#include "util.hpp"
#include <pini/pini.hpp>
#include <util.hpp>


namespace pn {
namespace {
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "util.hpp"
#include <cassert>
#include <util.hpp>

namespace util {

Expand Down
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.19)

project(pini-test)
add_executable(${PROJECT_NAME} pini_test.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE pini::pini)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror=return-type)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

add_test(pini-test pini-test)
12 changes: 12 additions & 0 deletions test/pini_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <ios>
#include <iostream>
#include <pini/pini.hpp>

int main() {
pn::pini pin;

std::string_view raw_input{"a=5\nb=10\n23=c"};
// std::filesystem::path filename{"/test/test.ini"};
if (!pin.load_text(raw_input)) { return 1; }
if (pin.get_int32("a") != 5) { return 1; }
}