7 #ifndef INCLUDE_SPARROW_EMBED_COMMON_H
8 #define INCLUDE_SPARROW_EMBED_COMMON_H
10 #include "boost/optional.hpp"
16 inline std::ostream& sep(std::ostream& os) {
21 inline std::ostream& nl(std::ostream& os) {
26 inline std::string sp(
unsigned i) {
27 return std::string(i,
' ');
31 std::vector<std::string> includes;
32 std::vector<std::string> namespaces;
33 boost::optional<std::string> guard = boost::none;
35 void writeHeader(std::ostream& os) {
39 os << R
"delim(/**
* @file
* @copy)delim"
40 << R"delim(right This code is licensed under the 3-clause BSD license.\n
* Copyright ETH Zurich, Laboratory of Physical Chemistry, Reiher Group.\n
* See LICENSE.txt for details.
*
* @note This file was generated by the Embed binary from runtime values.
* Prefer improving the generator over editing this file whenever possible.
*
)delim";
44 os << R
"delim( * This file contains functions generating runtime values. It was
* generated from runtime values of its return type. It is not intended to be
* human-readable. A small guide: Return values are directly brace-initialized
* in deep nesting to keep file size to a minimum. Types are annotated only when
* necessary. Floating point values are represented in hexadecimal (see
* std::hexfloat) to ensure serialization does not cause loss of accuracy.
*
* The functions defined here might be declared and called elsewhere entirely.
*
)delim";
47 os << R"delim( */
)delim";
50 os <<
"#ifndef " << guard.value() << nl;
51 os <<
"#define " << guard.value() << nl << nl;
54 for (
auto& include : includes) {
55 if (include[0] ==
'<' || include[0] ==
'\"') {
56 os <<
"#include " << include << nl;
59 os <<
"#include \"" << include <<
"\"" << nl;
64 for (
auto& name : namespaces) {
65 os <<
"namespace " << name <<
" {" << nl;
71 void writeFooter(std::ostream& os) {
73 for (
auto iter = std::rbegin(namespaces); iter != std::rend(namespaces); ++iter) {
74 os <<
"} // namespace " << *iter << nl;
83 inline std::string lower(std::string a) {
84 std::transform(std::begin(a), std::end(a), std::begin(a), [](
unsigned char c) {
return std::tolower(c); });
88 inline std::string upper(std::string a) {
89 std::transform(std::begin(a), std::end(a), std::begin(a), [](
unsigned char c) {
return std::toupper(c); });
95 template<
typename Arg>
96 void writePack(std::ostream& os, Arg arg) {
100 template<
typename Arg,
typename... Args>
101 void writePack(std::ostream& os, Arg arg1, Args... args) {
103 writePack(os, args...);
106 template<
typename Tuple, std::size_t... Inds>
107 void writeTuplePackHelper(std::ostream& os,
const Tuple& tup, std::index_sequence<Inds...>
109 writePack(os, std::get<Inds>(tup)...);
112 template<
typename Tuple>
113 void writeTuplePack(std::ostream& os,
const Tuple& tup) {
114 writeTuplePackHelper(os, tup, std::make_index_sequence<std::tuple_size<Tuple>::value>{});
119 template<
typename... Args>
121 Joiner(
const Args&... args) : bound(args...) {
124 std::tuple<
const Args&...> bound;
127 template<
typename... Args>
128 auto join(
const Args&... args) {
129 return Joiner<Args...>(args...);
132 template<
typename... Args>
133 std::ostream& operator<<(std::ostream& os,
const Joiner<Args...>& join) {
134 detail::writeTuplePack(os, join.bound);
145 boost::optional<T> optional;
149 auto wrapOptional(
const boost::optional<T>& optional) {
154 std::ostream& operator<<(std::ostream& os, const OptionalWrapper<T>& o) {
156 os << o.optional.value();