Skip to content
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

fhiclcpp to fhiclcppsimple + some new features #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 19 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.14 FATAL_ERROR)

project(fhiclcpp VERSION 23.06 LANGUAGES CXX)
project(fhiclcppsimple VERSION 23.06 LANGUAGES CXX)

if(NOT DEFINED CMAKE_INSTALL_PREFIX OR
"${CMAKE_INSTALL_PREFIX}x" STREQUAL "x" OR
Expand All @@ -25,44 +25,44 @@ if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14)
set(CMAKE_CXX_STANDARD 14)
endif()

include (${PROJECT_SOURCE_DIR}/cmake/Modules/fhiclcppDependencies.cmake)
include (${PROJECT_SOURCE_DIR}/cmake/Modules/fhiclcppsimpleDependencies.cmake)

add_library(fhiclcpp_includes INTERFACE)
target_include_directories(fhiclcpp_includes INTERFACE
add_library(fhiclcppsimple_includes INTERFACE)
target_include_directories(fhiclcppsimple_includes INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(fhiclcpp_includes INTERFACE linedoc::includes)
set_target_properties(fhiclcpp_includes PROPERTIES EXPORT_NAME fhiclcpp::includes)
target_link_libraries(fhiclcppsimple_includes INTERFACE linedoc::includes)
set_target_properties(fhiclcppsimple_includes PROPERTIES EXPORT_NAME fhiclcppsimple::includes)

install(TARGETS fhiclcpp_includes EXPORT fhiclcppTargets)
install(TARGETS fhiclcppsimple_includes EXPORT fhiclcppsimpleTargets)

add_library(fhiclcpp::includes ALIAS fhiclcpp_includes)
add_library(fhiclcppsimple::includes ALIAS fhiclcppsimple_includes)

add_subdirectory(fhiclcpp)
add_subdirectory(fhiclcppsimple)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/fhiclcppConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/fhiclcppsimpleConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/Templates/fhiclcppConfig.cmake.in"
"${PROJECT_BINARY_DIR}/fhiclcppConfig.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/Templates/fhiclcppsimpleConfig.cmake.in"
"${PROJECT_BINARY_DIR}/fhiclcppsimpleConfig.cmake"
INSTALL_DESTINATION cmake
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

install(EXPORT fhiclcppTargets
DESTINATION lib/cmake/fhiclcpp )
install(EXPORT fhiclcppsimpleTargets
DESTINATION lib/cmake/fhiclcppsimple )

install(FILES "${PROJECT_BINARY_DIR}/fhiclcppConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/fhiclcppConfig.cmake"
DESTINATION lib/cmake/fhiclcpp)
install(FILES "${PROJECT_BINARY_DIR}/fhiclcppsimpleConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/fhiclcppsimpleConfig.cmake"
DESTINATION lib/cmake/fhiclcppsimple)

configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/Templates/setup.fhiclcpp.sh.in ${PROJECT_BINARY_DIR}/setup.fhiclcpp.sh @ONLY)
install(PROGRAMS ${PROJECT_BINARY_DIR}/setup.fhiclcpp.sh DESTINATION bin)
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/Templates/setup.fhiclcppsimple.sh.in ${PROJECT_BINARY_DIR}/setup.fhiclcppsimple.sh @ONLY)
install(PROGRAMS ${PROJECT_BINARY_DIR}/setup.fhiclcppsimple.sh DESTINATION bin)

