Compare commits

...

17 Commits

Author SHA1 Message Date
Maarten L. Hekkelman
288b2bb720 update changelog 2023-10-17 12:23:59 +02:00
Maarten L. Hekkelman
fb3b7bda68 made data dir options more visible in cmake config
better error reporting in file::load
2023-10-10 13:39:13 +02:00
Maarten L. Hekkelman
6d5efe1cbd Merge branch 'trunk' of github.com:PDB-REDO/libcifpp into trunk 2023-09-26 14:40:44 +02:00
Maarten L. Hekkelman
1ceec22184 Better conversion from string to int 2023-09-26 14:40:38 +02:00
Maarten L. Hekkelman
951ff9b953 Better conversion from string to int 2023-09-26 14:39:26 +02:00
Maarten L. Hekkelman
641f06a7e7 sqrt is not constexpr on macOS 2023-09-22 09:37:15 +02:00
Maarten L. Hekkelman
915ba4ac21 describe download CCD 2023-09-18 10:49:08 +02:00
Maarten L. Hekkelman
824637d83f Update README.md, add link to documentation 2023-09-15 08:56:34 +02:00
Maarten L. Hekkelman
0871406fe3 Eigen dependency removed for clients
Typos fixed
Version bump
2023-09-14 16:03:00 +02:00
Maarten L. Hekkelman
1ad7e47b2e version bump, changelog 2023-09-14 12:53:07 +02:00
Maarten L. Hekkelman
f72a2c69d0 rename doxygen target 2023-09-14 11:14:38 +02:00
Maarten L. Hekkelman
84d9275cb8 update versionstring 2023-09-14 11:12:49 +02:00
Maarten L. Hekkelman
1b7c387c8b reintroduced get_terminal_width as an exported function 2023-09-14 09:52:52 +02:00
Maarten L. Hekkelman
2f1adbd22c clean up 2023-09-14 09:45:13 +02:00
Maarten L. Hekkelman
65031523a6 Merge branch 'trunk' of github.com:PDB-REDO/libcifpp into trunk 2023-09-14 09:15:07 +02:00
Maarten L. Hekkelman
02cc0fa0f6 Using CTest
Create docs/xml directory
2023-09-14 09:13:16 +02:00
Maarten L. Hekkelman
1e1afa023f Using CTest
Create docs/xml directory
2023-09-14 09:12:28 +02:00
16 changed files with 280 additions and 189 deletions

View File

