BPPrint
General object hashing library for C++
|
BPPrint is a small wrapper around the common C string formatting functions. It adds some helpful compile-time and run-time checks, as well as a few nice features.
The BPPrint project is configured and built using CMake (https://cmake.org).
The only dependencies are a C++ compiler (and standard libraries) capable of compiling C++11 (in particular, variadic templates) and CMake (v3.1.3 or above).
The basic building steps are the traditional CMake steps:
There are a few more helpful options:
BUILD_SHARED_LIBS
can be set to True
to build a shared library, rather than the default static library.
CMAKE_CXX_FLAGS
can be set to compiler-specific optimization flags. For example, to let g++ autodetect the best optimization for the current system, you can use
For the Intel compiler, the equivalent would be
Testing is done with make test.
make install
will install the headers and library. It will also install a CMake configuration file that can be used to include BPPrint in other projects. This creates a CMake interface target that can be used with target_link_libraries
. The top-level install path (what was passed to CMAKE_INSTALL_PREFIX
) must be in your CMAKE_PREFIX_PATH
(or be one of the system defaults).
Note that your project must be built with (at least) C++11 support.
There are two main funtions provided by BPPrint that you would use. Both are declared in <bpprint/Format.hpp>
. The first is format_string()
, which returns an std::string
with the new, formatted string. The second in format_stream
, which outputs the results to a C++ ostream.
The arguments to either of these functions are similar to the printf
family of functions in C, and almost all features are supported.
The correct type specifier can be automatically determined via the ?
specifier. In addition,
If there is an error (bad substitution, etc) an std::runtime_error
exception is thrown with a description of the problem.
BPPrint does not support reordering of arguments. It also does not (yet) support wide characters or any string other than the basic std::string
.
Copyright (c) 2016, Benjamin Pritchard <ben@b> enny p.org
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.