if(DOTEST)
file(GLOB EXAMPLE_FCL fcl/*.fcl)
Expand Down
37 changes: 0 additions & 37 deletions cmake/Templates/fhiclcppConfig.cmake.in

This file was deleted.

37 changes: 37 additions & 0 deletions cmake/Templates/fhiclcppsimpleConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@PACKAGE_INIT@

find_package(linedoc REQUIRED)

set(fhiclcppsimple_VERSION @PROJECT_VERSION@)

include(${CMAKE_CURRENT_LIST_DIR}/fhiclcppsimpleTargets.cmake)
if(NOT TARGET fhiclcppsimple::includes)
message(WARNING "Expected to find target fhiclcppsimple::includes in ${CMAKE_CURRENT_LIST_DIR}/fhiclcppsimpleTargets.cmake")
set(fhiclcppsimple_FOUND FALSE)
return()
endif()

get_filename_component(fhiclcppsimple_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

find_path(fhiclcppsimple_INCLUDE_DIR
NAMES fhiclcppsimple/fhicl_doc.hxx
PATHS ${fhiclcppsimple_CMAKE_DIR}/../../../include
)

find_path(fhiclcppsimple_PREFIX
NAMES bin/setup.fhiclcppsimple.sh
PATHS ${fhiclcppsimple_CMAKE_DIR}/../../../
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(fhiclcppsimple
REQUIRED_VARS
fhiclcppsimple_INCLUDE_DIR
fhiclcppsimple_PREFIX
VERSION_VAR
fhiclcppsimple_VERSION
)

message(STATUS "Found fhiclcppsimple Version: ${fhiclcppsimple_VERSION} in \"${fhiclcppsimple_CMAKE_DIR}\"")
message(STATUS " fhiclcppsimple_INCLUDE_DIR: ${fhiclcppsimple_INCLUDE_DIR}")
message(STATUS " fhiclcppsimple_PREFIX: ${fhiclcppsimple_PREFIX}")
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function add_to_FHICL_FILE_PATH () {

fi

export fhiclcpp_ROOT="@CMAKE_INSTALL_PREFIX@"
export fhiclcpp_VERSION="@PROJECT_VERSION@"
export fhiclcppsimple_ROOT="@CMAKE_INSTALL_PREFIX@"
export fhiclcppsimple_VERSION="@PROJECT_VERSION@"

add_to_PATH "${fhiclcpp_ROOT}/bin"
add_to_PATH "${fhiclcppsimple_ROOT}/bin"

if [ "@DOTEST_CONFIG@" == "TRUE" ]; then
add_to_FHICL_FILE_PATH "${fhiclcpp_ROOT}/fcl"
add_to_FHICL_FILE_PATH "${fhiclcppsimple_ROOT}/fcl"
fi
6 changes: 0 additions & 6 deletions fhiclcpp/ParameterSet.h

This file was deleted.

22 changes: 0 additions & 22 deletions fhiclcpp/make_ParameterSet.h

This file was deleted.

6 changes: 3 additions & 3 deletions fhiclcpp/CMakeLists.txt → fhiclcppsimple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ add_subdirectory(string_parsers)
add_subdirectory(types)

add_executable(fhicl-dump fhicl-dump.cxx)
target_link_libraries(fhicl-dump fhiclcpp_includes linedoc::includes)
target_link_libraries(fhicl-dump fhiclcppsimple_includes linedoc::includes)
install(TARGETS fhicl-dump DESTINATION bin)

if(DOTEST)
add_executable(fhiclcpp_tests tests.cxx)
target_link_libraries(fhiclcpp_tests fhiclcpp_includes linedoc::includes)
target_link_libraries(fhiclcpp_tests fhiclcppsimple_includes linedoc::includes)
install(TARGETS fhiclcpp_tests DESTINATION test)

add_test(NAME fhiclcpp_tests COMMAND fhiclcpp_tests)
Expand All @@ -19,4 +19,4 @@ install(FILES
make_ParameterSet.h
ParameterSet.h
recursive_build_fhicl.hxx
DESTINATION include/fhiclcpp)
DESTINATION include/fhiclcppsimple)
6 changes: 6 additions & 0 deletions fhiclcppsimple/ParameterSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "fhiclcppsimple/types/ParameterSet.hxx"
#include "fhiclcppsimple/types/Sequence.hxx"

#include "fhiclcppsimple/types/CompositeTypesSharedImpl.hxx"
6 changes: 3 additions & 3 deletions fhiclcpp/exception.hxx → fhiclcppsimple/exception.hxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "fhiclcpp/types/exception.hxx"
#include "fhiclcppsimple/types/exception.hxx"

#include <sstream>
#include <stdexcept>

namespace fhicl {
namespace fhiclsimple {

#define NEW_EXCEPT(EXCEPT_NAME) \
struct EXCEPT_NAME : public fhicl_cpp_simple_except { \
Expand Down Expand Up @@ -36,4 +36,4 @@ struct unexpected_newline : public malformed_document {
}
};

} // namespace fhicl
} // namespace fhiclsimple
2 changes: 1 addition & 1 deletion fhiclcpp/fhicl-dump.cxx → fhiclcppsimple/fhicl-dump.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ int main(int argc, char const *argv[]) {
return 1;
}

fhicl::ParameterSet ps = fhicl::make_ParameterSet(argv[1]);
fhiclsimple::ParameterSet ps = fhiclsimple::make_ParameterSet(argv[1]);
std::cout << ps.to_indented_string() << std::endl;
}
30 changes: 25 additions & 5 deletions fhiclcpp/fhicl_doc.hxx → fhiclcppsimple/fhicl_doc.hxx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "fhiclcpp/exception.hxx"
#include "fhiclcppsimple/exception.hxx"

#include "fhiclcpp/string_parsers/traits.hxx"
#include "fhiclcpp/string_parsers/utility.hxx"
#include "fhiclcppsimple/string_parsers/traits.hxx"
#include "fhiclcppsimple/string_parsers/utility.hxx"

#include "linedoc/doc.hxx"

Expand All @@ -12,18 +12,21 @@
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>

// Unix
#include <dirent.h>
#include <unistd.h>

namespace fhicl {
namespace fhiclsimple {

class fhicl_doc;

inline fhicl_doc read_doc(std::string const &filename);
inline fhicl_doc convert_from_string(std::string const &str);
inline linedoc::doc_line_point find_matching_bracket(
fhicl_doc const &doc, char open_bracket = '{', char close_bracket = '}',
linedoc::doc_line_point begin = linedoc::doc_line_point::begin());
Expand Down Expand Up @@ -613,4 +616,21 @@ inline fhicl_doc read_doc(std::string const &filename) {
return doc;
}

} // namespace fhicl
inline fhicl_doc convert_from_string(std::string const &str){

std::istringstream iss(str);

std::string line;
fhicl_doc doc;
size_t ctr = 0;

while (std::getline(iss, line)) {
string_parsers::trim(line);
doc.push_back(line, "", ctr);
ctr++;
}
return doc;

}

} // namespace fhiclsimple
33 changes: 33 additions & 0 deletions fhiclcppsimple/make_ParameterSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "fhiclcppsimple/ParameterSet.h"
#include "fhiclcppsimple/recursive_build_fhicl.hxx"

namespace fhiclsimple {

inline ParameterSet make_ParameterSet(std::string const &filename) {
ParameterSet prolog;
ParameterSet working_doc;

fhiclsimple::fhicl_doc doc = fhiclsimple::read_doc(filename);
doc.resolve_includes();

return parse_fhicl_document(doc);
}

inline ParameterSet make_ParameterSet_from_string(std::string const &str) {
ParameterSet prolog;
ParameterSet working_doc;

fhiclsimple::fhicl_doc doc = fhiclsimple::convert_from_string(str);

doc.resolve_includes();

return parse_fhicl_document(doc);
}

inline void make_ParameterSet(std::string const &filename, ParameterSet& pset){
pset = make_ParameterSet(filename);
}

} // namespace fhiclsimple
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include "fhiclcpp/ParameterSet.h"
#include "fhiclcppsimple/ParameterSet.h"

#include "fhiclcpp/fhicl_doc.hxx"
#include "fhiclcppsimple/fhicl_doc.hxx"

#include <cstdio>

namespace fhicl {
namespace fhiclsimple {

inline ParameterSet parse_fhicl_document(fhicl_doc const &,
ParameterSet const &,
Expand Down Expand Up @@ -222,7 +222,8 @@ parse_object(fhicl_doc const &doc, linedoc::doc_range range,
<< ". N.B. quoted strings cannot span multiple lines.";
}

std::string value = doc.substr(first_string_point, matching_quote);
std::string value = "\""+doc.substr(first_string_point, matching_quote)+"\"";

next_character = doc.advance(matching_quote);
#ifdef FHICLCPP_SIMPLE_PARSERS_DEBUG
std::cout << indent << "[INFO]: Found KV: {" << std::quoted(current_key)
Expand Down Expand Up @@ -620,4 +621,4 @@ parse_fhicl_document(fhicl_doc const &doc,

return (*ps);
}
} // namespace fhicl
} // namespace fhiclsimple
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(DOTEST)
add_executable(string_parsers_tests tests.cxx)
target_link_libraries(string_parsers_tests fhiclcpp_includes linedoc::includes)
target_link_libraries(string_parsers_tests fhiclcppsimple_includes linedoc::includes)
install(TARGETS string_parsers_tests DESTINATION test)

add_test(NAME string_parsers_tests COMMAND string_parsers_tests)
Expand All @@ -13,4 +13,4 @@ install(FILES
to_string.hxx
traits.hxx
utility.hxx
DESTINATION include/fhiclcpp/string_parsers)
DESTINATION include/fhiclcppsimple/string_parsers)
Loading