@@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.16)
# set the project name
project(libcifpp VERSION 5.2.0 LANGUAGES CXX)
project(libcifpp VERSION 5.2.2 LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -36,6 +36,8 @@ include(CheckLibraryExists)
include(CMakePackageConfigHelpers)
include(CheckCXXSourceCompiles)
include(GenerateExportHeader)
include(CTest)
include(CMakeDependentOption)
set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)
@@ -49,9 +51,6 @@ elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
# Building shared libraries?
option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" OFF)
# Build documentation?
option(BUILD_DOCUMENTATION "Build the documentation" OFF)
@@ -61,6 +60,10 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Optionally build a version to be installed inside CCP4
option(BUILD_FOR_CCP4 "Build a version to be installed in CCP4" OFF)
# Building shared libraries?
cmake_policy(SET CMP0127 NEW)
cmake_dependent_option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" OFF "NOT (BUILD_FOR_CCP4 AND WIN32)" ON)
# Lots of code depend on the availability of the components.cif file
option(CIFPP_DOWNLOAD_CCD "Download the CCD file components.cif during installation" ON)
@@ -83,8 +86,6 @@ else()
endif()
# Unit tests
option(ENABLE_TESTING "Build test exectuables" OFF)
if(BUILD_FOR_CCP4)
if("$ENV{CCP4}" STREQUAL "" OR NOT EXISTS $ENV{CCP4})
message(FATAL_ERROR "A CCP4 built was requested but CCP4 was not sourced")
@@ -296,7 +297,7 @@ target_include_directories(cifpp
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_link_libraries(cifpp PUBLIC Threads::Threads ZLIB::ZLIB Eigen3::Eigen ${CIFPP_REQUIRED_LIBRARIES})
target_link_libraries(cifpp PUBLIC Threads::Threads ZLIB::ZLIB ${CIFPP_REQUIRED_LIBRARIES})
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_link_options(cifpp PRIVATE -undefined dynamic_lookup)
@@ -318,11 +319,12 @@ if(CIFPP_DOWNLOAD_CCD)
endif()
# Installation directories
set(CIFPP_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/libcifpp")
set(CIFPP_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/libcifpp" CACHE PATH "The directory where dictionary files are stored")
target_compile_definitions(cifpp PUBLIC DATA_DIR="${CIFPP_DATA_DIR}")
if(UNIX)
set(CIFPP_CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/libcifpp")
set(CIFPP_CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/libcifpp"
CACHE PATH "The directory where the update script stores new dictionary files")
target_compile_definitions(cifpp PUBLIC CACHE_DIR="${CIFPP_CACHE_DIR}")
set(CIFPP_ETC_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
@@ -395,11 +397,10 @@ install(FILES
COMPONENT Devel
)
set(cifpp_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR})
set_target_properties(cifpp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION "${cifpp_MAJOR_VERSION}.${cifpp_MINOR_VERSION}"
INTERFACE_cifpp_MAJOR_VERSION ${cifpp_MAJOR_VERSION})
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
INTERFACE_cifpp_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set_property(TARGET cifpp APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING cifpp_MAJOR_VERSION
@@ -411,9 +412,7 @@ write_basic_package_version_file(
COMPATIBILITY AnyNewerVersion
)
if(ENABLE_TESTING)
enable_testing()
if(BUILD_TESTING)
find_package(Boost REQUIRED)
list(APPEND CIFPP_tests unit-v2 unit-3d format model rename-compound sugar spinner)

View File

@@ -2,6 +2,10 @@
This library contains code to work with mmCIF and legacy PDB files.
## Documentation
The documentation can be found at https://www.hekkelman.com/libcifpp-doc/
## Synopsis
```c++
@@ -108,13 +112,9 @@ This checks out the source code from github, creates a new directory
where cmake stores its files. Run a configure, build the code and then
it installs the library and auxiliary files.
If you want to run the tests before installing, you should add `-DENABLE_TESTING=ON`
to the first cmake command. So that would be:
Tests are created by default, and to test the code you can run:
```console
git clone https://github.com/PDB-REDO/libcifpp.git --recurse-submodules
cd libcifpp
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$HOME/.local -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=ON
cmake --build build
ctest --test-dir build
```

View File

@@ -1,3 +1,15 @@
Version 5.2.2
- Remove dependency on Eigen3 for users of libcifpp
- Fix typos in documentation
- Do not build latex files in documentation
- Fixed conversion from string to integer, would fail on +2 e.g.
- sqrt is not constexpr, thus kGoldenRatio should be const, not constexpr
Version 5.2.1
- New versionstring module
- small fixes for generating documentation
- correctly setting SONAME
Version 5.2.0
- With lots of documentation
- Refactored coloured text output

View File

@@ -54,6 +54,10 @@ cmake_minimum_required(VERSION 3.15)
variables contained in the revision file.
#]=======================================================================]
# Record the location of this module now, not at the time the CMakeLists.txt
# is being processed
get_filename_component(_current_cmake_module_dir ${CMAKE_CURRENT_LIST_FILE} PATH)
# First locate a .git file or directory.
function(_get_git_dir _start_dir _variable)
@@ -255,141 +259,13 @@ function(write_version_header dir)
if(VERSION_STRING_OPTION_LIB_NAME)
set(VAR_PREFIX "${VERSION_STRING_OPTION_LIB_NAME}")
set(IDENT_PREFIX "${VERSION_STRING_OPTION_LIB_NAME}_")
set(BOOL_IS_MAIN "false")
else()
set(VAR_PREFIX "")
set(IDENT_PREFIX "")
set(BOOL_IS_MAIN "true")
endif()
# And finally, write out the header file
file(WRITE "${VERSION_STRING_DATA}/${file_name}.in" [[// This file was generated by VersionString.cmake
#pragma once
#include <ostream>
constexpr const char k@VAR_PREFIX@ProjectName[] = "@PROJECT_NAME@";
constexpr const char k@VAR_PREFIX@VersionNumber[] = "@PROJECT_VERSION@";
constexpr int k@VAR_PREFIX@BuildNumber = @BUILD_NUMBER@;
constexpr const char k@VAR_PREFIX@RevisionGitTag[] = "@REVISION_GIT_TAGREF@";
constexpr const char k@VAR_PREFIX@RevisionDate[] = "@REVISION_DATE_TIME@";
#ifndef VERSION_INFO_DEFINED
#define VERSION_INFO_DEFINED 1
namespace version_info_v1
{
class version_info_base
{
public:
static void write(std::ostream &os, bool verbose)
{
auto &s_head = head();
if (s_head != nullptr)
write(s_head, os, verbose);
}
protected:
version_info_base(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date)
: m_name(name)
, m_version(version)
, m_build_number(build_number)
, m_git_tag(git_tag)
, m_revision_date(revision_date)
{
auto &s_head = head();
m_next = s_head;
s_head = this;
}
static void write(const version_info_base *inst, std::ostream &os, bool verbose)
{
if (inst->m_next)
{
write(inst->m_next, os, verbose);
if (not verbose)
return;
os << '-' << std::endl;
}
os << inst->m_name << " version " << inst->m_version << std::endl;
if (verbose)
{
if (inst->m_build_number != 0)
{
os << "build: " << inst->m_build_number << ' ' << inst->m_revision_date << std::endl;
if (inst->m_git_tag[0] != 0)
os << "git tag: " << inst->m_git_tag << std::endl;
}
}
}
using version_info_ptr = version_info_base *;
static version_info_ptr &head()
{
static version_info_ptr s_head = nullptr;
return s_head;
}
const char *m_name;
const char *m_version;
int m_build_number;
const char *m_git_tag;
const char *m_revision_date;
version_info_base *m_next = nullptr;
};
template<typename T>
class version_info : public version_info_base
{
public:
using implementation_type = T;
version_info(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date)
: version_info_base(name, version, build_number, git_tag, revision_date)
{
}
struct register_object
{
register_object()
{
static implementation_type s_instance;
}
};
template<register_object&> struct reference_object;
static register_object s_registered_object;
static reference_object<s_registered_object> s_referenced_object;
};
template<typename T> typename version_info<T>::register_object version_info<T>::s_registered_object;
}
inline void write_version_string(std::ostream &os, bool verbose)
{
version_info_v1::version_info_base::write(os, verbose);
}
#endif
class version_info_@IDENT_PREFIX@impl : public version_info_v1::version_info<version_info_@IDENT_PREFIX@impl>
{
public:
version_info_@IDENT_PREFIX@impl()
: version_info(k@VAR_PREFIX@ProjectName, k@VAR_PREFIX@VersionNumber, k@VAR_PREFIX@BuildNumber, k@VAR_PREFIX@RevisionGitTag, k@VAR_PREFIX@RevisionDate)
{
}
};
]])
configure_file("${VERSION_STRING_DATA}/${file_name}.in" "${dir}/${file_name}" @ONLY)
configure_file("${_current_cmake_module_dir}/revision.hpp.in" "${dir}/${file_name}" @ONLY)
endfunction()

View File

@@ -11,7 +11,6 @@ include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(ZLIB REQUIRED)
find_dependency(Eigen3 REQUIRED)
if(MSVC)
find_dependency(zeep REQUIRED)

138
cmake/revision.hpp.in Normal file
View File

@@ -0,0 +1,138 @@
// This file was generated by VersionString.cmake
#pragma once
#include <ostream>
constexpr const char k@VAR_PREFIX@ProjectName[] = "@PROJECT_NAME@";
constexpr const char k@VAR_PREFIX@VersionNumber[] = "@PROJECT_VERSION@";
constexpr int k@VAR_PREFIX@BuildNumber = @BUILD_NUMBER@;
constexpr const char k@VAR_PREFIX@RevisionGitTag[] = "@REVISION_GIT_TAGREF@";
constexpr const char k@VAR_PREFIX@RevisionDate[] = "@REVISION_DATE_TIME@";
#ifndef VERSION_INFO_DEFINED
#define VERSION_INFO_DEFINED 1
namespace version_info_v1_1
{
class version_info_base
{
public:
static void write_version_string(std::ostream &os, bool verbose)
{
auto s_main = registered_main();
if (s_main != nullptr)
s_main->write(os, verbose);
if (verbose)
{
for (auto lib = registered_libraries(); lib != nullptr; lib = lib->m_next)
{
os << '-' << std::endl;
lib->write(os, verbose);
}
}
}
protected:
version_info_base(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date, bool is_main)
: m_name(name)
, m_version(version)
, m_build_number(build_number)
, m_git_tag(git_tag)
, m_revision_date(revision_date)
{
if (is_main)
registered_main() = this;
else
{
auto &s_head = registered_libraries();
m_next = s_head;
s_head = this;
}
}
void write(std::ostream &os, bool verbose)
{
os << m_name << " version " << m_version << std::endl;
if (verbose)
{
if (m_build_number != 0)
{
os << "build: " << m_build_number << ' ' << m_revision_date << std::endl;
if (m_git_tag[0] != 0)
os << "git tag: " << m_git_tag << std::endl;
}
}
}
using version_info_ptr = version_info_base *;
static version_info_ptr &registered_main()
{
static version_info_ptr s_main = nullptr;
return s_main;
}
static version_info_ptr &registered_libraries()
{
static version_info_ptr s_head = nullptr;
return s_head;
}
const char *m_name;
const char *m_version;
int m_build_number;
const char *m_git_tag;
const char *m_revision_date;
version_info_base *m_next = nullptr;
};
template <typename T>
class version_info : public version_info_base
{
public:
using implementation_type = T;
version_info(const char *name, const char *version, int build_number, const char *git_tag, const char *revision_date, bool is_main)
: version_info_base(name, version, build_number, git_tag, revision_date, is_main)
{
}
struct register_object
{
register_object()
{
static implementation_type s_instance;
}
};
template <register_object &>
struct reference_object;
static register_object s_registered_object;
static reference_object<s_registered_object> s_referenced_object;
};
template <typename T>
typename version_info<T>::register_object version_info<T>::s_registered_object;
} // namespace version_info_v1_1
inline void write_version_string(std::ostream &os, bool verbose)
{
version_info_v1_1::version_info_base::write_version_string(os, verbose);
}
#endif
class version_info_@IDENT_PREFIX@impl : public version_info_v1_1::version_info<version_info_@IDENT_PREFIX@impl>
{
public:
version_info_@IDENT_PREFIX@impl()
: version_info(k@VAR_PREFIX@ProjectName, k@VAR_PREFIX@VersionNumber, k@VAR_PREFIX@BuildNumber, k@VAR_PREFIX@RevisionGitTag, k@VAR_PREFIX@RevisionDate, @BOOL_IS_MAIN@)
{
}
};

View File

@@ -7,36 +7,42 @@ set(CIFPP_PUBLIC_HEADER_DIR ${PROJECT_SOURCE_DIR}/include)
file(GLOB_RECURSE CIFPP_PUBLIC_HEADERS ${CIFPP_PUBLIC_HEADER_DIR}/*.hpp)
set(DOXYGEN_INPUT_DIR ${CIFPP_PUBLIC_HEADER_DIR})
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml)
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/xml)
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/index.xml)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
#Replace variables inside @@ with the current values
# Replace variables inside @@ with the current values
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}/xml) #Doxygen won't create this for us
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${DOXYGEN_OUTPUT_DIR}/xml
DEPENDS ${CIFPP_PUBLIC_HEADERS} ${DOXYFILE_OUT}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
COMMENT "Generating docs")
add_custom_command(
OUTPUT ${DOXYGEN_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${DOXYGEN_OUTPUT_DIR})
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${DOXYGEN_OUTPUT_DIR}
DEPENDS ${DOXYGEN_OUTPUT_DIR} ${CIFPP_PUBLIC_HEADERS} ${DOXYFILE_OUT}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
COMMENT "Generating docs")
add_custom_target("Doxygen-${PROJECT_NAME}" ALL DEPENDS ${DOXYGEN_INDEX_FILE})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_SOURCE_DIR}/conf.py @ONLY)
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
add_custom_target(Sphinx ALL
COMMAND ${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.${PROJECT_NAME}=${DOXYGEN_OUTPUT_DIR}/xml
${SPHINX_SOURCE} ${SPHINX_BUILD}
DEPENDS ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/api
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx")
add_custom_target("Sphinx-${PROJECT_NAME}" ALL
COMMAND ${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.${PROJECT_NAME}=${DOXYGEN_OUTPUT_DIR}
${SPHINX_SOURCE} ${SPHINX_BUILD}
DEPENDS ${DOXYGEN_INDEX_FILE}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/api
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sphinx/ DESTINATION ${CMAKE_INSTALL_DOCDIR} PATTERN .doctrees EXCLUDE)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sphinx/
DESTINATION ${CMAKE_INSTALL_DOCDIR}
PATTERN .doctrees EXCLUDE
PATTERN .buildinfo EXCLUDE)

View File

@@ -3,6 +3,7 @@ FILE_PATTERNS = *.hpp
STRIP_FROM_PATH = @DOXYGEN_INPUT_DIR@
RECURSIVE = YES
GENERATE_XML = YES
GENERATE_LATEX = NO
PREDEFINED += and=&& or=|| not=! CIFPP_EXPORT= HAVE_LIBCLIPPER=1
GENERATE_HTML = NO
GENERATE_TODOLIST = NO

View File

@@ -26,7 +26,7 @@ Writing is equally easy:
file << "Hello, world!";
file.close();
You can also use the :cpp:class:`cif::gzio:istream` and feed it a *std::streambuf* object that may or may not contain compressed data. In that case the first bytes of the input are sniffed and if it is gzip compressed data, decompression will be done.
You can also use the :cpp:class:`cif::gzio::istream` and feed it a *std::streambuf* object that may or may not contain compressed data. In that case the first bytes of the input are sniffed and if it is gzip compressed data, decompression will be done.
A progress bar
--------------

View File

@@ -9,4 +9,25 @@ Information about compounds is captured in the :cpp:class:`cif::compound`. An in
If the compound you want to use is not available in the CCD or in CCP4, you can add that information yourself. For this you can use the method :cpp:func:`cif::compound_factory::push_dictionary`.
So, given that we have CCD, CCP4 monomer library and used defined compound definitions, what will you get when you try to retrieve such a compound by ID? The answer is, the factory has a stack of compound generators. The first thrown on the stack is the one for a CCD file (*components.cif*) if it can be found. Then, if the *CLIBD_MON* environmental variable is defined, a generator for monomer library files is added to the stack. And then all generators for files you added using *push_dictionary* are added in order. The generators are searched in the reverse order in which they were added to see if it creates a compound object for the ID. If no compound was created at all, nullptr is returned.
So, given that we have CCD, CCP4 monomer library and used defined compound definitions, what will you get when you try to retrieve such a compound by ID? The answer is, the factory has a stack of compound generators. The first thrown on the stack is the one for a CCD file (*components.cif*) if it can be found. Then, if the *CLIBD_MON* environmental variable is defined, a generator for monomer library files is added to the stack. And then all generators for files you added using *push_dictionary* are added in order. The generators are searched in the reverse order in which they were added to see if it creates a compound object for the ID. If no compound was created at all, nullptr is returned.
Updating CCD
------------
The CCD data is stored in a single file called *components.cif* and can be downloaded from `CCD <https://www.wwpdb.org/data/ccd>`_.
As can be read in the section on resources (:doc:`/resources`) files in libcifpp are loaded in a specific order. If the CCD datafile was downloaded during installation, a copy can be found in the directory */usr/share/libcifpp/* (if you installed in */usr*). This is a static file and will not be updated until the next installation of libcifpp.
When configuring libcifpp, you can specify the *CIFPP_INSTALL_UPDATE_SCRIPT* option, as in:
.. code-block:: console
cmake -S . -B build -DCIFPP_INSTALL_UPDATE_SCRIPT=ON # ... more options?
This will install a script named *update-libcifpp-data* in */etc/cron.weekly* or */etc/periodic/weekly*. This file uses a config file named */etc/libcifpp.conf* which you then need to edit. In this config file the following line needs to be uncommented:
.. code-block:: console
# update=true
After that, the update script will weekly download the latest components.cif file to */var/cache/libcifpp*.

View File

@@ -459,9 +459,14 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
{
auto txt = ref.text();
std::from_chars_result r = selected_charconv<value_type>::from_chars(txt.data(), txt.data() + txt.size(), result);
auto b = txt.data();
auto e = txt.data() + txt.size();
if (r.ec != std::errc())
std::from_chars_result r = (b + 1 < e and *b == '+' and std::isdigit(b[1])) ?
selected_charconv<value_type>::from_chars(b + 1, e, result) :
selected_charconv<value_type>::from_chars(b, e, result);
if (r.ec != std::errc() or r.ptr != e)
{
result = {};
if (cif::VERBOSE)
@@ -470,6 +475,8 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
std::cerr << "Attempt to convert " << std::quoted(txt) << " into a number\n";
else if (r.ec == std::errc::result_out_of_range)
std::cerr << "Conversion of " << std::quoted(txt) << " into a type that is too small\n";
else
std::cerr << "Not a valid number " << std::quoted(txt) << '\n';
}
}
}
@@ -489,9 +496,14 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
{
value_type v = {};
std::from_chars_result r = selected_charconv<value_type>::from_chars(txt.data(), txt.data() + txt.size(), v);
auto b = txt.data();
auto e = txt.data() + txt.size();
if (r.ec != std::errc())
std::from_chars_result r = (b + 1 < e and *b == '+' and std::isdigit(b[1])) ?
selected_charconv<value_type>::from_chars(b + 1, e, v) :
selected_charconv<value_type>::from_chars(b, e, v);
if (r.ec != std::errc() or r.ptr != e)
{
if (cif::VERBOSE)
{
@@ -499,6 +511,8 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_arithmetic_v<T> an
std::cerr << "Attempt to convert " << std::quoted(txt) << " into a number\n";
else if (r.ec == std::errc::result_out_of_range)
std::cerr << "Conversion of " << std::quoted(txt) << " into a type that is too small\n";
else
std::cerr << "Not a valid number " << std::quoted(txt) << '\n';
}
result = 1;
}

View File

@@ -882,7 +882,7 @@ class spherical_dots
spherical_dots()
{
constexpr double
const double
kGoldenRatio = (1 + std::sqrt(5.0)) / 2;
auto p = m_points.begin();

View File

@@ -77,6 +77,9 @@ extern CIFPP_EXPORT int VERBOSE;
/// return the git 'build' number
std::string get_version_nr();
/// return the width of the current output terminal, or 80 if it cannot be determined
uint32_t get_terminal_width();
// --------------------------------------------------------------------
namespace colour

View File

@@ -182,17 +182,17 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name)
void file::load(const std::filesystem::path &p)
{
gzio::ifstream in(p);
if (not in.is_open())
throw std::runtime_error("Could not open file '" + p.string() + '\'');
try
{
gzio::ifstream in(p);
if (not in.is_open())
throw std::runtime_error("Could not open file " + p.string());
load(in);
}
catch (const std::exception &)
{
throw_with_nested(std::runtime_error("Error reading file " + p.string()));
throw_with_nested(std::runtime_error("Error reading file '" + p.string() + '\''));
}
}

View File

@@ -43,11 +43,6 @@
#include <sstream>
#include <thread>
#if not defined(_WIN32)
#include <sys/ioctl.h>
#include <termios.h>
#endif
namespace fs = std::filesystem;
// --------------------------------------------------------------------
@@ -88,6 +83,8 @@ uint32_t get_terminal_width()
#else
#include <sys/ioctl.h>
#include <termios.h>
#include <limits.h>
uint32_t get_terminal_width()

View File

@@ -150,6 +150,31 @@ BOOST_AUTO_TEST_CASE(cc_2)
}
}
BOOST_AUTO_TEST_CASE(cc_3)
{
cif::category c("foo");
c.emplace({
{ "f-1", 1 },
{ "f-2", "-1" },
{ "f-3", "+1" },
{ "f-4", " 1" },
{ "f-5", " +1" },
{ "f-6", "1 " },
});
auto row = c.front();
BOOST_CHECK_EQUAL(row["f-1"].as<int>(), 1);
BOOST_CHECK_EQUAL(row["f-2"].as<int>(), -1);
BOOST_CHECK_EQUAL(row["f-3"].as<int>(), 1);
// BOOST_CHECK_THROW(row["f-4"].as<int>(), std::exception);
// BOOST_CHECK_THROW(row["f-5"].as<int>(), std::exception);
// BOOST_CHECK_THROW(row["f-6"].as<int>(), std::exception);
BOOST_CHECK_EQUAL(row["f-4"].as<int>(), 0);
BOOST_CHECK_EQUAL(row["f-5"].as<int>(), 0);
BOOST_CHECK_EQUAL(row["f-6"].as<int>(), 0);
}
BOOST_AUTO_TEST_CASE(item_1)
{
using namespace cif;